Skip to main content

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:

# 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)
# 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.

# my_app/settings.py
from snyk_metrics import initialise

initialise(prometheus_enabled=True, lock_registry=False)
# 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()

Metadata

Release files for snyk-metrics 0.0.6

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

Source distribution (sdist)

Source distribution for snyk-metrics 0.0.6
File Size Uploaded Provenance Actions
snyk_metrics-0.0.6.tar.gz 6.7 kB Without provenance Details for snyk_metrics-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for snyk-metrics 0.0.6
File Interpreter ABI Platform Actions
snyk_metrics-0.0.6-py3-none-any.whl Python 3 none any Details for snyk_metrics-0.0.6-py3-none-any.whl

Total release size: 15.6 kB

Release files / snyk_metrics-0.0.6.tar.gz

Download URL snyk_metrics-0.0.6.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5d9d4829d388c33bd917d8815e39e9f869e0e096237a557996d2d41fd04ef0be
BLAKE2b-256 checksum
How to use checksums
6e35b0cfa68456741f87056828682cfb5c01474980fd4bbe8a8f8bdf57a8fe02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.14 Linux/5.15.0-1056-aws

Release files / snyk_metrics-0.0.6-py3-none-any.whl

Download URL snyk_metrics-0.0.6-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92e36f8154587ed8932dd5df3495f217eda998631ef06ece51a84c678e321f75
BLAKE2b-256 checksum
How to use checksums
059e209a9770214a9f23b609c708817896f61938db6ab50f37149090ec2d89b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.10.14 Linux/5.15.0-1056-aws

Security for snyk-metrics 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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