question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with labels method on metrics objects

See original GitHub issue

I am expecting to be able to set labels on a Counter like in the examples:

from prometheus_client import Counter
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
c.labels(method='get', endpoint='/').inc()

I am using prometheus-client (0.0.14) from PyPI.

$ python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from prometheus_client import Counter, CollectorRegistry
>>> reg = CollectorRegistry()
>>> c = Counter('items_total', 'number of items total', registry=reg)
>>> c.labels(first=1, another=2).inc()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Counter' object has no attribute 'labels'
>>>
>>> type(c)
<class 'prometheus_client.core.Counter'>
>>> dir(c)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_reserved_labelnames', '_samples', '_type', '_value', 'collect', 'count_exceptions', 'inc']

The Counter object does not seem to have a labels method attached to it. Perhaps some recent changes has affected the application of the decorator that applies it to the metrics? #99 kind of indicates this same problem but has words relating it to pushgateway.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
brian-brazilcommented, Mar 17, 2017
5reactions
zhaoyuan0218commented, Apr 19, 2018

you can try: g = Gauge(‘node_load5_norm’, ‘node_load5_norm’, [“host”], registry=registry) g.labels(hostname).set(value) push_to_gateway(gateway_uri, job=‘pushgateway’, registry=registry)

then: metric like this: node_load5_norm{‘host’=xx} 0.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Hardness of Metric Labeling - TTIC
The Metric Labeling problem is an elegant and powerful mathematical model capturing a wide range of classifica- tion problems. The input to the...
Read more >
Configure labels on log-based metrics - Google Cloud
All log-based metrics come with some predefined labels: Resource labels: All metrics use a monitored resource object to identify the source of time...
Read more >
Metric Labeling and Markov Random Fields
1.2. THE METRIC LABELING PROBLEM. One can make these issues precise in the following way. Consider a set P of n objects that...
Read more >
Evaluating Multi-label Classifiers - Towards Data Science
Even for the case we just discussed — multi-label classification — there's another metric called a Hamming Score, which evaluates how close your ......
Read more >
Metric Clustering via Consistent Labeling
Our technical approach is to cast a number of metric clustering problems that have been well ... Labeling problem, take both the object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found