From f5339107c2924ad1654eb64f0f15a1d50bb8085e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Thu, 19 Oct 2023 12:09:06 +0200 Subject: [PATCH 1/6] add restricted registry documentation Signed-off-by: remi --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index f1b71dcd..bae1a3fb 100644 --- a/README.md +++ b/README.md @@ -737,6 +737,39 @@ 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 + +Registry support querying a specific metric with the GET parameter "name[]". +Since it's an array it can be use multiple times. + +```python +curl -v --get --data-urlencode "name[]=python_gc_objects_collected_total" --data-urlencode "name[]=python_info" http://127.0.0.1:9200/metrics +* About to connect() to 127.0.0.1 port 9200 (#0) +* Trying 127.0.0.1... +* Connected to 127.0.0.1 (127.0.0.1) port 9200 (#0) +> GET /metrics?name[]=python_gc_objects_collected_total&name[]=python_info HTTP/1.1 +> User-Agent: curl/7.29.0 +> Host: 127.0.0.1:9200 +> Accept: */* +> +* HTTP 1.0, assume close after body +< HTTP/1.0 200 OK +< Date: Thu, 19 Oct 2023 10:00:38 GMT +< Server: WSGIServer/0.2 CPython/3.9.3 +< Content-Type: text/plain; version=0.0.4; charset=utf-8 +< Content-Length: 454 +< +# 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 +* Closing connection 0 +``` + ## Links * [Releases](https://github.com/prometheus/client_python/releases): The releases page shows the history of the project and acts as a changelog. From 3c9065cdf2ca85b0d4f7a8e6ff0e55c95f707629 Mon Sep 17 00:00:00 2001 From: remi Date: Tue, 24 Oct 2023 11:31:52 +0200 Subject: [PATCH 2/6] remove curl verbose in readme Signed-off-by: remi --- README.md | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/README.md b/README.md index bae1a3fb..a902278a 100644 --- a/README.md +++ b/README.md @@ -743,22 +743,7 @@ Registry support querying a specific metric with the GET parameter "name[]". Since it's an array it can be use multiple times. ```python -curl -v --get --data-urlencode "name[]=python_gc_objects_collected_total" --data-urlencode "name[]=python_info" http://127.0.0.1:9200/metrics -* About to connect() to 127.0.0.1 port 9200 (#0) -* Trying 127.0.0.1... -* Connected to 127.0.0.1 (127.0.0.1) port 9200 (#0) -> GET /metrics?name[]=python_gc_objects_collected_total&name[]=python_info HTTP/1.1 -> User-Agent: curl/7.29.0 -> Host: 127.0.0.1:9200 -> Accept: */* -> -* HTTP 1.0, assume close after body -< HTTP/1.0 200 OK -< Date: Thu, 19 Oct 2023 10:00:38 GMT -< Server: WSGIServer/0.2 CPython/3.9.3 -< Content-Type: text/plain; version=0.0.4; charset=utf-8 -< Content-Length: 454 -< +curl --get --data-urlencode "name[]=python_gc_objects_collected_total" --data-urlencode "name[]=python_info" http://127.0.0.1:9200/metrics # 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 @@ -767,7 +752,6 @@ python_info{implementation="CPython",major="3",minor="9",patchlevel="3",version= 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 -* Closing connection 0 ``` ## Links From 5f2633cd3b3e556c7fbc90d41f29ede28e8e2ab4 Mon Sep 17 00:00:00 2001 From: remi Date: Tue, 24 Oct 2023 13:48:17 +0200 Subject: [PATCH 3/6] show example for generate_latest Signed-off-by: remi --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a902278a..65a0c5ce 100644 --- a/README.md +++ b/README.md @@ -739,11 +739,21 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"): ## Restricted registry -Registry support querying a specific metric with the GET parameter "name[]". -Since it's an array it can be use multiple times. +Registry 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 @@ -754,6 +764,7 @@ 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. From cc43fe0ab1a8785e340a2a5faab6b8f0ff0e8d52 Mon Sep 17 00:00:00 2001 From: Remi Jouannet Date: Tue, 24 Oct 2023 17:35:17 +0200 Subject: [PATCH 4/6] Update README.md Co-authored-by: Chris Marchbanks Signed-off-by: Remi Jouannet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 65a0c5ce..58bcc5d7 100644 --- a/README.md +++ b/README.md @@ -740,7 +740,7 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"): ## Restricted registry Registry 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 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 From eba0e01a3079f3687b15fa0853ea50b0e2bcd9df Mon Sep 17 00:00:00 2001 From: Remi Jouannet Date: Tue, 24 Oct 2023 17:35:30 +0200 Subject: [PATCH 5/6] Update README.md Co-authored-by: Chris Marchbanks Signed-off-by: Remi Jouannet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58bcc5d7..1d404169 100644 --- a/README.md +++ b/README.md @@ -739,7 +739,7 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"): ## Restricted registry -Registry support restriction to only return specific metrics. +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(). From 3418d14aaf09a3dd4eeac74c426775d888e0bce7 Mon Sep 17 00:00:00 2001 From: Remi Jouannet Date: Tue, 24 Oct 2023 17:35:51 +0200 Subject: [PATCH 6/6] Update README.md Co-authored-by: Chris Marchbanks Signed-off-by: Remi Jouannet --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d404169..eff48488 100644 --- a/README.md +++ b/README.md @@ -741,7 +741,7 @@ for family in text_string_to_metric_families(u"my_gauge 1.0\n"): 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(). +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