from prometheus_client import Summary import random # Create a summary metric summary_metric = Summary('my_summary', 'This is my summary metric') # Collect some data and observe it for i in range(100): summary_metric.observe(random.uniform(0, 1)) # Print some statistics print(summary_metric.count) print(summary_metric.sum) print(summary_metric.quantiles())
from prometheus_client import Summary from prometheus_client.core import REGISTRY import time # Create a summary metric summary_metric = Summary('my_summary', 'This is my summary metric') # Register the metric with the registry REGISTRY.register(summary_metric) # Generate some data and observe it over time for i in range(100): summary_metric.observe(i * 10) time.sleep(0.1)In this example, we create a `Summary` metric with the name `my_summary`. We then register it with the `REGISTRY`, which is used to expose metrics to Prometheus. Finally, we generate some data and observe it over time, sleeping for 0.1 seconds between each observation. Overall, the `prometheus_client` package library provides a simple way to instrument your Python applications with custom metrics and expose them to Prometheus for monitoring and alerting.