Name: aioshumway
Owner: Spotify
Description: An asyncio-supported micro metrics framework for FFWD
Created: 2018-01-24 18:17:17.0
Updated: 2018-05-16 17:45:13.0
Pushed: 2018-05-16 17:59:29.0
Homepage: null
Size: 13
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A wrapper around the shumway library that uses asyncio to make all IO operations non-blocking and compatible with the async/await syntax.
NOTE: This is a lightly touched up copy of shumway's README since the only difference between these libraries is that this one provides an awaitable interface.
) $ pip install aioshumway
Create a default counter and send to FFWD:
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
ncr(METRIC_NAME)
side an async context
t mr.flush()
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
ter = aioshumway.Counter(metric_name, SERVICE_NAME, value=10)
et_counter(metric_name, counter)
ncr(metric_name)
side an async context
t mr.flush()
Create a named counter and increment by a value different than 1:
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
ncr(METRIC_NAME, 2)
side an async context
t mr.flush()
Set custom attributes for metrics:
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
ter = aioshumway.counter(metric_name, SERVICE_NAME,
{attr_1: value_1,
attr_2: value_2})
et_counter(metric_name, counter)
ncr(metric_name)
side an async context
t mr.flush()
NB: If you use duplicate names when calling set_counter
it will overwrite the
counter. You will likely want to use a unique metric name for each set of
attributes you are setting.
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
r = mr.timer('timing-this-thing')
side an async context
timer:
...task you want to time
t mr.flush()
Timers can also be created independently in order to set custom attributes:
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME)
r = aioshumway.Timer('timing-this-thing', SERVICE_NAME,
{'attr_1': value_1, 'attr_2': value_2})
side an async context
timer:
# ...task you want to time
et_timer('timing-this-thing', timer)
t mr.flush()
There are two ways to send metrics to the ffwd
agent:
You can emit a one-off, event-type metric immediately:
rt aioshumway
aioshumway.MetricRelay('my-service')
side an async context
me event happened
t mr.emit('a-successful-event', 1)
me event happened with attributes
t mr.emit('a-successful-event', 1, {'attr_1': value_1, 'attr_2': value_2})
event with a multiple value happened
t mr.emit('a-successful-event', 5)
For batch-like metrics, you can flush metrics once you're ready:
rt aioshumway
aioshumway.MetricRelay('my-service')
asure all the things
me all the things
side an async context
ot dry_run:
await mr.flush()
Check for existence of metrics in the MetricRelay with in
:
import aioshumway
mr = aioshumway.MetricRelay('my-service')
counter = aioshumway.Counter('thing-to-count', 'my-service', value=5)
mr.set_counter('thing-to-count', counter)
'thing-to-count' in mr
'not-a-counter' in mr
e
By default, aioshumway
will send metrics to a local ffwd
agent at 127.0.0.1:19000
.
If your ffwd
agent is elsewhere, then pass that information through when initializing the MetricRelay
:
rt aioshumway
aioshumway.MetricRelay(SERVICE_NAME, ffwd_ip='10.99.0.1', ffwd_port=19001)
the thing
For development and running tests, your system must have all supported versions of Python installed. We suggest using pyenv.
t clone git@github.com:spotify/aioshumway.git && cd aioshumway
ke a virtualenv
) $ pip install -r dev-requirements.txt
To run the entire test suite:
tside of the virtualenv
tox is not yet installed
p install tox
x
To run an individual test, pass the test's name to pytest, through tox
:
side virtualenv
) $ tox -- tests/test_aioshumway.py::TestSomething
This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.