Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyberdelia/metrology
A library to easily measure what's going on in your python.
https://github.com/cyberdelia/metrology
Last synced: about 5 hours ago
JSON representation
A library to easily measure what's going on in your python.
- Host: GitHub
- URL: https://github.com/cyberdelia/metrology
- Owner: cyberdelia
- License: mit
- Created: 2012-03-15T11:23:12.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-08-10T21:03:37.000Z (over 4 years ago)
- Last Synced: 2024-10-20T08:53:41.937Z (24 days ago)
- Language: Python
- Homepage: https://metrology.readthedocs.org
- Size: 164 KB
- Stars: 309
- Watchers: 8
- Forks: 25
- Open Issues: 8
-
Metadata Files:
- Readme: README.rst
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
=========
Metrology
=========A library to easily measure what's going on in your python.
Metrology allows you to add instruments to your python code and hook them to external reporting tools like Graphite so as to better understand what's going on in your running python program.
Installing
==========To install : ::
pip install metrology
API
===Gauge
-----A gauge is an instantaneous measurement of a value
.. code-block:: python
class JobGauge(metrology.instruments.Gauge):
def value(self):
return len(queue)
gauge = Metrology.gauge('pending-jobs', JobGauge())Counters
--------A counter is like a gauge, but you can increment or decrement its value
.. code-block:: python
counter = Metrology.counter('pending-jobs')
counter.increment()
counter.decrement()
counter.countMeters
------A meter measures the rate of events over time (e.g., "requests per second").
In addition to the mean rate, you can also track 1, 5 and 15 minutes moving averages.. code-block:: python
meter = Metrology.meter('requests')
meter.mark()
meter.countor as a decorator:
.. code-block:: python
@Metrology.meter('requests')
def do_this_again():
# do somethingor with context manager:
.. code-block:: python
with Metrology.meter('requests'):
# do somethingTimers
------A timer measures both the rate that a particular piece of code is called and the distribution of its duration
.. code-block:: python
timer = Metrology.timer('responses')
with timer:
do_something()or as a decorator:
.. code-block:: python
@Metrology.timer('responses')
def response():
# do_somethingUtilization Timer
-----------------A specialized timer that calculates the percentage of wall-clock time that was spent
.. code-block:: python
utimer = Metrology.utilization_timer('responses')
with utimer:
do_something()Tagging metrics
---------------All metrics can be tagged if the reporter supports it (currently: Graphite, Librato, Logger. The StatsD reporter supports the Datadog tag format because no official tag standard has been devised by the project).
Tags can be arbitrary key-value pairs. Just assign a dict as metric name. A 'name'-entry is required... code-block:: python
counter = Metrology.counter({
'name': 'pending-jobs',
'host': 'backend',
'priority': 'high'
})
counter.increment()
counter.decrement()
counter.countAll metric types support tagging.
Reporters
=========Logger Reporter
---------------A logging reporter that write metrics to a logger
.. code-block:: python
reporter = LoggerReporter(level=logging.INFO, interval=10)
reporter.start()Graphite Reporter
-----------------A graphite reporter that send metrics to graphite
.. code-block:: python
reporter = GraphiteReporter('graphite.local', 2003)
reporter.start()Librato Reporter
----------------A librator metric reporter that send metrics to librato API
.. code-block:: python
reporter = LibratoReporter("", "")
reporter.start()Ganglia Reporter
----------------A ganglia reporter that sends metrics to gmond.
.. code-block:: python
reporter = GangliaReporter("Group Name", "localhost", 8649, "udp", interval=60)
reporter.start()StatsD Reporter
----------------A statsd reporter that sends metrics to statsd daemon.
.. code-block:: python
reporter = StatsDReporter('localhost', 3333, conn_type='tcp')
reporter.start()or use default UDP setting:
.. code-block:: python
reporter = StatsDReporter('localhost', 3333)
reporter.start()Acknowledgement
===============This is heavily inspired by the awesome `metrics `_ library.