Reputation: 3339
I'm getting started with Prometheus to get trending data on a service I've built. I'm trying to use the Python client library, but I'm unclear as to how to use it.
Based on the "Getting started" docs there is a prometheus.yml
file that points to the applications you want to monitor, and the Python client library has this code as an example.
from prometheus_client import start_http_server, Summary
import random
import time
# Create a metric to track time spent and requests made.
REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request')
# Decorate function with metric.
@REQUEST_TIME.time()
def process_request(t):
"""A dummy function that takes some time."""
time.sleep(t)
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(8000)
# Generate some requests.
while True:
process_request(random.random())
It looks like it starts up it's own server and isn't meant to be intertwined with the code in my services.
So my question is, how do I use the Prometheus client, to tell Prometheus exactly what functions to monitor from my services?
Upvotes: 0
Views: 2153
Reputation: 34112
You should add metrics such as the Summary
in the example to your own code, and they'll be exposed on port 8000.
Upvotes: 1