Skip to main content
client_python
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Collector

Process Collector

The Python client automatically exports metrics about process CPU usage, RAM, file descriptors and start time. These all have the prefix process, and are only currently available on Linux.

The namespace and pid constructor arguments allows for exporting metrics about other processes, for example:

ProcessCollector(namespace='mydaemon', pid=lambda: open('/var/run/daemon.pid').read())

Platform Collector

The client also automatically exports some metadata about Python. If using Jython, metadata about the JVM in use is also included. This information is available as labels on the python_info metric. The value of the metric is 1, since it is the labels that carry information.

Disabling Default Collector metrics

By default the collected process, gc, and platform collector metrics are exported. If this information is not helpful, it can be disabled using the following:

import prometheus_client

prometheus_client.REGISTRY.unregister(prometheus_client.GC_COLLECTOR)
prometheus_client.REGISTRY.unregister(prometheus_client.PLATFORM_COLLECTOR)
prometheus_client.REGISTRY.unregister(prometheus_client.PROCESS_COLLECTOR)

API Reference

ProcessCollector

ProcessCollector(namespace='', pid=lambda: 'self', proc='/proc', registry=REGISTRY)

Collects process metrics from /proc. Only available on Linux.

ParameterTypeDefaultDescription
namespacestr''Prefix added to all metric names, e.g. 'mydaemon' produces mydaemon_process_cpu_seconds_total.
pidCallable[[], int or str]lambda: 'self'Callable that returns the PID to monitor. 'self' monitors the current process.
procstr'/proc'Path to the proc filesystem. Useful for testing or containerised environments with a non-standard mount point.
registryCollectorRegistryREGISTRYRegistry to register with. Pass None to skip registration.

Metrics exported:

MetricDescription
process_cpu_seconds_totalTotal user and system CPU time in seconds.
process_virtual_memory_bytesVirtual memory size in bytes.
process_resident_memory_bytesResident memory size in bytes.
process_start_time_secondsStart time since Unix epoch in seconds.
process_open_fdsNumber of open file descriptors.
process_max_fdsMaximum number of open file descriptors.

The module-level PROCESS_COLLECTOR is the default instance registered with REGISTRY.

PlatformCollector

PlatformCollector(registry=REGISTRY, platform=None)

Exports Python runtime metadata as a python_info gauge metric with labels.

ParameterTypeDefaultDescription
registryCollectorRegistryREGISTRYRegistry to register with. Pass None to skip registration.
platformmoduleNoneOverride the platform module. Intended for testing.

Labels on python_info: version, implementation, major, minor, patchlevel. On Jython, additional labels are added: jvm_version, jvm_release, jvm_vendor, jvm_name.

The module-level PLATFORM_COLLECTOR is the default instance registered with REGISTRY.

GCCollector

GCCollector(registry=REGISTRY)

Exports Python garbage collector statistics. Only active on CPython (skipped silently on other implementations).

ParameterTypeDefaultDescription
registryCollectorRegistryREGISTRYRegistry to register with.

Metrics exported:

MetricDescription
python_gc_objects_collected_totalObjects collected during GC, by generation.
python_gc_objects_uncollectable_totalUncollectable objects found during GC, by generation.
python_gc_collections_totalNumber of times each generation was collected.

The module-level GC_COLLECTOR is the default instance registered with REGISTRY.