nameko-prometheus is a dependency for the nameko microservice framework which allows application metrics collection with Prometheus.
Project description
docs |
|
---|---|
tests |
|
package |
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
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
License
This work is released under the Apache 2.0 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nameko-prometheus-1.6.0.tar.gz
.
File metadata
- Download URL: nameko-prometheus-1.6.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a772885b9b21a9f684b36a36377ef0736944cc585d79db199b3c621cfb7d702a |
|
MD5 | 7f271b834a2ba80e8f4c7f1e0ae32887 |
|
BLAKE2b-256 | f8946c213a042ac1332a1ce7f8f82eda325eccef3212751a8b4fceddf402c9d7 |
File details
Details for the file nameko_prometheus-1.6.0-py3-none-any.whl
.
File metadata
- Download URL: nameko_prometheus-1.6.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14dabded4763e25da5da60104396c0a0d02846f396a4adddfcdfff7425ff46e8 |
|
MD5 | 2e34b5ccb7bd9159433697a5d02caf72 |
|
BLAKE2b-256 | 8e0f75ba99e278c1f849a27a4cd0c67878bae64d710e2ee1e6fb5ec6c7ee0bfd |