Skip to main content

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

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

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

meter = Metrology.meter('requests')
meter.mark()
meter.count

or as a decorator:

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

or with context manager:

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

timer = Metrology.timer('responses')
with timer:
    do_something()

or as a decorator:

@Metrology.timer('responses')
def response():
    # do_something

Utilization Timer

A specialized timer that calculates the percentage of wall-clock time that was spent

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.

counter = Metrology.counter({
  'name': 'pending-jobs',
  'host': 'backend',
  'priority': 'high'
})
counter.increment()
counter.decrement()
counter.count

All metric types support tagging.

Reporters

Logger Reporter

A logging reporter that write metrics to a logger

reporter = LoggerReporter(level=logging.INFO, interval=10)
reporter.start()

Graphite Reporter

A graphite reporter that send metrics to graphite

reporter = GraphiteReporter('graphite.local', 2003)
reporter.start()

Librato Reporter

A librator metric reporter that send metrics to librato API

reporter = LibratoReporter("<email>", "<token>")
reporter.start()

Ganglia Reporter

A ganglia reporter that sends metrics to gmond.

reporter = GangliaReporter("Group Name", "localhost", 8649, "udp", interval=60)
reporter.start()

StatsD Reporter

A statsd reporter that sends metrics to statsd daemon.

reporter = StatsDReporter('localhost', 3333, conn_type='tcp')
reporter.start()

or use default UDP setting:

reporter = StatsDReporter('localhost', 3333)
reporter.start()

Acknowledgement

This is heavily inspired by the awesome metrics library.

Release files for metrology 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metrology 1.3.0
File Size Uploaded
metrology-1.3.0.tar.gz 32.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for metrology 1.3.0
File Interpreter ABI Platform
metrology-1.3.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 57.1 kB

Release files / metrology-1.3.0.tar.gz

Download URL metrology-1.3.0.tar.gz
Size 32.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4136c2d20851445ebfe39be56357a96135c1ef704191ebfb5616d88b25a040c9
BLAKE2b-256 checksum
How to use checksums
12550b5f0452e98461d12bc2fb92164eec1c64cbdf9f81fc8b8cbce186ef8058
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / metrology-1.3.0-py2.py3-none-any.whl

Download URL metrology-1.3.0-py2.py3-none-any.whl
Size 24.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2254a2e31439ca692fe13f418848f5ca0d061cbe0ef654b25ebb04469b4ac8ae
BLAKE2b-256 checksum
How to use checksums
ac618ea1c52b78bdc9c69b8cd3ae3d5367a9dc97e9845b8cda9d187568e229f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5

1 release file

0.4.1

1 release file

0.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.2

1 release file

0.1

1 release 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