PCA (Prometheus Certified Associate) sample exam question with answer 531
Question:
Which of the following is the correct way to define a new Counter metric in Prometheus with Python?
- Counter('my_counter', 'A counter for my application')
- prometheus.Counter('my_counter', 'A counter for my application')
- prometheus_client.Counter('my_counter', 'A counter for my application')
- prometheus_client.Counter('my_counter', 'A counter for my application').register()
Answer:
C - is the correct answer. To define a new Counter metric in Prometheus with Python, you need to use the prometheus_client.Counter class
A - is incorrect as it does not include the prometheus_client module name
B - is incorrect as it uses the wrong syntax to import the prometheus module
D - is incorrect as it includes the .register() method call, which is not needed when defining the metric