10000 Add example for initializing metrics with labels (#589) · rayandas/client_python@02be07a · GitHub
[go: up one dir, main page]

Skip to content

Commit 02be07a

Browse files
authored
Add example for initializing metrics with labels (prometheus#589)
Signed-off-by: Michele Pittoni <michele@pittoni.org>
1 parent 3889a5d commit 02be07a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ c.labels(method='get', endpoint='/').inc()
220220
c.labels(method='post', endpoint='/submit').inc()
221221
```
222222

223+
Metrics with labels are not initialized when declared, because the client can't
224+
know what values the label can have. It is recommended to initialize the label
225+
values by calling the `.labels()` method alone:
226+
227+
```python
228+
from prometheus_client import Counter
229+
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
230+
c.labels('get', '/')
231+
c.labels('post', '/submit')
232+
```
233+
223234
### Process Collector
224235

225236
The Python client automatically exports metrics about process CPU usage, RAM,

0 commit comments

Comments
 (0)
0