I have a strange problem and was hoping to find a solution here. I am using push_to_gateway module to allow Prometheus to scape some data. There are 2 steps to the process:
1) declare a variable as like so:
g = Gauge(ctr, '', ['host', 'ip'], registry=registry)
host and ip are labels used in the Prometheus DB. registry isn't relevant to my problem.
2) Populate the data:
g.labels(hostname, ipaddr).set(val)
hostname and ipaddr are the variables containing values
When you look at the data in Prometheus, you'll see something like:
ctr{hostname="node1",ip="1.1.1.1"} -1
Since I have thousands of counters to import into Prometheus, and all of them have different sets of labels, I want to create an ordereddict containing the labels and their values while parsing the data and using that to generate 1) and 2). Filling part 1) is easy. I just type:
g = Gauge(ctr, '', list(labels.keys()), registry=registry)
The line is expecting a list, and it gets a list.
But how can I fill in part 2) since the g.labels is expecting the hostname and ipaddr seperated by a ',' (ie not a list). If I do list(labels.values()), then it shows up as a list inside the parenthesis and that doesn't work. I need the list(labels.values()) to expand to exactly 'node1','1.1.1.1' inside the parenthesis for this to work, and I have no clue how to do it (if at all possible) so that 2) looks like:
g.labels('node1', '1.1.1.1').set(val)
Thx