Skip to content

feat: add native Prometheus metrics exporter to stats server#2754

Open
lavr wants to merge 1 commit intounbit:masterfrom
lavr:prometheus-exporter
Open

feat: add native Prometheus metrics exporter to stats server#2754
lavr wants to merge 1 commit intounbit:masterfrom
lavr:prometheus-exporter

Conversation

@lavr
Copy link
Copy Markdown

@lavr lavr commented Mar 29, 2026

Motivation

Prometheus has become the de facto standard for application monitoring. In practice, virtually no production deployment goes without Prometheus metrics - it is the first thing teams set up for observability.

In real-world production environments, it is essential to monitor uWSGI internals: worker busyness, request rates, memory consumption, harakiri counts, queue lengths. Currently, the only way to expose these metrics to Prometheus is to run a sidecar exporter (typically uwsgi_exporter). This adds operational complexity - an extra container/process to deploy, configure, and maintain - and consumes additional resources, all just to translate JSON stats into Prometheus format.

This PR eliminates the need for a sidecar by adding native Prometheus exposition format support directly into the uWSGI stats server.

Changes

  • GET /metrics on the stats server returns Prometheus text exposition format
  • All other paths return JSON as before - fully backwards compatible
  • Metric names are compatible with timonwong/uwsgi_exporter for drop-in replacement
  • The prometheus path is configurable via --stats-prometheus-path
  • The HTTP stats layer is refactored into uwsgi_stats_read_request() / uwsgi_stats_send_http_header() with enum uwsgi_stats_format for clean format selection
  • Integration tests for both JSON and Prometheus endpoints

Usage

No additional flags required in uwsgi config. The /metrics endpoint is automatically available on the existing stats HTTP server:

[uwsgi]
stats = :9191
stats-http = true

Prometheus scrape config:

scrape_configs:
- job_name: uwsgi
  static_configs:
    - targets: ['localhost:9191']

No extra flags, no sidecar.

Closes #1733

@lavr lavr force-pushed the prometheus-exporter branch from ecd5a27 to 93c1a79 Compare March 29, 2026 19:03
Add a built-in Prometheus exposition format endpoint to the uWSGI stats
server, eliminating the need for external sidecar exporters like
uwsgi_exporter. Metric names are compatible with timonwong/uwsgi_exporter
for drop-in replacement.

GET /metrics returns Prometheus text format (42 metrics covering global,
socket, worker, app, core, and cache stats). All other paths return JSON
as before. The prometheus path is configurable via --stats-prometheus-path.

The HTTP stats layer is split into uwsgi_stats_read_request() and
uwsgi_stats_send_http_header() with an enum uwsgi_stats_format for
clean format selection.

Includes integration tests for both JSON and Prometheus endpoints.
@lavr lavr force-pushed the prometheus-exporter branch from 93c1a79 to 0590ae6 Compare March 29, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add prometheus exporter

1 participant