Compare commits

..

2 Commits

Author SHA1 Message Date
2f249beb8a final... 2026-01-29 15:12:43 +01:00
8ee84eb550 WIP need to fix systemid 2026-01-29 14:31:31 +01:00
2 changed files with 18 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ interval: 10
port: 8000
username: gloabl-user
password: global-password
systemid: ["1"] # Strings, not integers!
hosts:
- fqdn: host1.example.com
username: user1
@@ -11,4 +12,5 @@ hosts:
username: user2
password: secret2
- fqdn: host3.example.com
systemid: ["0"] # Strings, not integers!
- fqdn: host4.example.com

View File

@@ -20,6 +20,7 @@ class HostConfig:
fqdn: str
username: str
password: str
systemid: list[str] | None = None
max_retries: int = 1
backoff: int = 2
cool_down: int = 120 # seconds to wait after too many failures
@@ -241,12 +242,19 @@ async def get_power_data(session, host: HostConfig):
if not chassis_member_url:
continue
# Get Chassis ID from url ("/redfish/v1/Chassis/1" -> 1)
chassis_id = chassis_member_url.split("/")[-1]
# Check if the chassis id is in config (had problem with chassis "NVMe")
if hasattr(host, 'systemid') and host.systemid:
if chassis_id not in host.systemid:
continue
member_url = f"https://{host.fqdn}{chassis_member_url}"
member_data = await fetch_with_retry(session, host, member_url)
if not member_data:
continue
# PowerSubsystem extrahieren
# PowerSubsystem url
power_subsystem_url = member_data.get("PowerSubsystem", {}).get("@odata.id")
if not power_subsystem_url:
logging.warning("No PowerSubsystem found for %s", host.fqdn)
@@ -265,7 +273,6 @@ async def get_power_data(session, host: HostConfig):
power_supplies_url = power_subsystem_data.get("PowerSupplies", {}).get(
"@odata.id"
)
if not power_supplies_url:
logging.warning("No PowerSupplies found for %s", host.fqdn)
continue
@@ -299,28 +306,21 @@ async def get_power_data(session, host: HostConfig):
metrics_data = await fetch_with_retry(session, host, metrics_url)
if not metrics_data:
continue
pretty = json.dumps(metrics_data, indent=4, sort_keys=True)
print(pretty)
exit(100)
# Get Metrics from data
line_input_v = metrics_data.get("LineInputVoltage")
watts_input = metrics_data.get("PowerInputWatts")
line_input_v = metrics_data.get("InputVoltage", {}).get("Reading")
watts_input = metrics_data.get("InputPowerWatts", {}).get("Reading")
amps_input = metrics_data.get("InputCurrentAmps", {}).get("Reading")
serial = psu_data.get("SerialNumber")
# Calculate Amps
amps = (
round(watts_input / line_input_v, 2)
if line_input_v and watts_input
else None
)
if line_input_v is not None:
voltage_gauge.labels(host=host.fqdn, psu_serial=serial).set(
line_input_v
)
if watts_input is not None:
watts_gauge.labels(host=host.fqdn, psu_serial=serial).set(watts_input)
if amps is not None:
amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps)
if amps_input is not None:
amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps_input)
REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start)
@@ -356,6 +356,7 @@ async def run_exporter(config, stop_event):
port = config.get("port", 8000)
default_username = config.get("username")
default_password = config.get("password")
default_systemid = config.get("systemid")
hosts = config["hosts"]
interval = config.get("interval", 10)
@@ -371,6 +372,7 @@ async def run_exporter(config, stop_event):
fqdn=host_entry["fqdn"],
username=host_entry.get("username", default_username),
password=host_entry.get("password", default_password),
systemid=host_entry.get("systemid", default_systemid),
)
else:
hc = HostConfig(