statsd is a client for Etsy's node-js statsd server. A proxy for the Graphite stats collection and graphing server.
Project description
Introduction
statsd is a client for Etsy’s statsd server, a front end/proxy for the Graphite stats collection and graphing server.
- Graphite
Install
To install simply execute python setup.py install. If you want to run the tests first, run python setup.py nosetests
Usage
To get started real quick, just try something like this:
Basic Usage
Timers
>>> import statsd >>> >>> timer = statsd.Timer('MyApplication') >>> >>> timer.start() >>> # do something here >>> timer.stop('SomeTimer')
Counters
>>> import statsd >>> >>> counter = statsd.Counter('MyApplication') >>> # do something here >>> counter += 1
Gauge
>>> import statsd >>> >>> gauge = statsd.Gauge('MyApplication') >>> # do something here >>> gauge.send('SomeName', value)
Raw
Raw strings should be e.g. pre-summarized data or other data that will get passed directly to carbon. This can be used as a time and bandwidth-saving mechanism sending a lot of samples could use a lot of bandwidth (more b/w is used in udp headers than data for a gauge, for instance).
>>> import statsd >>> >>> raw = statsd.Raw('MyApplication', connection) >>> # do something here >>> raw.send('SomeName', value, timestamp)
The raw type wants to have a timestamp in seconds since the epoch (the standard unix timestamp, e.g. the output of “date +%s”), but if you leave it out or provide None it will provide the current time as part of the message
Average
>>> import statsd >>> >>> average = statsd.Average('MyApplication', connection) >>> # do something here >>> average.send('SomeName', 'somekey:%d'.format(value))
Advanced Usage
>>> import statsd >>> >>> # Open a connection to `server` on port `1234` with a `50%` sample rate >>> statsd_connection = statsd.Connection( ... host='server', ... port=1234, ... sample_rate=0.5, ... ) >>> >>> # Create a client for this application >>> statsd_client = statsd.Client(__name__, statsd_connection) >>> >>> class SomeClass(object): ... def __init__(self): ... # Create a client specific for this class ... self.statsd_client = statsd_client.get_client( ... self.__class__.__name__) ... ... def do_something(self): ... # Create a `timer` client ... timer = self.statsd_client.get_client(class_=statsd.Timer) ... ... # start the measurement ... timer.start() ... ... # do something ... timer.interval('intermediate_value') ... ... # do something else ... timer.stop('total')
If there is a need to turn OFF the service and avoid sending UDP messages, the Connection class can be disabled by enabling the disabled argument:
>>> statsd_connection = statsd.Connection( ... host='server', ... port=1234, ... sample_rate=0.5, ... disabled=True ... )
If logging’s level is set to debug the Connection object will inform it is not sending UDP messages anymore.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file python-statsd-1.5.7.tar.gz
.
File metadata
- Download URL: python-statsd-1.5.7.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22ecf91b5d8ce658eaf9d4467a4abd2641803923ad7416cfbe70cf0c2c6a87ab |
|
MD5 | e9df6f68a7ad3c8c5a162e855e40d3a3 |
|
BLAKE2b-256 | cfd5147f1d802536201e47140791387470a84bc2b41bc956ac69ed80d86f8134 |