How to set multiple label values with using tuple or list to gauge object?

3,300 views
Skip to first unread message

stanisla...@tikalk.com

unread,
Sep 13, 2017, 6:10:43 AM9/13/17
to Prometheus Developers
Hi Prometheus Developers,

I met with following issue in during writing custom exporter:

example:

from prometheus_client import Gauge

g = Gauge('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])

g.labels('get', '/').set(100) - that works

but if i have big amount of labels and i am trying to pass as list(or tuple):

labels_names = ['customerid', 'tenantname', 'operation', 'product', 'feature', 'context', 'hostname', 'message', 'region', 'podname']

labels_values = [u'Admin Tenant', u'RE-P01-IN01-C', u'us-west-1', u'Web Services', u'Admin Tenant', u'SXPServerHealthCheck', u'SO Server', u'mon...@cscloud.com', u'PR01', u'SXPServerHealthCheck']

if len(labels_names) == len(labels_values):

g = Gauge('my_requests_total', 'HTTP Failures', labels_names)
g.labels(labels_values).set(100)

i got:

File "/Library/Python/2.7/site-packages/prometheus_client/core.py", line 516, in labels
raise ValueError('Incorrect label count')
ValueError: Incorrect label count

In debug i see that method is getting following tuple:

<type 'tuple'>: ([u'Admin Tenant', u'RE-P01-IN01-C', u'us-west-1', u'Web Services', u'Admin Tenant', u'SXPServerHealthCheck', u'SO Server', u'mon...@cscloud.com', u'PR01', u'SXPServerHealthCheck'],)

instead what i am expecting:

(u'Admin Tenant', u'RE-P01-IN01-C', u'us-west-1', u'Web Services', u'Admin Tenant', u'SXPServerHealthCheck', u'SO Server', u'mon...@cscloud.com', u'PR01', u'SXPServerHealthCheck')

Any way to set values by passing list or tuple or i need to pass only strings separated by comma?


Brian Brazil

unread,
Sep 13, 2017, 6:14:35 AM9/13/17
to stanisla...@tikalk.com, Prometheus Developers
You can do g.labels(*label_values) which will have Python pass the list as *args.

That is rather a lot of labels to have, you might be wanting a logging solution rather than a metrics system like Prometheus.

--

stanisla...@tikalk.com

unread,
Sep 16, 2017, 7:51:43 AM9/16/17
to Prometheus Developers

Thank you for answer that wasn't obvious from python client sdk.

Reply all
Reply to author
Forward
0 new messages