Skip to main content

Multiprocess-safe metrics

Project description

mpmetrics

mpmetrics implements metrics suitable for use with OpenMetrics. It provides multiprocess-safe replacements for prometheus_client's Counter, Gauge, Summary, and Histogram. 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.
@REQUEST_TIME.time()
def process_request(t):
    """A dummy function that takes some time."""
    time.sleep(t)

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

if __name__ == '__main__':
    # Start up the server to expose the metrics.
    start_http_server(8000)
    # Generate some requests from two processes
    multiprocessing.Process(target=generate_requests).start()
    generate_requests()

Features

  • Completely thread- and process-safe.
  • All operations are atomic. Metrics will never be partially updated.
  • Updating metrics is lock-free.
  • TODO: better performance?

Compatibility

The following behaviors differ from prometheus_client:

  • Labeled metrics cannot be removed or cleared.
  • Info metrics are not implemented. Use prometheus_client.Info instead.
  • Enums (StateSets) are not implemented.
  • Exemplars are not implemented.
  • Using a value of None for registry is not supported.

Limitations

The following limitations apply to this library

  • Only Unix is supported, and only Linux x86-64 has been tested.
  • Only the fork start method has been tested, though the others should work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpmetrics-0.0.1.tar.gz (38.3 kB view details)

Uploaded Source

File details

Details for the file mpmetrics-0.0.1.tar.gz.

File metadata

  • Download URL: mpmetrics-0.0.1.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.1

File hashes

Hashes for mpmetrics-0.0.1.tar.gz
Algorithm Hash digest
SHA256 46561031371a00137b9212098cd3ff20299f1b8f62fd6a6d590d812e35b3b82a
MD5 e8dac5628bcf561a4dc26ee2552291f8
BLAKE2b-256 758280ca09275fef5e0c6b5eb3ffe451681dbc6574b23680346a2a33214a8e26

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page