switch to labels

This commit is contained in:
Kai Jan Kriegel 2023-02-07 20:25:54 +01:00
parent 010f4e0dbd
commit 3336126ceb

29
main.py
View File

@ -5,21 +5,22 @@ import asyncio
import pyfabapi.fabapi import pyfabapi.fabapi
def convert2int(enum): def convert2int(enum):
if(enum == "free"): if enum == "free":
return 0.0 return 0.0
if(enum == "inUse"): if enum == "inUse":
return 1.0 return 1.0
if(enum == "toCheck"): if enum == "toCheck":
return 2.0 return 2.0
if(enum == "blocked"): if enum == "blocked":
return 3.0 return 3.0
if(enum == "disabled"): if enum == "disabled":
return 4.0 return 4.0
if(enum == "reserved"): if enum == "reserved":
return 5.0 return 5.0
if(enum == "totakeover"): if enum == "totakeover":
return 6.0 return 6.0
async def main(): async def main():
polling_interval_seconds = int(os.getenv("POLLING_INTERVAL_SECONDS", "5")) polling_interval_seconds = int(os.getenv("POLLING_INTERVAL_SECONDS", "5"))
exporter_port = int(os.getenv("EXPORTER_PORT", "9000")) exporter_port = int(os.getenv("EXPORTER_PORT", "9000"))
@ -33,21 +34,19 @@ async def main():
metriclist = {} metriclist = {}
session = await pyfabapi.fabapi.connect(bffh_host, bffh_port, bffh_user, bffh_password) session = await pyfabapi.fabapi.connect(bffh_host, bffh_port, bffh_user, bffh_password)
machine_state = Gauge("bffh_machine_state", "Machine State", ["machine_id", "machine_name", "category"])
while True:
machine_list = await session.machineSystem.info.getMachineList().a_wait() machine_list = await session.machineSystem.info.getMachineList().a_wait()
machine_list = machine_list.machine_list machine_list = machine_list.machine_list
for machine in machine_list: for machine in machine_list:
metriclist[machine.id] = Gauge("bffh_machine_" + machine.id + "_state", "Machine State") machine_state.labels(machine.id, machine.name, machine.category).set(convert2int(machine.state))
while True:
machine_list_new = await session.machineSystem.info.getMachineList().a_wait()
machine_list_new = machine_list_new.machine_list
for machine in machine_list_new:
metriclist[machine.id].set(convert2int(machine.state))
await asyncio.sleep(polling_interval_seconds) await asyncio.sleep(polling_interval_seconds)
if __name__ == "__main__": if __name__ == "__main__":
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)