Skip to content

Conversation

@mpitt
Copy link
Contributor

@mpitt mpitt commented Oct 21, 2020

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.

Signed-off-by: Michele Pittoni <michele@pittoni.org>
README.md Outdated
```python
from prometheus_client import Counter
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
# when using labels, metrics are not initialized at creation
Copy link
Contributor

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.

Copy link
Contributor Author

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.

mpitt added 2 commits October 21, 2020 15:57
Signed-off-by: Michele Pittoni <michele@pittoni.org>
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
Copy link
Contributor

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

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

labels

Copy link
Contributor Author

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
Copy link
Contributor

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>
@brian-brazil brian-brazil merged commit 02be07a into prometheus:master Oct 21, 2020
@brian-brazil
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants