PK Ί@+O= = $ python-statsd-v1.4/statsd.timer.html
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 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
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 the data to statsd via self.connection
Parameters: |
|
---|
Start the timer and store the start time, this can only be executed once per instance
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) |
---|
statsd is a client for Etsy’s statsd server, a front end/proxy for the Graphite stats collection and graphing server.
To install simply execute python setup.py install. If you want to run the tests first, run python setup.py nosetests
To get started real quick, just try something like this:
>>> import statsd
>>>
>>> timer = statsd.Timer('MyApplication')
>>>
>>> timer.start()
>>> # do something here
>>> timer.stop('SomeTimer')
>>> import statsd
>>>
>>> counter = statsd.Counter('MyApplication')
>>> # do something here
>>> counter += 1
>>> import statsd
>>>
>>> # Open a connection to `server` on port `1234` with a `50%` sample rate
>>> statsd_connection = statsd.Connection(
... name='server',
... port=1234,
... sample_rate=0.5,
... )
>>>
>>> # Create a client for this application
>>> statsd_client = statsd.Client(__name__, statsd_connection)
>>>
>>> class SomeClass(object):
... def __init__(self):
... # Create a client specific for this class
... self.statsd_client = statsd_client.get_client(
... self.__class__.__name__)
...
... def do_something(self):
... # Create a `timer` client
... timer = self.statsd_client.get_client(class_=statsd.Timer)
...
... # start the measurement
... timer.start()
...
... # do something
... timer.interval('intermediate_value')
...
... # do something else
... timer.stop('total')
Please activate JavaScript to enable the search functionality.
From here you can search these documents. Enter your search words into the box below and click "search". Note that the search function will automatically search for all of the words. Pages containing fewer words won't appear in the result list.