Usage¶
Basics¶
aiodogstatsd.Client
can be initialized with:
host
— host string of your StatsD server (default:localhost
);port
— post of your StatsD server (default:9125
);namespace
— optional namespace string to prefix all metrics;constant_tags
— optional tags dictionary to apply to all metrics;read_timeout
(default:0.5
);close_timeout
;sample_rate
(default:1
).
Below you can find an example of client initialization. Keep your eyes on lines 13 and 15. You always need to not to forget to initialize connection and close it at the end:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Context manager¶
As an option you can use aiodogstatsd.Client
as a context manager. In that case you don't need to remember to initialize and close connection:
1 2 |
|
Sending metrics¶
Gauge¶
Record the value of a gauge, optionally setting tags
and a sample_rate
.
1 |
|
Increment¶
Increment a counter, optionally setting a value
, tags
and a sample_rate
.
1 |
|
Decrement¶
Decrement a counter, optionally setting a value
, tags
and a sample_rate
.
1 |
|
Histogram¶
Sample a histogram value, optionally setting tags
and a sample_rate
.
1 |
|
Distribution¶
Send a global distribution value, optionally setting tags
and a sample_rate
.
1 |
|
Timing¶
Record a timing, optionally setting tags
and a sample_rate
.
1 |
|
TimeIt¶
Context manager for easily timing methods, optionally settings tags
, sample_rate
and threshold_ms
.
1 2 |
|
timeit_task¶
Wrapper for asyncio.create_task
that creates a task from a given Awaitable
and sends timing metric of it's duration.
1 2 3 |
|