8000 add restricted registry documentation (#968) · suligap/client_python@e56cfda · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit e56cfda

Browse files
add restricted registry documentation (prometheus#968)
* 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>
1 parent 377e386 commit e56cfda

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,34 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"):
737737
print("Name: {0} Labels: {1} Value: {2}".format(*sample))
738738
```
739739

740+
## Restricted registry
741+
742+
Registries support restriction to only return specific metrics.
743+
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.
744+
If you’re directly using `generate_latest`, you can use the function `restricted_registry()`.
745+
746+
```python
747+
curl --get --data-urlencode "name[]=python_gc_objects_collected_total" --data-urlencode "name[]=python_info" http://127.0.0.1:9200/metrics
748+
```
749+
750+
```python
751+
from prometheus_client import generate_latest
752+
753+
generate_latest(REGISTRY.restricted_registry(['python_gc_objects_collected_total', 'python_info']))
754+
```
755+
756+
```python
757+
# HELP python_info Python platform information
758+
# TYPE python_info gauge
759+
python_info{implementation="CPython",major="3",minor="9",patchlevel="3",version="3.9.3"} 1.0
760+
# HELP python_gc_objects_collected_total Objects collected during gc
761+
# TYPE python_gc_objects_collected_total counter
762+
python_gc_objects_collected_total{generation="0"} 73129.0
763+
python_gc_objects_collected_total{generation="1"} 8594.0
764+
python_gc_objects_collected_total{generation="2"} 296.0
765+
```
766+
767+
740768
## Links
741769

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

0 commit comments

Comments
 (0)
0