From 4ee8d860ccdef5fa98e83eb5ad9e95786e0cb797 Mon Sep 17 00:00:00 2001 From: Michele Pittoni Date: Wed, 21 Oct 2020 15:05:25 +0200 Subject: [PATCH 1/4] Add example for initializing metrics with labels Signed-off-by: Michele Pittoni --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5630d769..edd7e257 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,11 @@ Taking a counter as an example: ```python from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) +# when using labels, metrics are not initialized at creation +# to initialize them (highly reccommended) use .labels() without e.g. .inc() +c.labels('get', '/') +c.labels('post', '/submit') +# then use the metrics as normal c.labels('get', '/').inc() c.labels('post', '/submit').inc() ``` From c03ca0bbe76b84d9e3f84a265f969a489271c599 Mon Sep 17 00:00:00 2001 From: Michele Pittoni Date: Wed, 21 Oct 2020 15:57:16 +0200 Subject: [PATCH 2/4] Separate label init example from common use case Signed-off-by: Michele Pittoni --- README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index edd7e257..a81ff25c 100644 --- a/README.md +++ b/README.md @@ -207,11 +207,6 @@ Taking a counter as an example: ```python from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) -# when using labels, metrics are not initialized at creation -# to initialize them (highly reccommended) use .labels() without e.g. .inc() -c.labels('get', '/') -c.labels('post', '/submit') -# then use the metrics as normal c.labels('get', '/').inc() c.labels('post', '/submit').inc() ``` @@ -225,6 +220,21 @@ c.labels(method='get', endpoint='/').inc() c.labels(method='post', endpoint='/submit').inc() ``` +Metrics with labels are not initialized when declared, because the client can't +know what values the label can have. It is reccommended to initialize the label +values by calling the `.label()` method alone: + +```python +from prometheus_client import Counter +c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) +# initialize the label values +c.labels('get', '/') +c.labels('post', '/submit') +# then use the metrics as normal +c.labels('get', '/').inc() +c.labels('post', '/submit').inc() +``` + ### Process Collector The Python client automatically exports metrics about process CPU usage, RAM, From 1b4801834a89bdd59e19c93709b5a647db51dfcd Mon Sep 17 00:00:00 2001 From: Michele Pittoni Date: Wed, 21 Oct 2020 16:01:06 +0200 Subject: [PATCH 3/4] Fix typo Signed-off-by: Michele Pittoni --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a81ff25c..afb1542d 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ c.labels(method='post', endpoint='/submit').inc() ``` Metrics with labels are not initialized when declared, because the client can't -know what values the label can have. It is reccommended to initialize the label +know what values the label can have. It is recommended to initialize the label values by calling the `.label()` method alone: ```python From 2480f098675ceb1884e23d20faeda01ac08ef1ce Mon Sep 17 00:00:00 2001 From: Michele Pittoni Date: Wed, 21 Oct 2020 16:38:45 +0200 Subject: [PATCH 4/4] Remove redundancy, fix typo Signed-off-by: Michele Pittoni --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index afb1542d..7a3da8fd 100644 --- a/README.md +++ b/README.md @@ -222,17 +222,13 @@ c.labels(method='post', endpoint='/submit').inc() Metrics with labels are not initialized when declared, because the client can't know what values the label can have. It is recommended to initialize the label -values by calling the `.label()` method alone: +values by calling the `.labels()` method alone: ```python from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) -# initialize the label values c.labels('get', '/') c.labels('post', '/submit') -# then use the metrics as normal -c.labels('get', '/').inc() -c.labels('post', '/submit').inc() ``` ### Process Collector