{"id":25379268,"url":"https://github.com/mozilla-services/markus","last_synced_at":"2025-04-09T20:02:20.301Z","repository":{"id":19694939,"uuid":"87572990","full_name":"mozilla-services/markus","owner":"mozilla-services","description":"Markus is a Python library for generating metrics","archived":false,"fork":false,"pushed_at":"2025-04-01T14:16:23.000Z","size":340,"stargazers_count":70,"open_issues_count":6,"forks_count":8,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-09T20:01:45.945Z","etag":null,"topics":["library","metrics","python","statsd"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mozilla-services.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-07T17:58:50.000Z","updated_at":"2025-04-01T14:16:20.000Z","dependencies_parsed_at":"2023-02-13T03:55:12.444Z","dependency_job_id":"880f258a-7a11-46cc-91d9-e42bb39493c1","html_url":"https://github.com/mozilla-services/markus","commit_stats":{"total_commits":193,"total_committers":8,"mean_commits":24.125,"dds":0.1295336787564767,"last_synced_commit":"7ae69d2f1b6cc1b49e2f1ca66fc9a1978777e035"},"previous_names":["mozilla-services/markus","willkg/markus"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fmarkus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fmarkus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fmarkus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fmarkus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mozilla-services","download_url":"https://codeload.github.com/mozilla-services/markus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103863,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["library","metrics","python","statsd"],"created_at":"2025-02-15T05:08:52.973Z","updated_at":"2025-04-09T20:02:20.194Z","avatar_url":"https://github.com/mozilla-services.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"======\nMarkus\n======\n\nMarkus is a Python library for generating metrics.\n\n:Code:          https://github.com/mozilla-services/markus\n:Issues:        https://github.com/mozilla-services/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 and any\noptions they require to publish metrics.\n\nFor example, let us configure Markus to publish metrics to the Python logging\ninfrastructure and Datadog::\n\n    import markus\n\n    markus.configure(\n        backends=[\n            {\n                # Publish metrics to the Python logging infrastructure\n                \"class\": \"markus.backends.logging.LoggingMetrics\",\n            },\n            {\n                # Publish 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\nOnce you've added code that publishes metrics, you'll want to test it and make\nsure it's working correctly. Markus comes with a ``markus.testing.MetricsMock``\nto make testing and asserting specific outcomes 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla-services%2Fmarkus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmozilla-services%2Fmarkus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla-services%2Fmarkus/lists"}