Performance metrics, based on Coda Hale's Yammer metrics
Project description
Applipy Metrics
Note: This is a hard fork of Lightricks/PyFormance at commit
d59501e
A Python port of the core portion of a Java Metrics library by Coda Hale, with inspiration by YUNOMI - Y U NO MEASURE IT?
Applipy Metrics is a toolset for performance measurement and statistics, with a signaling mechanism that allows to issue events in cases of unexpected behavior
Core Features
Gauge
A gauge metric is an instantaneous reading of a particular value.
Counter
Simple interface to increment and decrement a value. For example, this can be used to measure the total number of jobs sent to the queue, as well as the pending (not yet complete) number of jobs in the queue. Simply increment the counter when an operation starts and decrement it when it completes.
Summary
Measures the statistical distribution of values in a data stream. Keeps track of minimum, maximum, mean, standard deviation, etc. It also measures median, 75th, 90th, 95th, 98th, 99th, and 99.9th percentiles. An example use case would be for looking at the number of daily logins for 99 percent of your days, ignoring outliers.
Regex Grouping
Useful when working with APIs. A RegexRegistry allows to group API calls and measure from a single location instead of having to define different timers in different places.
>>> from applipy_metrics.registry import RegexRegistry
>>> reg = RegexRegistry(pattern='^/api/(?P<model>)/\d+/(?P<verb>)?$')
>>> def rest_api_request(path):
... with reg.timer(path).time():
... # do stuff
>>> print(reg.dump_metrics())
applipy
This library exposes an applipy module, if applipy is installed.
The module can be imported at applipy_metrics.MetricsModule
.
It binds a MetricsRegistry
instance, so that other modules can declare a
dependency and use it to create metrics.
Configurations available
metrics.clock
: fully qualified name of an object with a member function namedtime()
that returns unix timestamps. Will be used as the registry clock, used for summaries.metrics.summary.sample_provider
: fully qualified name of a function that accepts a clock instance and returns an instance of eitherapplipy_metrics.stats.samples.ExpDecayingSample
,applipy_metrics.stats.samples.SlidingTimeWindowSample
orNone
.
Metrics Reporters
If you want to report your metrics using a
applipy_metrics.reporters.reporter.Reporter
instance, simply bind your
reporter provider/instance to the base reporter type. The MetricsModule will
take care of its lifecycle.
Examples
Decorators
The simplest and easiest way to use the Applipy Metrics library.
Counter
You can use the count_calls
decorator to count the number of times a function
is called.
>>> from applipy_metrics import counter, count_calls
>>> @count_calls
... def test():
... pass
...
>>> for i in range(10):
... test()
...
>>> print(counter("test_calls").get_count())
10
Timer
You can use the time_calls
decorator to time the execution of a function and
get distribution data from it.
>>> import time
>>> from applipy_metrics import summary, time_calls
>>> @time_calls
... def test():
... time.sleep(0.1)
...
>>> for i in range(10):
... test()
...
>>> print(summary("test_calls").get_snapshot().get_mean())
0.100820207596
With statement
You can also use a timer using the with statement
Chronometer
>>> import time
>>> from applipy_metrics import summary, Chronometer
>>> with Chronometer(on_stop=lambda x: summary("test").add(x)):
... time.sleep(0.1)
>>> print(summary("test").get_snapshot().get_mean())
0.10114598274230957
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file applipy_metrics-1.2.3.tar.gz
.
File metadata
- Download URL: applipy_metrics-1.2.3.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48db99df03edec9e2a117567b66ea99eb368bf6d05ac85aa63444a8590b47513 |
|
MD5 | cd573e8103e2a3b2fbb2f4b1ed2e92c7 |
|
BLAKE2b-256 | ff935eff87cd53f852f728af5acee2989a41cdbc91adbdf7158108fb06e3cf1f |
File details
Details for the file applipy_metrics-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: applipy_metrics-1.2.3-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3a677e0f204b5ed1e4bc24ef5dab19fc2950255579fa11270469c724ff3f167 |
|
MD5 | c74b08de4bf6ad64f96ebd9068cc91fd |
|
BLAKE2b-256 | 41641ceb0ee8d8da3e7b3b9469cc29cf8daee7023253cabce1ee0028db83ef1e |