final...
This commit is contained in:
@@ -3,6 +3,7 @@ interval: 10
|
|||||||
port: 8000
|
port: 8000
|
||||||
username: gloabl-user
|
username: gloabl-user
|
||||||
password: global-password
|
password: global-password
|
||||||
|
systemid: ["1"] # Strings, not integers!
|
||||||
hosts:
|
hosts:
|
||||||
- fqdn: host1.example.com
|
- fqdn: host1.example.com
|
||||||
username: user1
|
username: user1
|
||||||
@@ -11,4 +12,5 @@ hosts:
|
|||||||
username: user2
|
username: user2
|
||||||
password: secret2
|
password: secret2
|
||||||
- fqdn: host3.example.com
|
- fqdn: host3.example.com
|
||||||
|
systemid: ["0"] # Strings, not integers!
|
||||||
- fqdn: host4.example.com
|
- fqdn: host4.example.com
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class HostConfig:
|
|||||||
fqdn: str
|
fqdn: str
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
systemid: list[str] | None = None
|
||||||
max_retries: int = 1
|
max_retries: int = 1
|
||||||
backoff: int = 2
|
backoff: int = 2
|
||||||
cool_down: int = 120 # seconds to wait after too many failures
|
cool_down: int = 120 # seconds to wait after too many failures
|
||||||
@@ -234,8 +235,6 @@ async def get_power_data(session, host: HostConfig):
|
|||||||
host.mark_failure()
|
host.mark_failure()
|
||||||
up_gauge.labels(host=host.fqdn).set(0)
|
up_gauge.labels(host=host.fqdn).set(0)
|
||||||
return
|
return
|
||||||
pretty = json.dumps(chassis_data, indent=4, sort_keys=True)
|
|
||||||
print(pretty)
|
|
||||||
|
|
||||||
# 3. Power-Daten aus den Chassis-Mitgliedern extrahieren
|
# 3. Power-Daten aus den Chassis-Mitgliedern extrahieren
|
||||||
for chassis_member in chassis_data.get("Members", []):
|
for chassis_member in chassis_data.get("Members", []):
|
||||||
@@ -243,6 +242,13 @@ async def get_power_data(session, host: HostConfig):
|
|||||||
if not chassis_member_url:
|
if not chassis_member_url:
|
||||||
continue
|
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_url = f"https://{host.fqdn}{chassis_member_url}"
|
||||||
member_data = await fetch_with_retry(session, host, member_url)
|
member_data = await fetch_with_retry(session, host, member_url)
|
||||||
if not member_data:
|
if not member_data:
|
||||||
@@ -302,23 +308,19 @@ async def get_power_data(session, host: HostConfig):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Get Metrics from data
|
# Get Metrics from data
|
||||||
line_input_v = metrics_data.get("LineInputVoltage")
|
line_input_v = metrics_data.get("InputVoltage", {}).get("Reading")
|
||||||
watts_input = metrics_data.get("PowerInputWatts")
|
watts_input = metrics_data.get("InputPowerWatts", {}).get("Reading")
|
||||||
|
amps_input = metrics_data.get("InputCurrentAmps", {}).get("Reading")
|
||||||
serial = psu_data.get("SerialNumber")
|
serial = psu_data.get("SerialNumber")
|
||||||
# Calculate Amps
|
# 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:
|
if line_input_v is not None:
|
||||||
voltage_gauge.labels(host=host.fqdn, psu_serial=serial).set(
|
voltage_gauge.labels(host=host.fqdn, psu_serial=serial).set(
|
||||||
line_input_v
|
line_input_v
|
||||||
)
|
)
|
||||||
if watts_input is not None:
|
if watts_input is not None:
|
||||||
watts_gauge.labels(host=host.fqdn, psu_serial=serial).set(watts_input)
|
watts_gauge.labels(host=host.fqdn, psu_serial=serial).set(watts_input)
|
||||||
if amps is not None:
|
if amps_input is not None:
|
||||||
amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps)
|
amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps_input)
|
||||||
|
|
||||||
REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start)
|
REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start)
|
||||||
|
|
||||||
@@ -354,6 +356,7 @@ async def run_exporter(config, stop_event):
|
|||||||
port = config.get("port", 8000)
|
port = config.get("port", 8000)
|
||||||
default_username = config.get("username")
|
default_username = config.get("username")
|
||||||
default_password = config.get("password")
|
default_password = config.get("password")
|
||||||
|
default_systemid = config.get("systemid")
|
||||||
hosts = config["hosts"]
|
hosts = config["hosts"]
|
||||||
interval = config.get("interval", 10)
|
interval = config.get("interval", 10)
|
||||||
|
|
||||||
@@ -369,6 +372,7 @@ async def run_exporter(config, stop_event):
|
|||||||
fqdn=host_entry["fqdn"],
|
fqdn=host_entry["fqdn"],
|
||||||
username=host_entry.get("username", default_username),
|
username=host_entry.get("username", default_username),
|
||||||
password=host_entry.get("password", default_password),
|
password=host_entry.get("password", default_password),
|
||||||
|
systemid=host_entry.get("systemid", default_systemid),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
hc = HostConfig(
|
hc = HostConfig(
|
||||||
|
|||||||
Reference in New Issue
Block a user