All Projects → stephenhillier → Starlette_exporter

stephenhillier / Starlette_exporter

Licence: apache-2.0
Prometheus exporter for Starlette and FastAPI

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Starlette exporter

Promcord
📊 Analyze your entire discord guild in grafana using prometheus. Message, User, Game and Voice statistics...
Stars: ✭ 39 (-54.12%)
Mutual labels:  prometheus, prometheus-exporter
Windows exporter
Prometheus exporter for Windows machines
Stars: ✭ 1,230 (+1347.06%)
Mutual labels:  prometheus, prometheus-exporter
Ssh exporter
A Prometheus exporter for running SSH commands on a remote host and collecting statistics on those outputs
Stars: ✭ 40 (-52.94%)
Mutual labels:  prometheus, prometheus-exporter
Unifiedmetrics
Fully-featured metrics collection agent for Minecraft servers. Supports Prometheus and InfluxDB. Dashboard included out-of-box.
Stars: ✭ 29 (-65.88%)
Mutual labels:  prometheus, prometheus-exporter
Script exporter
Prometheus exporter to execute scripts and collect metrics from the output or the exit status.
Stars: ✭ 84 (-1.18%)
Mutual labels:  prometheus, prometheus-exporter
Iperf3 exporter
Simple server that probes iPerf3 endpoints and exports results via HTTP for Prometheus consumption
Stars: ✭ 30 (-64.71%)
Mutual labels:  prometheus, prometheus-exporter
Unifi Poller
Application: Collect ALL UniFi Controller, Site, Device & Client Data - Export to InfluxDB or Prometheus
Stars: ✭ 1,050 (+1135.29%)
Mutual labels:  prometheus, prometheus-exporter
Postgresql exporter
A Prometheus exporter for some postgresql metrics
Stars: ✭ 26 (-69.41%)
Mutual labels:  prometheus, prometheus-exporter
Ebpf exporter
A Prometheus exporter which uses eBPF to measure block IO request latency / size
Stars: ✭ 56 (-34.12%)
Mutual labels:  prometheus, prometheus-exporter
Unifi exporter
Multiarch images for scraping Prometheus metrics from a Unifi Controller. Kubernetes / prometheus-operator compatible.
Stars: ✭ 54 (-36.47%)
Mutual labels:  prometheus, prometheus-exporter
Zk Exporter
Exposes monitoring metrics for Apache Zookeeper to Prometheus
Stars: ✭ 27 (-68.24%)
Mutual labels:  prometheus, prometheus-exporter
Systemd exporter
Exporter for systemd unit metrics
Stars: ✭ 82 (-3.53%)
Mutual labels:  prometheus, prometheus-exporter
Prometheus Tor exporter
Prometheus exporter for the TOR daemon
Stars: ✭ 20 (-76.47%)
Mutual labels:  prometheus, prometheus-exporter
Kafka exporter
Kafka exporter for Prometheus
Stars: ✭ 996 (+1071.76%)
Mutual labels:  prometheus, prometheus-exporter
Json Exporter
Prometheus exporter which fetches JSON from a URL and exports one of the values as gauge metrics
Stars: ✭ 26 (-69.41%)
Mutual labels:  prometheus, prometheus-exporter
Phpfpm exporter
Prometheus exporter for PHP-FPM.
Stars: ✭ 51 (-40%)
Mutual labels:  prometheus, prometheus-exporter
Snmp exporter
SNMP Exporter for Prometheus
Stars: ✭ 705 (+729.41%)
Mutual labels:  prometheus, prometheus-exporter
Ebpf exporter
Prometheus exporter for custom eBPF metrics
Stars: ✭ 829 (+875.29%)
Mutual labels:  prometheus, prometheus-exporter
Druid Exporter
A Golang based exporter captures druid API related metrics and receives druid-emitting HTTP JSON data.
Stars: ✭ 54 (-36.47%)
Mutual labels:  prometheus, prometheus-exporter
Citrix Adc Metrics Exporter
Export metrics from Citrix ADC (NetScaler) to Prometheus
Stars: ✭ 67 (-21.18%)
Mutual labels:  prometheus, prometheus-exporter

starlette_exporter

Prometheus exporter for Starlette and FastAPI.

The middleware collects basic metrics:

  • Counter: starlette_requests_total
  • Histogram: starlette_request_duration_seconds

Metrics include labels for the HTTP method, the path, and the response status code.

starlette_requests_total{method="GET",path="/",status_code="200"} 1.0
starlette_request_duration_seconds_bucket{le="0.01",method="GET",path="/",status_code="200"} 1.0

Use the HTTP handler handle_metrics at path /metrics to expose a metrics endpoint to Prometheus.

Usage

pip install starlette_exporter

Starlette

from starlette.applications import Starlette
from starlette_exporter import PrometheusMiddleware, handle_metrics

app = Starlette()
app.add_middleware(PrometheusMiddleware)
app.add_route("/metrics", handle_metrics)

...

FastAPI

from fastapi import FastAPI
from starlette_exporter import PrometheusMiddleware, handle_metrics

app = FastAPI()
app.add_middleware(PrometheusMiddleware)
app.add_route("/metrics", handle_metrics)

...

Options

app_name: Sets the value of the app_name label for exported metrics (default: starlette).

prefix: Sets the prefix of the exported metric names (default: starlette).

group_paths: setting this to True will populate the path label using named parameters (if any) in the router path, e.g. /api/v1/items/{item_id}. This will group requests together by endpoint (regardless of the value of item_id). This option may come with a performance hit for larger routers. Default is False, which will result in separate metrics for different URLs (e.g., /api/v1/items/42, /api/v1/items/43, etc.).

filter_unhandled_paths: setting this to True will cause the middleware to ignore requests with unhandled paths (in other words, 404 errors). This helps prevent filling up the metrics with 404 errors and/or intentially bad requests. Default is False.

buckets: accepts an optional list of numbers to use as histogram buckets. The default value is None, which will cause the library to fall back on the Prometheus defaults (currently [0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0]).

Example:

app.add_middleware(PrometheusMiddleware, app_name="hello_world", group_paths=True, prefix='myapp', buckets=[0.1, 0.25, 0.5])

Custom Metrics

starlette_exporter will export all the prometheus metrics from the process, so custom metrics can be created by using the prometheus_client API.

Example:

from prometheus_client import Counter
from starlette.responses import RedirectResponse

REDIRECT_COUNT = Counter("redirect_total", "Count of redirects", ("from",))

async def some_view(request):
    REDIRECT_COUNT.labels(from="some_view").inc()
    return RedirectResponse(url="https://example.com", status_code=302)

The new metric will now be included in the the /metrics endpoint output:

...
redirect_total{from="some_view"} 2.0
...

Developing

git clone https://github.com/stephenhillier/starlette_exporter
cd starlette_exporter
pytest tests

License

Code released under the Apache License, Version 2.0.

Dependencies

https://github.com/prometheus/client_python

https://github.com/encode/starlette

Credits

Starlette - https://github.com/encode/starlette

FastAPI - https://github.com/tiangolo/fastapi

Flask exporter - https://github.com/rycus86/prometheus_flask_exporter

Alternate Starlette exporter - https://github.com/perdy/starlette-prometheus

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].