This module can be used to instrument an application using Counters, Distribution Summaries, Gauges, Timers, and Percentile Timers using a dimensional data model.
The generated metrics are periodically sent to an Atlas Aggregator.
Install the library from PyPI:
pip install netflix-spectator-py
from spectator import GlobalRegistry GlobalRegistry.counter('server.numRequests').increment() GlobalRegistry.gauge('server.capacity').set(50)
The import of the
GlobalRegistry will start a daemon thread that will publish metrics in the
background. The cache will be flushed upon normal interpreter termination using atexit, with
the following exceptions:
- The program is killed by a signal not handled by Python.
- A Python fatal internal error is detected.
If you do not want the
GlobalRegistry to automatically start at module import, then set the
following environment variable:
With this configuration, you will have to manually call the
GlobalRegistry.stop() methods. Failure to do so will prevent metric publishing.
This library does not add the
nf.node tag to the published metrics. If you need it, remember to
If you are using this library while running behind Gunicorn, make sure that you do not use
--preload flag, because it can cause issues with how the background thread operates due
to loading the application code before the worker processes are forked.
On the Paved Path, with EzConfig, that is achieved with the following configuration:
WSGI_GUNICORN_PRELOAD = undef
Add the internal configuration for the Spectator Python client, so that it can send metrics to
an Atlas Aggregator cluster. Replace
SMARTIPROXY_HOSTNAME with the hostname of the internal
pip install -i https://SMARTIPROXY_HOSTNAME/pypi netflix-spectator-pyconf