This repository has been archived by the owner. It is now read-only.
Prometheus metrics for API Star apps.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
apistar_prometheus
tests
tests_multiprocess
.bumpversion.cfg
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
Pipfile
Pipfile.lock
README.md
setup.cfg
setup.py

README.md

apistar_prometheus

Build Status Test Coverage Maintainability PyPI version

Prometheus metrics for API Star apps.

Requirements

Installation

Use pipenv (or plain pip) to install the package:

pipenv install apistar_prometheus

To hook it into your app, add the Prometheus component to your app's components list, add a route for the expose_metrics handler and add before_request and after_request as the first and last hooks, respectively.

from apistar import App, Route
from apistar_prometheus import PrometheusComponent, PrometheusHooks, expose_metrics

routes = [
    # ...
    Route("/metrics", method="GET", handler=expose_metrics),
]

components = [
    PrometheusComponent(),
]

event_hooks = [
    PrometheusHooks(),
]

app = App(
    routes=routes,
    components=components,
    event_hooks=event_hooks,
)

Multiprocess mode

The default configuration assumes a single multi-threaded worker process. To expose metrics in a multiprocess configuration (eg. using gunicorn), set the prometheus_multiprocess_dir environment variable and use the expose_metrics_multiprocess handler.

from apistar_prometheus import PrometheusComponent, PrometheusHooks, expose_metrics_multiprocess

routes = [
    # ...,
    Route("/metrics", method="GET", handler=expose_metrics_multiprocess),
]

License

apistar_prometheus is licensed under Apache 2.0. Please see LICENSE for licensing details.