mirror of
https://gitlab.com/fabinfra/fabaccess/prometheus-exporter.git
synced 2024-12-22 04:23:49 +01:00
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import os
|
|
from prometheus_client import Gauge
|
|
from prometheus_async import aio
|
|
import asyncio
|
|
import pyfabapi.fabapi
|
|
|
|
def convert2int(enum):
|
|
if(enum == "free"):
|
|
return 0.0
|
|
if(enum == "inUse"):
|
|
return 1.0
|
|
if(enum == "toCheck"):
|
|
return 2.0
|
|
if(enum == "blocked"):
|
|
return 3.0
|
|
if(enum == "disabled"):
|
|
return 4.0
|
|
if(enum == "reserved"):
|
|
return 5.0
|
|
if(enum == "totakeover"):
|
|
return 6.0
|
|
|
|
async def main():
|
|
polling_interval_seconds = int(os.getenv("POLLING_INTERVAL_SECONDS", "5"))
|
|
exporter_port = int(os.getenv("EXPORTER_PORT", "9000"))
|
|
|
|
bffh_host = str(os.getenv("BFFH_HOST", "localhost"))
|
|
bffh_port = int(os.getenv("BFFH_PORT", "59661"))
|
|
bffh_user = str(os.getenv("BFFH_USER", "Admin1"))
|
|
bffh_password = str(os.getenv("BFFH_PASSWORD", "secret"))
|
|
|
|
await aio.web.start_http_server(addr="0.0.0.0", port=exporter_port)
|
|
|
|
metriclist = {}
|
|
session = await pyfabapi.fabapi.connect(bffh_host, bffh_port, bffh_user, bffh_password)
|
|
machine_list = await session.machineSystem.info.getMachineList().a_wait()
|
|
machine_list = machine_list.machine_list
|
|
|
|
for machine in machine_list:
|
|
metriclist[machine.id] = Gauge("bffh_machine_" + machine.id + "_state", "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)
|
|
|
|
if __name__ == "__main__":
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
loop.run_until_complete(main()) |