Exposes applipy metrics in prometheus format
Project description
Applipy Prometheus Metrics
pip install applipy_prometheus
Exposes applipy metrics in prometheus format as an HTTP endpoint with path /metrics.
Usage
Add the applipy_prometheus.PrometheusModule to your application. Optionally,
define through which http server to expose the /metrics endpoint, if no name
is given it defaults to the anonymous server:
# dev.yaml
app:
name: demo
modules:
- applipy_prometheus.PrometheusModule
http:
internal:
host: 0.0.0.0
port: 8080
prometheus.server_name: internal
To run this test just install applipy_prometheus and pyyaml and run the applipy application:
pip install applipy_prometheus pyyaml
python -m applipy
You can now query http://0.0.0.0:8080/metrics and you should see some metrics for that endpoint (you'll have to query it twice to see metrics).
This module uses
applipy_metrics's registry to
load the metrics and generate the Prometheus document.
Metrics Endpoint Wrapper
This library also comes with MetricsWrapper. It is an
applipy_http.EndpointWrapper
that can be bound to your APIs and will automatically measure the request time
and store it as a summary with name applipy_web_request_duration_seconds.
The wrapper has priority 100.
The metrics are tagged by default with:
method: HTTP request method (i.e.GET,POST, etc.)path: path of the endpoint handling the requestserver: name of the server handling the request (anonymous server is empty string)status: status code of the response
On top of that, a dictionary is added to the Context with the key
metrics.tags where you can add custom tags to the metric.
Example
from aiohttp import web
from applipy import Module
from applipy_http import Api, HttpModule, Endpoint, EndpointWrapper, PathFormatter
from applipy_inject import with_names
from applipy_prometheus import MetricsWrapper
class MyEndpoint(Endpoint):
async def get(self, req, ctx):
ctx['metrics.tags']['custom_tag'] = 'value'
return web.Response(body='Ok')
class MyModule(Module):
def configure(self, bind, register):
bind(Endpoint, MyEndpoint, name='myApi')
bind(PathFormatter, name='myApi')
# Register the MetricsWrapper to my Api
bind(EndpointWrapper, MetricsWrapper, name='myApi')
bind(with_names(Api, 'myApi'))
@classmethod
def depends_on(cls):
return HttpModule,
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file applipy_prometheus-0.11.2.tar.gz.
File metadata
- Download URL: applipy_prometheus-0.11.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b3e28b917cad2f8e07011ed471328164edc14491d1a98090986565cf490683c
|
|
| MD5 |
0ffe2198e4196a70fc9d4ddbe08b2877
|
|
| BLAKE2b-256 |
d136084b18cfd5098c4a7647bd8160a5078d736f8f5d573af4a2e5693078fbdf
|
File details
Details for the file applipy_prometheus-0.11.2-py3-none-any.whl.
File metadata
- Download URL: applipy_prometheus-0.11.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f58f6b35d948457e39d2adaae507049f48bbfe15f0c6626731e9789d3e350681
|
|
| MD5 |
02581be593bb4f491f3e98018d22e3bf
|
|
| BLAKE2b-256 |
b52adba79d50e96ed6891a9b689bdba6d6cb35cb4adc44707333d071da79b247
|