fabaccess-prometheus-exporter/main.py

53 lines
1.6 KiB
Python
Raw Normal View History

2022-06-01 01:05:19 +02:00
import os
from prometheus_client import Gauge
from prometheus_async import aio
import asyncio
import pyfabapi.fabapi
def convert2int(enum):
2023-02-07 20:25:54 +01:00
if enum == "free":
2022-06-01 01:05:19 +02:00
return 0.0
2023-02-07 20:25:54 +01:00
if enum == "inUse":
2022-06-01 01:05:19 +02:00
return 1.0
2023-02-07 20:25:54 +01:00
if enum == "toCheck":
2022-06-01 01:05:19 +02:00
return 2.0
2023-02-07 20:25:54 +01:00
if enum == "blocked":
2022-06-01 01:05:19 +02:00
return 3.0
2023-02-07 20:25:54 +01:00
if enum == "disabled":
2022-06-01 01:05:19 +02:00
return 4.0
2023-02-07 20:25:54 +01:00
if enum == "reserved":
2022-06-01 01:05:19 +02:00
return 5.0
2023-02-07 20:25:54 +01:00
if enum == "totakeover":
2022-06-01 01:05:19 +02:00
return 6.0
2023-02-07 20:25:54 +01:00
2022-06-01 01:05:19 +02:00
async def main():
polling_interval_seconds = int(os.getenv("POLLING_INTERVAL_SECONDS", "5"))
2023-02-07 05:34:26 +01:00
exporter_port = int(os.getenv("EXPORTER_PORT", "9000"))
2023-02-07 20:25:54 +01:00
2022-06-01 01:05:19 +02:00
bffh_host = str(os.getenv("BFFH_HOST", "localhost"))
2023-02-07 05:34:26 +01:00
bffh_port = int(os.getenv("BFFH_PORT", "59661"))
2022-06-01 01:05:19 +02:00
bffh_user = str(os.getenv("BFFH_USER", "Admin1"))
bffh_password = str(os.getenv("BFFH_PASSWORD", "secret"))
2023-02-07 20:25:54 +01:00
2023-02-07 04:38:42 +01:00
await aio.web.start_http_server(addr="0.0.0.0", port=exporter_port)
2023-02-07 20:25:54 +01:00
2022-06-01 01:05:19 +02:00
metriclist = {}
session = await pyfabapi.fabapi.connect(bffh_host, bffh_port, bffh_user, bffh_password)
2023-02-07 20:25:54 +01:00
machine_state = Gauge("bffh_machine_state", "Machine State", ["machine_id", "machine_name", "category"])
2022-06-01 01:05:19 +02:00
while True:
2023-02-07 20:25:54 +01:00
machine_list = await session.machineSystem.info.getMachineList().a_wait()
machine_list = machine_list.machine_list
for machine in machine_list:
machine_state.labels(machine.id, machine.name, machine.category).set(convert2int(machine.state))
2022-06-01 01:05:19 +02:00
await asyncio.sleep(polling_interval_seconds)
2023-02-07 20:25:54 +01:00
2022-06-01 01:05:19 +02:00
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(main())