Skip to content

Commit

Permalink
add restricted registry documentation (#968)
Browse files Browse the repository at this point in the history
* add restricted registry documentation
* show example for generate_latest

Signed-off-by: remi <remijouannet@gmail.com>
Signed-off-by: Remi Jouannet <remijouannet@gmail.com>
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
  • Loading branch information
remijouannet and csmarchbanks committed Oct 24, 2023
1 parent 377e386 commit e56cfda
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,34 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"):
print("Name: {0} Labels: {1} Value: {2}".format(*sample))
```

## Restricted registry

Registries support restriction to only return specific metrics.
If you’re using the built-in HTTP server, you can use the GET parameter "name[]", since it’s an array it can be used multiple times.
If you’re directly using `generate_latest`, you can use the function `restricted_registry()`.

```python
curl --get --data-urlencode "name[]=python_gc_objects_collected_total" --data-urlencode "name[]=python_info" http://127.0.0.1:9200/metrics
```

```python
from prometheus_client import generate_latest

generate_latest(REGISTRY.restricted_registry(['python_gc_objects_collected_total', 'python_info']))
```

```python
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="3",minor="9",patchlevel="3",version="3.9.3"} 1.0
# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 73129.0
python_gc_objects_collected_total{generation="1"} 8594.0
python_gc_objects_collected_total{generation="2"} 296.0
```


## Links

* [Releases](https://github.com/prometheus/client_python/releases): The releases page shows the history of the project and acts as a changelog.
Expand Down

0 comments on commit e56cfda

Please sign in to comment.