Skip to main content

nameko-prometheus is a dependency for the nameko microservice framework which allows application metrics collection with Prometheus.

Project description

docs

Documentation Status

tests

Github Actions Build Status

package

PyPI Package latest release PyPI Wheel Supported versions Supported implementations
Commits since latest release

nameko-prometheus is a dependency for the nameko microservice framework which allows application metrics collection with Prometheus.

Features

  • automatic collection of request latency metrics for RPC methods, event handlers and HTTP requests

  • custom application metrics are also exposed automatically

  • HTTP endpoint exposing metrics to be scraped by Prometheus

Installation

pip install nameko-prometheus

You can also install the in-development version with:

pip install https://github.com/emplocity/nameko-prometheus/archive/master.zip

Usage

Define your application metrics using types from prometheus_client, such as Counter, Gauge, Histogram, etc. Add a PrometheusMetrics dependency provider to your service class. Then add a HTTP entrypoint (usually routed under /metrics URL) that forwards the request to expose_metrics() method of the provider. That’s it!

from nameko.rpc import rpc
from nameko.web.handlers import http
from nameko_prometheus import PrometheusMetrics
from prometheus_client import Counter


work_units = Counter(
    "my_service_work_units_total", "Total number of work units", ["work_type"]
)


class MyService:
   metrics = PrometheusMetrics()

   @rpc
   def say_hello(self):
      work_units.labels(work_type="hard").inc()
      return "Hello!"

   @http("GET", "/metrics")
   def serve_metrics(self, request):
      return self.metrics.expose_metrics(request)

There are a few automatically defined metrics as well. See the documentation of PrometheusMetrics for more.

See also the full stack example in example/ directory in this repo.

Documentation

https://nameko-prometheus.readthedocs.io/

Development

To run the all tests run:

tox

Note, to combine the coverage data from all the tox environments run:

Windows

set PYTEST_ADDOPTS=--cov-append
tox

Other

PYTEST_ADDOPTS=--cov-append tox

Development roadmap

Things we’d like to have in the future:

  • automatic registration of /metrics HTTP endpoint

  • decorator to exclude specific methods from tracing

Authors

nameko-prometheus is developed and maintained by Emplocity.

License

This work is released under the Apache 2.0 license.

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

nameko-prometheus-1.6.0.tar.gz (19.7 kB view hashes)

Uploaded Source

Built Distribution

nameko_prometheus-1.6.0-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

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