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?
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/4278b8f1-3dd6-4928-98db-9b65e0344b6an%40googlegroups.com.
"""Read weight from Arlyn Scales in StephLab Annex (P8484) and report."""
import prometheus_client
import telnetlib
import socket
import time
g = prometheus_client.Gauge("arlyn_scales_reading", "Annex LN2 Weight (lbs)")
stat = prometheus_client.Enum("arlyn_scales_status", "Status of Annex LN2
Scale",
states=['connected', 'not connected'])
def read_gauge():
"""Read the gauge and return the value and status."""
try:
mke5 = telnetlib.Telnet("arlyn-mke-5.sqt.local", port=10001, timeout=5)
except socket.gaierror:
stat.state('not connected')
time.sleep(1)
return float('nan')
stat.state('connected')
time.sleep(1)
mke5.write(b"*P\n")
resp = mke5.read_until(b"lb")
mke5.close()
return float(resp.split()[0])
g.set_function(read_gauge)
if __name__ == '__main__':
# Start up the server to expose the metrics.
prometheus_client.start_http_server(8005)
# The callback function is called passively.
while True:
pass