Skip to main content
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Description: =========
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.count

Meters
------

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.count

or as a decorator:

.. code-block:: python

@Metrology.meter('requests')
def do_this_again():
# do something

or with context manager:

.. code-block:: python

with Metrology.meter('requests'):
# do something

Timers
------

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_something


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

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("<email>", "<token>")
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 <https://github.com/codahale/metrics>`_ library.

Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Utilities

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metrology-1.2.3.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

metrology-1.2.3-py2.py3-none-any.whl (24.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file metrology-1.2.3.tar.gz.

File metadata

  • Download URL: metrology-1.2.3.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for metrology-1.2.3.tar.gz
Algorithm Hash digest
SHA256 7bfa1fdd99cc72c9982a920609620030c72fff65b38316a1deb8fb28f17ddc45
MD5 18d1092b7ff27c4809e3780e9305d678
BLAKE2b-256 b86ba1a9d9a93307f63b4d412c4f434ce41142e188e4273dd81ef0d71dd5e91b

See more details on using hashes here.

File details

Details for the file metrology-1.2.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for metrology-1.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f00817a732f1107ad9f83a2a2c4aa8644020eec6826737ac0261d7e83be65f5f
MD5 3a64c7f1896faab8bff2734d1f7bc99c
BLAKE2b-256 2f1378ab75b6190c0b160aa5f668e64769cc3d4ce8e82f069b146de293ec1857

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.0

2 files

1.2.4

2 files

This release

1.2.3 This release

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.10.1

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

1 file

0.7.3

1 file

0.7.2

1 file

0.7.1

1 file

0.7.0

1 file

0.6.3

1 file

0.6.2

1 file

0.6.1

1 file

0.6

1 file

0.5

1 file

0.4.1

1 file

0.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.2

1 file

0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page