Skip to content

A library of helper methods and decorators for adding statsd metrics to python applications.

License

Notifications You must be signed in to change notification settings

MatthewSBarnes/statsdecor

 
 

Repository files navigation

Statsdecor

Software License Build Status

A set of decorators and helper methods for adding statsd metrics to applications.

Installation

You can use pip to install statsdecor:

pip install statsdecor

Configuration

You must use statsdecor.configure to configure the internal statsd client before calling other methods:

import statsdecor

statsdecor.configure(host='localhost', prefix='superapp.')

Configuration is generally setup during your application's bootstrap. Once set configuration values are re-used in all clients that statsdecor creates.

Usage

You can track metrics with either the module functions, or decorators. Incrementing and decrementing counters looks like:

Metric functions

import statsdecor

statsdecor.incr('save.succeeded')
statsdecor.decr('attempts.remaining')
statsdecor.gauge('sessions.active', 9001)

Counters and timers can also be set through decorators:

import statsdecor.decorators as stats

@stats.increment('save.succeeded')
def save(self):
    pass

@stats.decrement('attempts.remaining')
def attempt():
    pass

@stats.timed('api_request.duration')
def perform_request(self, req)
    pass

When using decorators, metrics are only tracked if the decorated function does not raise an error.

About

A library of helper methods and decorators for adding statsd metrics to python applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 92.8%
  • Makefile 7.2%