Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Bogdanp/apistar_prometheus

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.