Metrics

class kaneda.base.Metrics(backend=None, queue=None)[source]

Metrics reporting class

Parameters:
  • backend – instance of kaneda.backends. It is the responsible to store the reported data.
  • queue – instance of kaneda.queues. It is the responsible to store the reported data asynchronously.

If none of the parameters are passed it tries get the backend from kaneda settings file.

custom(name, metric, value, tags=None, id_=None)[source]

Send a custom metric report.

>>> metrics.custom('hotel.response_data', metric='xml', value={'status': 'ok', 'xml': ...}, id_='2B75D750')
decrement(name, tags=None)[source]

Decrement a counter.

>>> metrics.decrement('hotel.occupation')
event(name, text, tags=None)[source]

Record an event.

>>> metrics.event('user.signup', 'New user registered')
gauge(name, value, tags=None)[source]

Record the value of a gauge.

>>> metrics.gauge('users.notifications', 13, tags=['new_message', 'follow_request'])
increment(name, tags=None)[source]

Increment a counter.

>>> metrics.increment('user.profile.views')
timed(name=None, tags=None, use_ms=None)[source]

Measure the amount of time of a function (using a decorator) or a piece of code (using a context manager). If name is not provided while using the decorator it will be used the name of the module and the function.

# With decorator
@metrics.timed('request.response_time')
def perform_request(params):
    pass

# With context manager
with metrics.timed('request.response_time'):
    pass
timing(name, value, tags=None)[source]

Record a timing.

>>> metrics.timing('hotel.availability.request_time', 4)