Monitoring Python Applications with Prometheus
Professional
You can instrument your Python application with the official Prometheus Python client library and let the Glouton agent scrape its /metrics endpoint.
Install the client library
Section titled “Install the client library”pip install prometheus-clientMinimal example
Section titled “Minimal example”The snippet below defines a counter and exposes it on http://localhost:8080/metrics:
import timefrom prometheus_client import Counter, start_http_server
requests_total = Counter( "myapp_requests_total", "Total number of processed requests.",)
if __name__ == "__main__": start_http_server(8080) while True: requests_total.inc() time.sleep(1)Scrape with Glouton
Section titled “Scrape with Glouton”Configure Glouton to scrape your application by adding the following to /etc/glouton/conf.d/50-prometheus-metrics.conf:
metric: prometheus: targets: - url: "http://localhost:8080/metrics" name: "my_python_application" allow_metrics: - "myapp_requests_total"Restart the agent to apply the configuration. See Prometheus Monitoring for the full list of options, including Docker label auto-discovery and Kubernetes annotations.