|
| 1 | +Prometheus Instrumentation |
| 2 | +========================== |
| 3 | + |
| 4 | +This shows how to use ``opentelemetry-exporter-prometheus`` to automatically generate Prometheus metrics. |
| 5 | + |
| 6 | +The source files of these examples are available :scm_web:`here <docs/examples/prometheus-grafana/>`. |
| 7 | + |
| 8 | +Preparation |
| 9 | +----------- |
| 10 | + |
| 11 | +This example will be executed in a separate virtual environment: |
| 12 | + |
| 13 | +.. code-block:: |
| 14 | +
|
| 15 | + $ mkdir prometheus_auto_instrumentation |
| 16 | + $ virtualenv prometheus_auto_instrumentation |
| 17 | + $ source prometheus_auto_instrumentation/bin/activate |
| 18 | +
|
| 19 | +
|
| 20 | +Installation |
| 21 | +------------ |
| 22 | + |
| 23 | +.. code-block:: |
| 24 | +
|
| 25 | + $ pip install -r requirements.txt |
| 26 | +
|
| 27 | +
|
| 28 | +Execution |
| 29 | +--------- |
| 30 | + |
| 31 | +.. code-block:: |
| 32 | +
|
| 33 | + $ python ./prometheus-monitor.py |
| 34 | + $ Server is running at http://localhost:8000 |
| 35 | +
|
| 36 | +Now you can visit http://localhost:8000/metrics to see Prometheus metrics. |
| 37 | +You should see something like: |
| 38 | + |
| 39 | +.. code-block:: |
| 40 | +
|
| 41 | + # HELP python_gc_objects_collected_total Objects collected during gc |
| 42 | + # TYPE python_gc_objects_collected_total counter |
| 43 | + python_gc_objects_collected_total{generation="0"} 320.0 |
| 44 | + python_gc_objects_collected_total{generation="1"} 58.0 |
| 45 | + python_gc_objects_collected_total{generation="2"} 0.0 |
| 46 | + # HELP python_gc_objects_uncollectable_total Uncollectable objects found during GC |
| 47 | + # TYPE python_gc_objects_uncollectable_total counter |
| 48 | + python_gc_objects_uncollectable_total{generation="0"} 0.0 |
| 49 | + python_gc_objects_uncollectable_total{generation="1"} 0.0 |
| 50 | + python_gc_objects_uncollectable_total{generation="2"} 0.0 |
| 51 | + # HELP python_gc_collections_total Number of times this generation was collected |
| 52 | + # TYPE python_gc_collections_total counter |
| 53 | + python_gc_collections_total{generation="0"} 61.0 |
| 54 | + python_gc_collections_total{generation="1"} 5.0 |
| 55 | + python_gc_collections_total{generation="2"} 0.0 |
| 56 | + # HELP python_info Python platform information |
| 57 | + # TYPE python_info gauge |
| 58 | + python_info{implementation="CPython",major="3",minor="8",patchlevel="5",version="3.8.5"} 1.0 |
| 59 | + # HELP MyAppPrefix_my_counter_total |
| 60 | + # TYPE MyAppPrefix_my_counter_total counter |
| 61 | + MyAppPrefix_my_counter_total 964.0 |
| 62 | + |
| 63 | +``MyAppPrefix_my_counter_total`` is the custom counter created in the application with the custom prefix ``MyAppPrefix``. |
0 commit comments