markus


Namemarkus JSON
Version 4.2.0 PyPI version JSON
download
home_pagehttps://github.com/willkg/markus
SummaryMetrics system for generating statistics about your app
upload_time2023-03-30 19:47:40
maintainer
docs_urlNone
authorWill Kahn-Greene
requires_python>=3.7
licenseMPLv2
keywords metrics datadog statsd
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ======
Markus
======

Markus is a Python library for generating metrics.

:Code:          https://github.com/willkg/markus
:Issues:        https://github.com/willkg/markus/issues
:License:       MPL v2
:Documentation: http://markus.readthedocs.io/en/latest/


Goals
=====

Markus makes it easier to generate metrics in your program by:

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

* sending metrics to multiple backends at the same time

* providing a testing framework for easy testing

* providing a decoupled architecture making it easier to write code to generate
  metrics without having to worry about making sure creating and configuring a
  metrics client has been done--similar to the Python logging Python logging
  module in this way

I use it at Mozilla in the collector of our crash ingestion pipeline. Peter used
it to build our symbols lookup server, too.


Install
=======

To install Markus, run::

    $ pip install markus

(Optional) To install the requirements for the
``markus.backends.statsd.StatsdMetrics`` backend::

    $ pip install 'markus[statsd]'

(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
``markus.main.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 ``markus.main.MetricsInterface`` 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 ``markus.main.MetricsInterface`` anywhere in that
module::

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


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

For example, let us 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 ``markus.testing.MetricsMock``
to make testing easier::

    from markus.testing import MetricsMock


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

            # Make assertions on metrics published
            mm.assert_incr_once("some.key", value=1)


History
=======

4.2.0 (March 30th, 2023)
------------------------

**Bug fixes**

* Add support for setting ``origin_detection_enabled`` in Datadog backend.
  (#108)

* Switch from Flake8 to Ruff. (#109)


4.1.0 (November 7th, 2022)
--------------------------

**Features**

* Add support for Python 3.11 (#100)

**Bug fixes**

* Redo how dev environment works so it's no longer installed via an extras but
  is now in a separate requirements-dev.txt file.

* Split flake8 tou a separate requirements-flake8.txt and tox environment to
  handle conflicts with installing other things.


4.0.1 (May 10th, 2022)
----------------------

**Bug fixes**

* Move pytest import to a pytest plugin so it's easier to determine when pytest
  is running. (#95) Thank you, John!


4.0.0 (October 22nd, 2021)
--------------------------

**Features**

* Added support for Python 3.10 (#88)

**Backwards incompatibel changes**

* Dropped support for Python 3.6 (#89)


3.0.0 (February 5th, 2021)
--------------------------

**Features**

* Added support for Python 3.9 (#79). Thank you, Brady!

* Changed ``assert_*`` helper methods on ``markus.testing.MetricsMock``
  to print the records to stdout if the assertion fails. This can save some
  time debugging failing tests. (#74)

**Backwards incompatible changes**

* Dropped support for Python 3.5 (#78). Thank you, Brady!

* ``markus.testing.MetricsMock.get_records`` and
  ``markus.testing.MetricsMock.filter_records`` return
  ``markus.main.MetricsRecord`` instances now. This might require
  you to rewrite/update tests that use the ``MetricsMock``.


2.2.0 (April 15th, 2020)
------------------------

**Features**

* Add ``assert_`` methods to ``MetricsMock`` to reduce the boilerplate for
  testing. Thank you, John! (#68)

**Bug fixes**

* Remove use of ``six`` library. (#69)


2.1.0 (October 7th, 2019)
-------------------------

**Features**

* Fix ``get_metrics()`` so you can call it without passing in a `thing`
  and it'll now create a ``MetricsInterface`` that doesn't have a key
  prefix. (#59)


2.0.0 (September 19th, 2019)
----------------------------

**Features**

* Use ``time.perf_counter()`` if available. Thank you, Mike! (#34)
* Support Python 3.7 officially.
* Add filters for adjusting and dropping metrics getting emitted.
  See documentation for more details. (#40)

**Backwards incompatible changes**

* ``tags`` now defaults to ``[]`` instead of ``None`` which may affect some
  expected test output.
* Adjust internals to run ``.emit()`` on backends. If you wrote your own
  backend, you may need to adjust it.
* Drop support for Python 3.4. (#39)
* Drop support for Python 2.7.
  
  If you're still using Python 2.7, you'll need to pin to ``<2.0.0``. (#42)

**Bug fixes**

* Document feature support in backends. (#47)
* Fix ``MetricsMock.has_record()`` example. Thank you, John!


1.2.0 (April 27th, 2018)
------------------------

**Features**

* Add ``.clear()`` to ``MetricsMock`` making it easier to build a pytest
  fixture with the ``MetricsMock`` context and manipulate records for easy
  testing. (#29)

**Bug fixes**

* Update Cloudwatch backend fixing ``.timing()`` and ``.histogram()`` to
  send ``histogram`` metrics type which Datadog now supports. (#31)


1.1.2 (April 5th, 2018)
-----------------------

**Typo fixes**

* Fix the date from the previous release. Ugh.


1.1.1 (April 5th, 2018)
-----------------------

**Features**

* Official switch to semver.

**Bug fixes**

* Fix ``MetricsMock`` so it continues to work even if ``configure``
  is called. (#27)


1.1 (November 13th, 2017)
-------------------------

**Features**

* Added ``markus.utils.generate_tag`` utility function


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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/willkg/markus",
    "name": "markus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "metrics datadog statsd",
    "author": "Will Kahn-Greene",
    "author_email": "willkg@mozilla.com",
    "download_url": "https://files.pythonhosted.org/packages/3c/17/4260d7e51a54445f259af71242da8d888778880061d5c8927adab9a1eee8/markus-4.2.0.tar.gz",
    "platform": null,
    "description": "======\nMarkus\n======\n\nMarkus is a Python library for generating metrics.\n\n:Code:          https://github.com/willkg/markus\n:Issues:        https://github.com/willkg/markus/issues\n:License:       MPL v2\n:Documentation: http://markus.readthedocs.io/en/latest/\n\n\nGoals\n=====\n\nMarkus makes it easier to generate metrics in your program by:\n\n* providing multiple backends (Datadog statsd, statsd, logging, logging rollup,\n  and so on) for sending data to different places\n\n* sending metrics to multiple backends at the same time\n\n* providing a testing framework for easy testing\n\n* providing a decoupled architecture making it easier to write code to generate\n  metrics without having to worry about making sure creating and configuring a\n  metrics client has been done--similar to the Python logging Python logging\n  module in this way\n\nI use it at Mozilla in the collector of our crash ingestion pipeline. Peter used\nit to build our symbols lookup server, too.\n\n\nInstall\n=======\n\nTo install Markus, run::\n\n    $ pip install markus\n\n(Optional) To install the requirements for the\n``markus.backends.statsd.StatsdMetrics`` backend::\n\n    $ pip install 'markus[statsd]'\n\n(Optional) To install the requirements for the\n``markus.backends.datadog.DatadogMetrics`` backend::\n\n    $ pip install 'markus[datadog]'\n\n\nQuick start\n===========\n\nSimilar to using the logging library, every Python module can create a\n``markus.main.MetricsInterface`` (loosely equivalent to a Python\nlogging logger) at any time including at module import time and use that to\ngenerate metrics.\n\nFor example::\n\n    import markus\n\n    metrics = markus.get_metrics(__name__)\n\n\nCreating a ``markus.main.MetricsInterface`` using ``__name__``\nwill cause it to generate all stats keys with a prefix determined from\n``__name__`` which is a dotted Python path to that module.\n\nThen you can use the ``markus.main.MetricsInterface`` anywhere in that\nmodule::\n\n    @metrics.timer_decorator(\"chopping_vegetables\")\n    def some_long_function(vegetable):\n        for veg in vegetable:\n            chop_vegetable()\n            metrics.incr(\"vegetable\", value=1)\n\n\nAt application startup, configure Markus with the backends you want to use to\npublish metrics and any options they require.\n\nFor example, let us configure metrics to publish to logs and Datadog::\n\n    import markus\n\n    markus.configure(\n        backends=[\n            {\n                # Log metrics to the logs\n                \"class\": \"markus.backends.logging.LoggingMetrics\",\n            },\n            {\n                # Log metrics to Datadog\n                \"class\": \"markus.backends.datadog.DatadogMetrics\",\n                \"options\": {\n                    \"statsd_host\": \"example.com\",\n                    \"statsd_port\": 8125,\n                    \"statsd_namespace\": \"\"\n                }\n            }\n        ]\n    )\n\n\nWhen you're writing your tests, use the ``markus.testing.MetricsMock``\nto make testing easier::\n\n    from markus.testing import MetricsMock\n\n\n    def test_something():\n        with MetricsMock() as mm:\n            # ... Do things that might publish metrics\n\n            # Make assertions on metrics published\n            mm.assert_incr_once(\"some.key\", value=1)\n\n\nHistory\n=======\n\n4.2.0 (March 30th, 2023)\n------------------------\n\n**Bug fixes**\n\n* Add support for setting ``origin_detection_enabled`` in Datadog backend.\n  (#108)\n\n* Switch from Flake8 to Ruff. (#109)\n\n\n4.1.0 (November 7th, 2022)\n--------------------------\n\n**Features**\n\n* Add support for Python 3.11 (#100)\n\n**Bug fixes**\n\n* Redo how dev environment works so it's no longer installed via an extras but\n  is now in a separate requirements-dev.txt file.\n\n* Split flake8 tou a separate requirements-flake8.txt and tox environment to\n  handle conflicts with installing other things.\n\n\n4.0.1 (May 10th, 2022)\n----------------------\n\n**Bug fixes**\n\n* Move pytest import to a pytest plugin so it's easier to determine when pytest\n  is running. (#95) Thank you, John!\n\n\n4.0.0 (October 22nd, 2021)\n--------------------------\n\n**Features**\n\n* Added support for Python 3.10 (#88)\n\n**Backwards incompatibel changes**\n\n* Dropped support for Python 3.6 (#89)\n\n\n3.0.0 (February 5th, 2021)\n--------------------------\n\n**Features**\n\n* Added support for Python 3.9 (#79). Thank you, Brady!\n\n* Changed ``assert_*`` helper methods on ``markus.testing.MetricsMock``\n  to print the records to stdout if the assertion fails. This can save some\n  time debugging failing tests. (#74)\n\n**Backwards incompatible changes**\n\n* Dropped support for Python 3.5 (#78). Thank you, Brady!\n\n* ``markus.testing.MetricsMock.get_records`` and\n  ``markus.testing.MetricsMock.filter_records`` return\n  ``markus.main.MetricsRecord`` instances now. This might require\n  you to rewrite/update tests that use the ``MetricsMock``.\n\n\n2.2.0 (April 15th, 2020)\n------------------------\n\n**Features**\n\n* Add ``assert_`` methods to ``MetricsMock`` to reduce the boilerplate for\n  testing. Thank you, John! (#68)\n\n**Bug fixes**\n\n* Remove use of ``six`` library. (#69)\n\n\n2.1.0 (October 7th, 2019)\n-------------------------\n\n**Features**\n\n* Fix ``get_metrics()`` so you can call it without passing in a `thing`\n  and it'll now create a ``MetricsInterface`` that doesn't have a key\n  prefix. (#59)\n\n\n2.0.0 (September 19th, 2019)\n----------------------------\n\n**Features**\n\n* Use ``time.perf_counter()`` if available. Thank you, Mike! (#34)\n* Support Python 3.7 officially.\n* Add filters for adjusting and dropping metrics getting emitted.\n  See documentation for more details. (#40)\n\n**Backwards incompatible changes**\n\n* ``tags`` now defaults to ``[]`` instead of ``None`` which may affect some\n  expected test output.\n* Adjust internals to run ``.emit()`` on backends. If you wrote your own\n  backend, you may need to adjust it.\n* Drop support for Python 3.4. (#39)\n* Drop support for Python 2.7.\n  \n  If you're still using Python 2.7, you'll need to pin to ``<2.0.0``. (#42)\n\n**Bug fixes**\n\n* Document feature support in backends. (#47)\n* Fix ``MetricsMock.has_record()`` example. Thank you, John!\n\n\n1.2.0 (April 27th, 2018)\n------------------------\n\n**Features**\n\n* Add ``.clear()`` to ``MetricsMock`` making it easier to build a pytest\n  fixture with the ``MetricsMock`` context and manipulate records for easy\n  testing. (#29)\n\n**Bug fixes**\n\n* Update Cloudwatch backend fixing ``.timing()`` and ``.histogram()`` to\n  send ``histogram`` metrics type which Datadog now supports. (#31)\n\n\n1.1.2 (April 5th, 2018)\n-----------------------\n\n**Typo fixes**\n\n* Fix the date from the previous release. Ugh.\n\n\n1.1.1 (April 5th, 2018)\n-----------------------\n\n**Features**\n\n* Official switch to semver.\n\n**Bug fixes**\n\n* Fix ``MetricsMock`` so it continues to work even if ``configure``\n  is called. (#27)\n\n\n1.1 (November 13th, 2017)\n-------------------------\n\n**Features**\n\n* Added ``markus.utils.generate_tag`` utility function\n\n\n1.0 (October 30th, 2017)\n------------------------\n\n**Features**\n\n* Added support for Python 2.7.\n\n* Added a ``markus.backends.statsd.StatsdMetrics`` backend that uses\n  pystatsd client for statsd pings. Thank you, Javier!\n\n**Bug fixes**\n\n* Added ``LoggingRollupMetrics`` to docs.\n\n* Mozilla has been running Markus in production for 6 months so we\n  can mark it production-ready now.\n\n\n0.2 (April 19th, 2017)\n----------------------\n\n**Features**\n\n* Added a ``markus.backends.logging.LoggingRollupMetrics`` backend that\n  rolls up metrics and does some light math on them. Possibly helpful\n  for light profiling for development.\n\n**Bug fixes**\n\n* Lots of documentation fixes. Thank you, Peter!\n\n\n0.1 (April 10th, 2017)\n----------------------\n\nInitial writing.\n",
    "bugtrack_url": null,
    "license": "MPLv2",
    "summary": "Metrics system for generating statistics about your app",
    "version": "4.2.0",
    "split_keywords": [
        "metrics",
        "datadog",
        "statsd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c62081a55e2e5f74fbfb5ca6f4d0927b2c4ea88e6da136ebfdb0f361e9744933",
                "md5": "2aa44043aa5ecce9524e2fe39d6573ff",
                "sha256": "156398b7de56db4e8ef420a80fcce1c49b6d3d41405874a3e128cb209cf4bfd8"
            },
            "downloads": -1,
            "filename": "markus-4.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2aa44043aa5ecce9524e2fe39d6573ff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 25523,
            "upload_time": "2023-03-30T19:47:38",
            "upload_time_iso_8601": "2023-03-30T19:47:38.844826Z",
            "url": "https://files.pythonhosted.org/packages/c6/20/81a55e2e5f74fbfb5ca6f4d0927b2c4ea88e6da136ebfdb0f361e9744933/markus-4.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c174260d7e51a54445f259af71242da8d888778880061d5c8927adab9a1eee8",
                "md5": "6b68ddd3fa016a1f79b9569b0c8c117e",
                "sha256": "9dd41ce53b25a3e806b0d065808fec00c4ec945e80cf5a72431bf9b61b44d7fb"
            },
            "downloads": -1,
            "filename": "markus-4.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6b68ddd3fa016a1f79b9569b0c8c117e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 37198,
            "upload_time": "2023-03-30T19:47:40",
            "upload_time_iso_8601": "2023-03-30T19:47:40.642951Z",
            "url": "https://files.pythonhosted.org/packages/3c/17/4260d7e51a54445f259af71242da8d888778880061d5c8927adab9a1eee8/markus-4.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-30 19:47:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "willkg",
    "github_project": "markus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "markus"
}
        
Elapsed time: 0.05145s