sprockets.clients.statsd¶

The sprockets.clients.statsd package implements a simple statsd client that is used by the sprockets.mixins.statsd package. It can be used in your applications for sending metric values to statsd.

Version Downloads Status Coverage License

Installation¶

sprockets.clients.statsd is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.clients.statsd

Configuration¶

The default statsd server that is used is localhost:8125. The STATSD_HOST and STATSD_PORT environment variables can be used to set the statsd server connection parameters. Note that the socket for communicating with statsd is created once upon module import and will not change until the application is restarted or the module is reloaded.

API Documentation¶

StatsD API¶

The default statsd server that is used is localhost:8125. The STATSD environment variable can be used to set the statsd server connection parameters. Note that the socket for communicating with statsd is created once upon module import and will not change until the application is restarted or the module is reloaded.

sprockets.clients.statsd.add_timing(*args, **kwargs)¶

Add a timer value to statsd. The key is specified as one or more strings that will be joined together with period delimiters. The value must be specified as a keyword argument. The following example will add a

timing to the statsd key foo.bar.baz of 3.14159.

add_timing('foo', 'bar', 'baz', value=3.14159)
Parameters:
  • parts (list) – The key parts to append to the base key
  • value (int|float) – The time value
sprockets.clients.statsd.incr(*args, **kwargs)¶

Increment a statsd counter by the specified value. If you intend to increment the value by anything other than one, you must specify the value as a keyword argument. In the following example, the statsd key foo.bar.baz will be incremented by 2.

incr('foo', 'bar', 'baz', value=2)
Parameters:
  • args (list) – Metric name parts to increment
  • value (int|float) – The value to increment by
sprockets.clients.statsd.set_address()¶

Set the (host, port) to connect to from the environment.

If the environment is updated, a call to this function will update the address this client connects to.

This function will prefer to use the STATSD connection string environment variable, but will fall back to using the STATSD_HOST and STATSD_PORT.

sprockets.clients.statsd.set_gauge(*args, **kwargs)¶

Set a gauge value in statsd. The key is specified as one or more strings that will be joined together with period delimiters. The value must be specified as a keyword argument. The following example will set the statsd key foo.bar.baz to 3.

set_gauge('foo', 'bar', 'baz', 3)
Parameters:
  • args (list) – The gauge metric name to set
  • value (int|float) – The gauge value

Examples¶

The following example demonstrates how to use sprockets.clients.statsd by incrementing a counter, setting a gauge value, and adding a timing value:

from sprockets.clients import statsd

# Increment foo.bar.baz by 1
statsd.incr('foo', 'bar', 'baz')

# Set a gauge value
statsd.set_gauge('foo', 'bar', 'baz', value=10)

# Add a timing value
statsd.add_timing('foo', 'bar', 'baz', value=3.14159)

Version History¶

See Version History

Issues¶

Please report any issues to the Github project at https://github.com/sprockets/sprockets.clients.statsd/issues

Source¶

sprockets.clients.statsd source is available on Github at https://github.com/sprockets/sprockets.clients.statsd

Indices and tables¶