You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-20Lines changed: 44 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -306,6 +306,19 @@ from prometheus_client import start_wsgi_server
306
306
start_wsgi_server(8000)
307
307
```
308
308
309
+
#### ASGI
310
+
311
+
To use Prometheus with [ASGI](http://asgi.readthedocs.org/en/latest/), there is
312
+
`make_asgi_app` which creates an ASGI application.
313
+
314
+
```python
315
+
from prometheus_client import make_asgi_app
316
+
317
+
app = make_asgi_app()
318
+
```
319
+
Such an application can be useful when integrating Prometheus metrics with ASGI
320
+
apps.
321
+
309
322
#### Flask
310
323
311
324
To use Prometheus with [Flask](http://flask.pocoo.org/) we need to serve metrics through a Prometheus WSGI application. This can be achieved using [Flask's application dispatching](http://flask.pocoo.org/docs/latest/patterns/appdispatch/). Below is a working example.
@@ -314,7 +327,7 @@ Save the snippet below in a `myapp.py` file
314
327
315
328
```python
316
329
from flask import Flask
317
-
from werkzeug.wsgiimport DispatcherMiddleware
330
+
from werkzeug.middleware.dispatcherimport DispatcherMiddleware
318
331
from prometheus_client import make_wsgi_app
319
332
320
333
# Create my app
@@ -452,7 +465,7 @@ used to predetermine the names of time series a `CollectorRegistry` exposes and
452
465
thus to detect collisions and duplicate registrations.
453
466
454
467
Usually custom collectors do not have to implement `describe`. If `describe` is
455
-
not implemented and the CollectorRegistry was created with `auto_desribe=True`
468
+
not implemented and the CollectorRegistry was created with `auto_describe=True`
456
469
(which is the case for the default registry) then `collect` will be called at
457
470
registration time instead of `describe`. If this could cause problems, either
458
471
implement a proper `describe`, or if that's not practical have `describe`
@@ -476,31 +489,25 @@ This comes with a number of limitations:
476
489
477
490
There's several steps to getting this working:
478
491
479
-
**One**: Gunicorn deployment
492
+
**1. Gunicorn deployment**:
480
493
481
494
The `prometheus_multiproc_dir` environment variable must be set to a directory
482
495
that the client library can use for metrics. This directory must be wiped
483
496
between Gunicorn runs (before startup is recommended).
484
497
485
-
Put the following in the config file:
486
-
```python
487
-
from prometheus_client import multiprocess
498
+
This environment variable should be set from a start-up shell script,
499
+
and not directly from Python (otherwise it may not propagate to child processes).
488
500
489
-
defchild_exit(server, worker):
490
-
multiprocess.mark_process_dead(worker.pid)
491
-
```
501
+
**2. Metrics collector**:
502
+
503
+
The application must initialize a new `CollectorRegistry`,
504
+
and store the multi-process collector inside.
492
505
493
-
**Two**: Inside the application
494
506
```python
495
507
from prometheus_client import multiprocess
496
-
from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST, Gauge
0 commit comments