Skip to main content

Metrics system for generating statistics about your app

Project description

Markus is a metrics generation library for generating statistics about your app.

Code:

https://github.com/willkg/markus

Issues:

https://github.com/willkg/markus/issues

License:

MPL v2

Documentation:

http://markus.readthedocs.io/en/latest/

Status:

Alpha

Goals

Markus makes it easier to add metrics generation to your app by:

  • providing multiple backends (Datadog statsd, statsd, logging, and so on) for sending data to multiple places

  • sending metrics to multiple backends

  • providing a testing framework for easy testing

  • providing a decoupled infrastructure making it easier to use metrics without having to worry about making sure your metrics client is configured and instantiated before the things that want to use it; it’s similar to the Python logging module in this way

Install

To install Markus, run:

$ pip install markus

(Optional) To install the requirements for the markus.backends.datadog.DatadogMetrics backend:

$ pip install markus[datadog]

Quick start

Similar to using the logging library, every Python module can create a MetricsInterface (loosely equivalent to a Python logging logger) at any time including at module import time and use that to generate metrics.

For example:

import markus

metrics = markus.get_metrics(__name__)

Creating a MetricsImplementation using __name__ will cause it to generate all stats keys with a prefix determined from __name__ which is a dotted Python path to that module.

Then you can use the MetricsImplementation anywhere in that module:

@metrics.timer_decorator('chopping_vegetables')
def some_long_function(vegetable):
    for veg in vegetable:
        chop_vegetable()
        metrics.incr('vegetable', 1)

At application startup, configure Markus with the backends you want to use to publish metrics and any options they require.

For example, lets configure metrics to publish to logs and Datadog:

import markus

markus.configure(
    backends=[
        {
            # Log metrics to the logs
            'class': 'markus.backends.logging.LoggingMetrics',
        },
        {
            # Log metrics to Datadog
            'class': 'markus.backends.datadog.DatadogMetrics',
            'options': {
                'statsd_host': 'example.com',
                'statsd_port': 8125,
                'statsd_namespace': ''
            }
        }
    ]
)

When you’re writing your tests, use the MetricsMock to make testing easier:

import markus
from markus.testing import MetricsMock


def test_something():
    with MetricsMock() as mm:
        # ... Do things that might publish metrics

        # This helps you debug and write your test
        mm.print_records()

        # Make assertions on metrics published
        assert mm.has_metric(markus.INCR, 'some.key', {'value': 1})

History

1.0 (October 30th, 2017)

Features

  • Added support for Python 2.7.

  • Added a markus.backends.statsd.StatsdMetrics backend that uses pystatsd client for statsd pings. Thank you, Javier!

Bug fixes

  • Added LoggingRollupMetrics to docs.

  • Mozilla has been running Markus in production for 6 months so we can mark it production-ready now.

0.2 (April 19th, 2017)

Features

  • Added a markus.backends.logging.LoggingRollupMetrics backend that rolls up metrics and does some light math on them. Possibly helpful for light profiling for development.

Bug fixes

  • Lots of documentation fixes. Thank you, Peter!

0.1 (April 10th, 2017)

Initial writing.

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

markus-1.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

markus-1.0-py2.py3-none-any.whl (16.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file markus-1.0.tar.gz.

File metadata

  • Download URL: markus-1.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for markus-1.0.tar.gz
Algorithm Hash digest
SHA256 c1100c79cd4f63890694fb3c805ce44e14b3fe53a5318a01df52cbf281aee408
MD5 bfb1762782f179eebe513e63c5093f89
BLAKE2b-256 96ceb15aaba625d3cdd3f1a26ab08badc30b5ccdeb335a45a717d2a7aedc97d9

See more details on using hashes here.

File details

Details for the file markus-1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for markus-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e96c111391a641d88bf2f21e899060e5417d3735d7061782465b95cee73d0da2
MD5 b1867b990f9f9a663ba5837efda174f7
BLAKE2b-256 bf07704371de27319fbca6468b074479ef33fe984e97cf0200d850d0e27f5a02

See more details on using hashes here.

Supported by

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