mpmetrics implements metrics suitable for use with OpenMetrics. It provides multiprocess-safe replacements for prometheus_client’s Counter, Gauge, Summary, Histogram, and Enum. To use it, just import these classes from mpmetrics instead of from prometheus_client:

from mpmetrics import Summary
from prometheus_client import start_http_server
import multiprocessing
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.
def process_request(t):
    """A dummy function that takes some time."""

# Create function for subprocess
def generate_requests():
    while True:

if __name__ == '__main__':
    # Start up the server to expose the metrics.
    # Generate some requests from two processes

Navigate to http://localhost:8000/metrics to view the results. For more examples, look in the examples/ directory.

Indices and tables