Python client status Enum reporting both states simultaneously?

487 views
Skip to first unread message

JF C

unread,
Feb 11, 2022, 6:39:09 PM2/11/22
to Prometheus Users

I have a measurement device that I can query over telnet with prometheus_client in python. I can report the value so Prometheus can see it, but when I try to report the status (connected/not connected) I somehow see both states at the same time?

The python script is attached, and what I see in the Prometheus web console: https://imgur.com/a/ZFo8GnT

Grafana also shows two solid lines for 0 and 1 for all times.

What am I doing wrong with the prometheus_client.Enum?

arlyn_scales.py.txt

Brian Candler

unread,
Feb 12, 2022, 4:49:36 AM2/12/22
to Prometheus Users
You are not seeing two states simultaneously.  You are seeing two timeseries: one has value 0 and one has value 1.

foo{state="connected"} 0
foo{state="not connected"} 1

If the system became "connected" then they would change to

foo{state="connected"} 1
foo{state="not connected"} 0

Given that prometheus only stores numeric metrics, this is the standard way of exposing an enumeration of states.

You could instead set the metric as a gauge value, in which case you'd have to choose a numeric value to represent each state, for example

foo 0   # means not connected
foo 1   # means connected

If you do it that way, then you get a single timeseries. The front-end application (e.g. grafana) can map those values to names and/or colours.  That also works.
Reply all
Reply to author
Forward
0 new messages