statsd.timer

class statsd.timer.Timer(name, connection=None)

Statsd Timer Object

Additional documentation is available at the parent class Client

>>> timer = Timer('application_name')
>>> timer.start()
>>>  # do something
>>> timer.stop('executed_action')
decorate(function_or_name)

Decorate a function to time the execution

The method can be called with or without a name. If no name is given the function defaults to the name of the function.

Parameters:function_or_name – The name to post to or the function to wrap
>>> from statsd import Timer
>>> timer = Timer('application_name')
>>>
>>> @timer.decorate
... def some_function():
...     # resulting timer name: application_name.some_function
...     pass
>>>
>>> @timer.decorate('my_timer')
... def some_function():
...     # resulting timer name: application_name.my_timer
...     pass
intermediate(subname)

Send the time that has passed since our last measurement

Parameters:subname – The subname to report the data to (appended to the client name)
send(subname, delta)

Send the data to statsd via self.connection

Parameters:
  • subname – The subname to report the data to (appended to the client name)
  • delta – The time delta (time.time() - time.time()) to report
start()

Start the timer and store the start time, this can only be executed once per instance

stop(subname='total')

Stop the timer and send the total since start() was run

Parameters:subname – The subname to report the data to (appended to the client name)

Project Versions

Previous topic

statsd.client

Next topic

statsd.counter

This Page