0
0
Microservicessystem_design~10 mins

Metrics collection (Prometheus) in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Prometheus client library in Python.

Microservices
from prometheus_client import [1]
Drag options to blanks, or click blank then click option'
ACollectorRegistry
BCounter
Cstart_http_server
DGauge
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a metric type that does not count events.
Importing a function instead of a metric class.
2fill in blank
medium

Complete the code to start the Prometheus metrics HTTP server on port 8000.

Microservices
start_http_server([1])
Drag options to blanks, or click blank then click option'
A8080
B9090
C8000
D5000
Attempts:
3 left
💡 Hint
Common Mistakes
Using the default Prometheus server port 9090 instead of the exporter port.
Using a port that is not open or commonly used.
3fill in blank
hard

Fix the error in the code to increment the counter metric named 'requests_total'.

Microservices
requests_total = Counter('requests_total', 'Total number of requests')
requests_total[1]()
Drag options to blanks, or click blank then click option'
Ainc
Bincrement
Cadd
Dincrease
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not exist in the Counter class.
Trying to add values with incorrect method names.
4fill in blank
hard

Fill both blanks to create a Gauge metric and set its value to 5.

Microservices
g = [1]('temperature_celsius', 'Current temperature in Celsius')
g.[2](5)
Drag options to blanks, or click blank then click option'
AGauge
BCounter
Cset
Dinc
Attempts:
3 left
💡 Hint
Common Mistakes
Using Counter instead of Gauge for values that can go up and down.
Using inc() instead of set() to assign a value.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that collects metrics only for services with more than 10 requests.

Microservices
metrics = [1]: [2] for [1], [2] in service_requests.items() if [2] > 10
Drag options to blanks, or click blank then click option'
Aservice
Bcount
Cservice_requests
Drequests
Attempts:
3 left
💡 Hint
Common Mistakes
Using the dictionary name as a variable name inside the loop.
Mixing up key and value variable names.