A set of decorators and helper methods for adding statsd metrics to applications.
Project description
# Statsdecor
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
[![Build Status](https://api.travis-ci.org/freshbooks/statsdecor.svg)](https://travis-ci.org/freshbooks/statsdecor)
A set of decorators and helper methods for adding statsd metrics to applications.
## Installation
You can use pip to install statsdecor:
```shell
pip install statsdecor
```
## Configuration
You must use `statsdecor.configure` to configure the internal statsd client before
calling other methods:
```python
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
```python
import statsdecor
statsdecor.incr('save.succeeded')
statsdecor.decr('attempts.remaining')
statsdecor.gauge('sessions.active', 9001)
```
Counters and timers can also be set through decorators:
```python
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.
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
[![Build Status](https://api.travis-ci.org/freshbooks/statsdecor.svg)](https://travis-ci.org/freshbooks/statsdecor)
A set of decorators and helper methods for adding statsd metrics to applications.
## Installation
You can use pip to install statsdecor:
```shell
pip install statsdecor
```
## Configuration
You must use `statsdecor.configure` to configure the internal statsd client before
calling other methods:
```python
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
```python
import statsdecor
statsdecor.incr('save.succeeded')
statsdecor.decr('attempts.remaining')
statsdecor.gauge('sessions.active', 9001)
```
Counters and timers can also be set through decorators:
```python
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.
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
statsdecor-0.3.4.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for statsdecor-0.3.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bd6eee5d502f4341a949bb7fbcd1a8dfaf36ff75df9bac4e42b1d380f778089 |
|
MD5 | c4b0c2bd58a2d1460ba491631db67a6a |
|
BLAKE2b-256 | b603001c24c82542885d36c05d394bc11346e2477acd85512ee580b48ed27fdc |