A uWSGI plugin that exports metrics in Prometheus text exposition format.
This plugin reads metrics from uWSGI's metrics subsystem and exposes them in Prometheus format. It converts uWSGI's hierarchical metric names (like worker.1.requests) into Prometheus metrics with labels (like uwsgi_worker_requests{worker="1"}).
The plugin supports two modes:
- Route handler: Serves metrics through the application workers at a specific path
- Dedicated server: Runs a separate metrics server in the master process
cd /path/to/uwsgi
python uwsgiconfig.py --plugin plugins/metrics_prometheusThis creates metrics_prometheus_plugin.so in the current directory.
Copy the plugin to where uWSGI can find it:
# System-wide installation
cp metrics_prometheus_plugin.so /usr/lib/uwsgi/plugins/
# Or use an absolute path in your config
# plugin = /path/to/metrics_prometheus_plugin.soThe dedicated server runs in the master process and doesn't use application workers.
[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = :9090
# Your application config
http = :8080
wsgi-file = app.py
processes = 4Access metrics at http://localhost:9090 (any path works).
The route handler serves metrics through application workers.
[uwsgi]
enable-metrics = true
plugin = metrics_prometheus
route = ^/metrics$ prometheus-metrics:
# Your application config
http = :8080
wsgi-file = app.py
processes = 4Access metrics at http://localhost:8080/metrics (only the matched path).
You can enable both modes simultaneously if needed.
[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = :9090
route = ^/metrics$ prometheus-metrics:
# Your application config
http = :8080
wsgi-file = app.py
processes = 4| Option | Description |
|---|---|
--enable-metrics |
Required. Enables uWSGI's metrics subsystem |
--master |
Required for dedicated server mode |
--prometheus-server ADDRESS |
Enable dedicated server on ADDRESS (e.g., :9090, 127.0.0.1:9090) |
--prometheus-prefix STRING |
Prefix for metric names (default: uwsgi_) |
--prometheus-no-workers |
Don't export per-worker metrics |
--prometheus-no-help |
Don't include HELP comments |
--prometheus-no-type |
Don't include TYPE comments |
TCP socket:
:9090- Listen on all interfaces127.0.0.1:9090- Listen on localhost only0.0.0.0:9090- Listen on all interfaces
Unix socket:
/tmp/metrics.sock- Unix domain socket
The plugin converts uWSGI metrics to Prometheus format:
| uWSGI Metric | Prometheus Metric | Labels |
|---|---|---|
worker.1.requests |
uwsgi_worker_requests |
worker="1" |
worker.2.exceptions |
uwsgi_worker_exceptions |
worker="2" |
core.1.2.requests |
uwsgi_core_requests |
worker="1", core="2" |
Numeric segments in metric names become labels:
- First number:
workerlabel - Second number:
corelabel - Third number:
threadlabel - Fourth number:
idlabel
Text segments become the metric name with dots replaced by underscores.
Configure Prometheus to scrape the metrics endpoint:
scrape_configs:
- job_name: 'uwsgi'
static_configs:
- targets: ['localhost:9090']
scrape_interval: 15sIf using route handler mode, specify the metrics path:
scrape_configs:
- job_name: 'uwsgi'
static_configs:
- targets: ['localhost:8080']
metrics_path: '/metrics'
scrape_interval: 15sCheck that metrics are valid:
curl -s http://localhost:9090 | promtool check metricsError: Metrics subsystem not initialized
Make sure you have:
enable-metrics = trueCheck that your uWSGI binary supports metrics:
uwsgi --help | grep enable-metricsIf the option doesn't appear, your uWSGI binary was compiled without metrics support.
Error: Failed to bind to :9090
Check if the port is already in use:
netstat -ln | grep 9090Make sure you have:
master = trueError: !!! no plugin loaded !!!
Check that the plugin file exists:
ls -l metrics_prometheus_plugin.soTry using an absolute path:
plugin = /full/path/to/metrics_prometheus_plugin.so[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = 127.0.0.1:9090
http = :8080
wsgi-file = app.py
processes = 4[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = :9090
prometheus-prefix = myapp_
http = :8080
wsgi-file = app.py
processes = 4[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = :9090
prometheus-no-workers = true
prometheus-no-help = true
http = :8080
wsgi-file = app.py
processes = 16[uwsgi]
master = true
enable-metrics = true
plugin = metrics_prometheus
prometheus-server = /tmp/uwsgi-metrics.sock
chmod-socket = 660
http = :8080
wsgi-file = app.py
processes = 4Start the server:
./uwsgi --ini config.iniCheck metrics:
curl http://localhost:9090Validate format:
curl -s http://localhost:9090 | promtool check metricsEdit uwsgiplugin.py and add debug flags:
CFLAGS = ['-g', '-O0']Then rebuild:
python uwsgiconfig.py --plugin plugins/metrics_prometheusgdb --args uwsgi --plugin ./metrics_prometheus_plugin.so --ini config.ini
(gdb) break prometheus_generate_metrics
(gdb) runvalgrind --leak-check=full uwsgi --plugin ./metrics_prometheus_plugin.so --ini config.iniplugin.c- Main plugin source codeuwsgiplugin.py- Build configurationREADME.md- This filePLUGIN_README.md- Developer documentation