@@ -489,31 +489,25 @@ This comes with a number of limitations:
489
489
490
490
There's several steps to getting this working:
491
491
492
- ** One ** : Gunicorn deployment
492
+ ** 1. Gunicorn deployment** :
493
493
494
494
The ` prometheus_multiproc_dir ` environment variable must be set to a directory
495
495
that the client library can use for metrics. This directory must be wiped
496
496
between Gunicorn runs (before startup is recommended).
497
497
498
- Put the following in the config file:
499
- ``` python
500
- 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).
501
500
502
- def child_exit (server , worker ):
503
- multiprocess.mark_process_dead(worker.pid)
504
- ```
501
+ ** 2. Metrics collector** :
502
+
503
+ The application must initialize a new ` CollectorRegistry ` ,
504
+ and store the multi-process collector inside.
505
505
506
- ** Two** : Inside the application
507
506
``` python
508
507
from prometheus_client import multiprocess
509
- from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST , Gauge
510
-
511
- # Example gauge.
512
- IN_PROGRESS = Gauge(" inprogress_requests" , " help" , multiprocess_mode = ' livesum' )
513
-
508
+ from prometheus_client import generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST
514
509
515
510
# Expose metrics.
516
- @IN_PROGRESS.track_inprogress ()
517
511
def app (environ , start_response ):
518
512
registry = CollectorRegistry()
519
513
multiprocess.MultiProcessCollector(registry)
@@ -527,19 +521,36 @@ def app(environ, start_response):
527
521
return iter ([data])
528
522
```
529
523
530
- ** Three** : Instrumentation
524
+ ** 3. Gunicorn configuration** :
525
+
526
+ The ` gunicorn ` configuration file needs to include the following function:
527
+
528
+ ``` python
529
+ from prometheus_client import multiprocess
530
+
531
+ def child_exit (server , worker ):
532
+ multiprocess.mark_process_dead(worker.pid)
533
+ ```
531
534
532
- Counters, Summarys and Histograms work as normal.
535
+ ** 4. Metrics tuning (Gauge) ** :
533
536
534
- Gauges have several modes they can run in, which can be selected with the
535
- ` multiprocess_mode ` parameter.
537
+ When ` Gauge ` metrics are used, additional tuning needs to be performed.
538
+ Gauges have several modes they can run in, which can be selected with the ` multiprocess_mode ` parameter.
536
539
537
540
- 'all': Default. Return a timeseries per process alive or dead.
538
541
- 'liveall': Return a timeseries per process that is still alive.
539
542
- 'livesum': Return a single timeseries that is the sum of the values of alive processes.
540
543
- 'max': Return a single timeseries that is the maximum of the values of all processes, alive or dead.
541
544
- 'min': Return a single timeseries that is the minimum of the values of all processes, alive or dead.
542
545
546
+ ``` python
547
+ from prometheus_client import Gauge
548
+
549
+ # Example gauge
550
+ IN_PROGRESS = Gauge(" inprogress_requests" , " help" , multiprocess_mode = ' livesum' )
551
+ ```
552
+
553
+
543
554
## Parser
544
555
545
556
The Python client supports parsing the Prometheus text format.
0 commit comments