-
Notifications
You must be signed in to change notification settings - Fork 816
Add example for initializing metrics with labels #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Michele Pittoni <michele@pittoni.org>
README.md
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really fit here, as a less common use case is being wedged in front of the simple normal usage.
This would be better as a separate thing down the send of this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I thought it was a strong enough recommendation to highlight it in the normal use case. Pushed a revision.
Signed-off-by: Michele Pittoni <michele@pittoni.org>
README.md
Outdated
# initialize the label values | ||
c.labels('get', '/') | ||
c.labels('post', '/submit') | ||
# then use the metrics as normal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need from this bit onwards.
README.md
Outdated
@@ -220,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 recommended to initialize the label | |||
values by calling the `.label()` method alone: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops
README.md
Outdated
```python | ||
from prometheus_client import Counter | ||
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) | ||
# initialize the label values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't needed.
Signed-off-by: Michele Pittoni <michele@pittoni.org>
Thanks! |
I know metrics should be initialized, but I wasn't able to find how to do it if they have labels in this doc. I eventually found the answer in Brian's blog, which is always an amazing source.