python_client counter with label

2,300 views
Skip to first unread message

Marc Pawlowsky

unread,
Jun 15, 2017, 12:05:47 PM6/15/17
to Prometheus Users
Can anybody tell me how to send a metric with labels using the python_client

I have:
counter= Counter(metric, metric,
labelnames=['client'], labelvalues=[ data['client'] ])
print counter
print dir(counter)
counter.inc(diff)

<prometheus_client.core._LabelWrapper object at 0xcf8ed0>
['class', 'delattr', 'dict', 'doc', 'format', 'getattribute', 'hash', 'init', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_kwargs', '_labelnames', '_lock', '_metrics', '_name', '_samples', '_type', '_wrappedClass', 'collect', 'describe', 'labels', 'remove']

counter.inc(diff)
| AttributeError: '_LabelWrapper' object has no attribute 'inc'



I was expecting counter to have the inc method.



Brian Brazil

unread,
Jun 15, 2017, 12:07:44 PM6/15/17
to Marc Pawlowsky, Prometheus Users

You need to specify labels, otherwise we don't know what to increment.

Brian
 

I was expecting counter to have the inc method.



--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/e0a13efa-dee0-4b66-ab65-cf703cf853ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Marc Pawlowsky

unread,
Jun 15, 2017, 12:26:22 PM6/15/17
to Prometheus Users, marc...@gmail.com
Go it, it is further down on the page, and just not quite what I expected. Feeling silly about how long I spent on it.

The constructor is used to define the labels that are valid, then when you access the counter you specify the labels values

counter= Counter(metric, metric, ['client'])
counter.labels(client=data['client']).inc(diff)

Thanks



On Thursday, June 15, 2017 at 12:07:44 PM UTC-4, Brian Brazil wrote:
On 15 June 2017 at 17:05, Marc Pawlowsky <marc...@gmail.com> wrote:
Can anybody tell me how to send a metric with labels using the python_client

I have:
counter= Counter(metric, metric,
labelnames=['client'], labelvalues=[ data['client'] ])
print counter
print dir(counter)
counter.inc(diff)

<prometheus_client.core._LabelWrapper object at 0xcf8ed0>
['class', 'delattr', 'dict', 'doc', 'format', 'getattribute', 'hash', 'init', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_kwargs', '_labelnames', '_lock', '_metrics', '_name', '_samples', '_type', '_wrappedClass', 'collect', 'describe', 'labels', 'remove']

counter.inc(diff)
| AttributeError: '_LabelWrapper' object has no attribute 'inc'




You need to specify labels, otherwise we don't know what to increment.

Brian
 

I was expecting counter to have the inc method.



--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To post to this group, send email to promethe...@googlegroups.com.



--
Reply all
Reply to author
Forward
0 new messages