snyk-metrics


Namesnyk-metrics JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/snyk/python-metrics
SummaryPython library to interact transparently with Prometheus, Pushgateway and Dogstatsd.
upload_time2023-04-12 11:10:35
maintainer
docs_urlNone
authorSnyk Security R&D
requires_python>=3.7,<4.0
licenseApache-2.0
keywords prometheus datadog metrics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # snyk-python-metrics

Python library to interact transparently with Prometheus, Pushgateway and
Dogstatsd.

## Usage

The client can be used with two different approaches, one more opinionated and
structured, with all the metrics created and registered at the creation of the
client, and one more flexible, where metrics can be registered at any time.

The first approach should help keeping the application using this client cleaner
and the metrics management in a centralised place.

### Example 1 - "Locked Registry"

In this example all the metrics used by the application are registered as part
of the client initialisation.

Example:

```python
# my_app/settings.py
from snyk_metrics import initialise, Counter

counter_1 = Counter(
    name="my_app_counter",
    documentation="Simple example counter",
    label_names=None,
)
counter_2 = Counter(
    name="my_app_requests",
    documentation="Requests per endpoint and method",
    label_names=("endpoint", "method"),
)

metrics = [counter_1, counter_2]

initialise(metrics=metrics, prometheus_enabled=True)
```

```python
# my_app/api/endpoints.py
from my_app.metrics import counter_1, counter_2


def my_function():
    counter_1.increment()


def foo_get_endpoint():
    counter_2.increment()
```

### Example 2 - "Unstructured flexibility"

In this example metrics are created and used within the same file. It could make
it harder to keep track of all the metrics in the application, but it can also
help in keeping them closer to the part of the project where the metrics are
used.

```python
# my_app/settings.py
from snyk_metrics import initialise

initialise(prometheus_enabled=True, lock_registry=False)
```

```python
# my_app/api/endpoints.py
from snyk_metrics import Counter

counter_1 = Counter(
    name="my_app_counter",
    documentation="Simple example counter",
    label_names=None,
)
counter_2 = Counter(
    name="my_app_requests",
    documentation="Requests per endpoint and method",
    label_names=("endpoint", "method"),
)


def my_function():
    counter_1.increment()


def foo_get_endpoint():
    counter_2.increment()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/snyk/python-metrics",
    "name": "snyk-metrics",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "prometheus,datadog,metrics",
    "author": "Snyk Security R&D",
    "author_email": "security-engineering@snyk.io",
    "download_url": "https://files.pythonhosted.org/packages/15/87/1e710a631ea4cdd2cacf4c783a4cdc831d7b9cf04bcd1d4a2b97bfec3d6f/snyk_metrics-0.0.4.tar.gz",
    "platform": null,
    "description": "# snyk-python-metrics\n\nPython library to interact transparently with Prometheus, Pushgateway and\nDogstatsd.\n\n## Usage\n\nThe client can be used with two different approaches, one more opinionated and\nstructured, with all the metrics created and registered at the creation of the\nclient, and one more flexible, where metrics can be registered at any time.\n\nThe first approach should help keeping the application using this client cleaner\nand the metrics management in a centralised place.\n\n### Example 1 - \"Locked Registry\"\n\nIn this example all the metrics used by the application are registered as part\nof the client initialisation.\n\nExample:\n\n```python\n# my_app/settings.py\nfrom snyk_metrics import initialise, Counter\n\ncounter_1 = Counter(\n    name=\"my_app_counter\",\n    documentation=\"Simple example counter\",\n    label_names=None,\n)\ncounter_2 = Counter(\n    name=\"my_app_requests\",\n    documentation=\"Requests per endpoint and method\",\n    label_names=(\"endpoint\", \"method\"),\n)\n\nmetrics = [counter_1, counter_2]\n\ninitialise(metrics=metrics, prometheus_enabled=True)\n```\n\n```python\n# my_app/api/endpoints.py\nfrom my_app.metrics import counter_1, counter_2\n\n\ndef my_function():\n    counter_1.increment()\n\n\ndef foo_get_endpoint():\n    counter_2.increment()\n```\n\n### Example 2 - \"Unstructured flexibility\"\n\nIn this example metrics are created and used within the same file. It could make\nit harder to keep track of all the metrics in the application, but it can also\nhelp in keeping them closer to the part of the project where the metrics are\nused.\n\n```python\n# my_app/settings.py\nfrom snyk_metrics import initialise\n\ninitialise(prometheus_enabled=True, lock_registry=False)\n```\n\n```python\n# my_app/api/endpoints.py\nfrom snyk_metrics import Counter\n\ncounter_1 = Counter(\n    name=\"my_app_counter\",\n    documentation=\"Simple example counter\",\n    label_names=None,\n)\ncounter_2 = Counter(\n    name=\"my_app_requests\",\n    documentation=\"Requests per endpoint and method\",\n    label_names=(\"endpoint\", \"method\"),\n)\n\n\ndef my_function():\n    counter_1.increment()\n\n\ndef foo_get_endpoint():\n    counter_2.increment()\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python library to interact transparently with Prometheus, Pushgateway and Dogstatsd.",
    "version": "0.0.4",
    "split_keywords": [
        "prometheus",
        "datadog",
        "metrics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4811de6d3d1dd7a73e33f3de83cf0876dfce17ec121048d69ce074f1e13f89a3",
                "md5": "1a4c465bd1455156c89d2e405ba4ab42",
                "sha256": "3567d9b6acff4407ca4a53d54290c624c2239e2e57947888d2bbe6fb7fbb4bcb"
            },
            "downloads": -1,
            "filename": "snyk_metrics-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1a4c465bd1455156c89d2e405ba4ab42",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 8856,
            "upload_time": "2023-04-12T11:10:34",
            "upload_time_iso_8601": "2023-04-12T11:10:34.284136Z",
            "url": "https://files.pythonhosted.org/packages/48/11/de6d3d1dd7a73e33f3de83cf0876dfce17ec121048d69ce074f1e13f89a3/snyk_metrics-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15871e710a631ea4cdd2cacf4c783a4cdc831d7b9cf04bcd1d4a2b97bfec3d6f",
                "md5": "037309ffb51349bb3c1241c5add755a6",
                "sha256": "79c32327f7017039b7cb89877918160d9a701a094bb1f6dea7c7ccfaa6fab399"
            },
            "downloads": -1,
            "filename": "snyk_metrics-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "037309ffb51349bb3c1241c5add755a6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 6696,
            "upload_time": "2023-04-12T11:10:35",
            "upload_time_iso_8601": "2023-04-12T11:10:35.418473Z",
            "url": "https://files.pythonhosted.org/packages/15/87/1e710a631ea4cdd2cacf4c783a4cdc831d7b9cf04bcd1d4a2b97bfec3d6f/snyk_metrics-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-12 11:10:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "snyk",
    "github_project": "python-metrics",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "lcname": "snyk-metrics"
}
        
Elapsed time: 1.25743s