Skip to main content

statsd is a client for Etsy's node-js statsd server. A proxy for the Graphite stats collection and graphing server.

Project description

Test Status Coverage Status

statsd is a client for Etsy’s statsd server, a front end/proxy for the Graphite stats collection and graphing server.

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))

Connection settings

If you need some settings other than the defaults for your Connection, you can use Connection.set_defaults().

>>> import statsd
>>> statsd.Connection.set_defaults(host='localhost', port=8125, sample_rate=1, disabled=False)

Every interaction with statsd after these are set will use whatever you specify, unless you explicitly create a different Connection to use (described below).

Defaults:

  • host = 'localhost'

  • port = 8125

  • sample_rate = 1

  • disabled = False

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.intermediate('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


Download files

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

Source Distribution

python-statsd-2.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

python_statsd-2.0.0-py2.py3-none-any.whl (13.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-statsd-2.0.0.tar.gz.

File metadata

File hashes

Hashes for python-statsd-2.0.0.tar.gz
Algorithm Hash digest
SHA256 54ed1a223eef8d735661c26f830ca9beaf307a56322532cebeea8c805b40a19a
MD5 378957b56b6672959962b5d08197dc5a
BLAKE2b-256 352a4dc9f89d659837ce3ee7a309edab62dc7966a6d94e6b8220e67c09293092

See more details on using hashes here.

File details

Details for the file python_statsd-2.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for python_statsd-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 52809a37cc64561573c1ecd64d4c569c8fe1056fac97ada19282c6c346a65168
MD5 cd4aac7b59f2f30b2a3d418c73f65b6f
BLAKE2b-256 9d20600fa861b47290480cb83a98101f190cb8a8db147b53ed98661a9c55a529

See more details on using hashes here.

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