Skip to main content

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()

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

applipy_metrics-0.11.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

applipy_metrics-0.11.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file applipy_metrics-0.11.1.tar.gz.

File metadata

  • Download URL: applipy_metrics-0.11.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.7

File hashes

Hashes for applipy_metrics-0.11.1.tar.gz
Algorithm Hash digest
SHA256 8e2dd33dde05ead773454244ab6171f6f623549f71c20a0d29538f9abdbda6c2
MD5 09884e52f9e76dfaab1117e90664b8bc
BLAKE2b-256 7e103e9bfc9f893f75027228949cc03dd9db86b501e5a8569b4a7b56194eb773

See more details on using hashes here.

File details

Details for the file applipy_metrics-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: applipy_metrics-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.7

File hashes

Hashes for applipy_metrics-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b99ca051d3d728c2209051dd9c91e24e7da294c2dab61f3d0c4748e1d7ac844c
MD5 e6d9bd3d674e92095ba1d52250a269da
BLAKE2b-256 a7a9d3477cc22d8a098e03a0c4e6a08b43e80704030bff1a4ac42c3a10e7182c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page