Skip to content

Commit 4b1fc1f

Browse files
committed
Ensure metric names start with smartmon
1 parent 783a68c commit 4b1fc1f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

etc/kayobe/ansible/scripts/smartmon.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,18 @@ def parse_device_info(device):
118118
metric_labels = f'disk="{device.name}",serial_number="{serial_number}",type="{device.interface}"'
119119

120120
metrics = [
121-
f'device_info{{{label_str}}} 1.0',
122-
f'device_smart_available{{{metric_labels}}} {float(1) if device.smart_capable else float(0)}',
121+
f'smartmon_device_info{{{label_str}}} 1.0',
122+
f'smartmon_device_smart_available{{{metric_labels}}} {float(1) if device.smart_capable else float(0)}',
123123
]
124124

125125
if device.smart_capable:
126126
metrics.append(
127-
f'device_smart_enabled{{{metric_labels}}} {float(1) if device.smart_enabled else float(0)}'
127+
f'smartmon_device_smart_enabled{{{metric_labels}}} {float(1) if device.smart_enabled else float(0)}'
128128
)
129129
if device.assessment:
130130
is_healthy = 1 if device.assessment.upper() == "PASS" else 0
131131
metrics.append(
132-
f'device_smart_healthy{{{metric_labels}}} {float(is_healthy)}'
132+
f'smartmon_device_smart_healthy{{{metric_labels}}} {float(is_healthy)}'
133133
)
134134

135135
return metrics
@@ -166,7 +166,7 @@ def parse_if_attributes(device):
166166
snake_name = camel_to_snake(attr_name)
167167

168168
if snake_name in SMARTMON_ATTRS and isinstance(val, (int, float)):
169-
metrics.append(f"{snake_name}{{{labels}}} {float(val)}")
169+
metrics.append(f"smartmon_{snake_name}{{{labels}}} {float(val)}")
170170

171171
return metrics
172172

@@ -219,7 +219,7 @@ def main(output_path=None):
219219
version_num = "unknown"
220220
except Exception:
221221
version_num = "unknown"
222-
all_metrics.append(f'smartctl_version{{version="{version_num}"}} 1')
222+
all_metrics.append(f'smartmon_smartctl_version{{version="{version_num}"}} 1')
223223

224224
dev_list = DeviceList()
225225

@@ -229,7 +229,7 @@ def main(output_path=None):
229229
serial_number = (dev.serial or "").lower()
230230

231231
run_timestamp = int(datetime.datetime.now(datetime.timezone.utc).timestamp())
232-
all_metrics.append(f'smartctl_run{{disk="{disk_name}",type="{disk_type}"}} {run_timestamp}')
232+
all_metrics.append(f'smartmon_smartctl_run{{disk="{disk_name}",type="{disk_type}"}} {run_timestamp}')
233233

234234
active = 1
235235
try:
@@ -243,7 +243,7 @@ def main(output_path=None):
243243
active = 0
244244

245245
all_metrics.append(
246-
f'device_active{{disk="{disk_name}",type="{disk_type}",serial_number="{serial_number}"}} {active}'
246+
f'smartmon_device_active{{disk="{disk_name}",type="{disk_type}",serial_number="{serial_number}"}} {active}'
247247
)
248248
if active == 0:
249249
continue

etc/kayobe/ansible/scripts/test_smartmon.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,42 +78,42 @@ def _test_parse_device_info(self, fixture_name):
7878

7979
# The device_info line should exist for every device
8080
device_info_found = any(
81-
line.startswith("device_info{") and
81+
line.startswith("smartmon_device_info{") and
8282
f'disk="{dev_name}"' in line and
8383
f'type="{dev_iface}"' in line and
8484
f'serial_number="{dev_serial}"' in line
8585
for line in metrics
8686
)
8787
self.assertTrue(
8888
device_info_found,
89-
f"Expected a device_info metric line for {dev_name} but didn't find it."
89+
f"Expected a smartmon_device_info metric line for {dev_name} but didn't find it."
9090
)
9191

9292
# If smart_capable is true, we expect device_smart_available = 1
9393
if device_info.get("smart_capable"):
9494
smart_available_found = any(
95-
line.startswith("device_smart_available{") and
95+
line.startswith("smartmon_device_smart_available{") and
9696
f'disk="{dev_name}"' in line and
9797
f'serial_number="{dev_serial}"' in line and
9898
line.endswith(" 1.0")
9999
for line in metrics
100100
)
101101
self.assertTrue(
102102
smart_available_found,
103-
f"Expected device_smart_available=1.0 for {dev_name}, not found."
103+
f"Expected smartmon_device_smart_available=1.0 for {dev_name}, not found."
104104
)
105105

106106
# If smart_enabled is true, we expect device_smart_enabled = 1
107107
if device_info.get("smart_enabled"):
108108
smart_enabled_found = any(
109-
line.startswith("device_smart_enabled{") and
109+
line.startswith("smartmon_device_smart_enabled{") and
110110
f'disk="{dev_name}"' in line and
111111
line.endswith(" 1.0")
112112
for line in metrics
113113
)
114114
self.assertTrue(
115115
smart_enabled_found,
116-
f"Expected device_smart_enabled=1.0 for {dev_name}, not found."
116+
f"Expected smartmon_device_smart_enabled=1.0 for {dev_name}, not found."
117117
)
118118

119119
# device_smart_healthy if assessment in [PASS, WARN, FAIL]
@@ -122,14 +122,14 @@ def _test_parse_device_info(self, fixture_name):
122122
if assessment in ["PASS", "WARN", "FAIL"]:
123123
expected_val = float(1) if assessment == "PASS" else float(0)
124124
smart_healthy_found = any(
125-
line.startswith("device_smart_healthy{") and
125+
line.startswith("smartmon_device_smart_healthy{") and
126126
f'disk="{dev_name}"' in line and
127127
line.endswith(f" {expected_val}")
128128
for line in metrics
129129
)
130130
self.assertTrue(
131131
smart_healthy_found,
132-
f"Expected device_smart_healthy={expected_val} for {dev_name}, not found."
132+
f"Expected smartmon_device_smart_healthy={expected_val} for {dev_name}, not found."
133133
)
134134

135135
def test_parse_device_info(self):
@@ -164,7 +164,7 @@ def _test_parse_if_attributes(self, fixture_name):
164164

165165
if isinstance(attr_val, (int, float)) and snake_key in SMARTMON_ATTRS:
166166
expected_line = (
167-
f"{snake_key}{{disk=\"{dev_name}\",serial_number=\"{dev_serial}\",type=\"{dev_iface}\"}} {float(attr_val)}"
167+
f"smartmon_{snake_key}{{disk=\"{dev_name}\",serial_number=\"{dev_serial}\",type=\"{dev_iface}\"}} {float(attr_val)}"
168168
)
169169
self.assertIn(
170170
expected_line,
@@ -175,7 +175,7 @@ def _test_parse_if_attributes(self, fixture_name):
175175
# If it's not in SMARTMON_ATTRS or not numeric,
176176
# we do NOT expect a line with that name+value
177177
unexpected_line = (
178-
f"{snake_key}{{disk=\"{dev_name}\",serial_number=\"{dev_serial}\",type=\"{dev_iface}\"}} {float(attr_val)}"
178+
f"smartmon_{snake_key}{{disk=\"{dev_name}\",serial_number=\"{dev_serial}\",type=\"{dev_iface}\"}} {float(attr_val)}"
179179
)
180180
self.assertNotIn(
181181
unexpected_line,
@@ -268,8 +268,8 @@ def run_command_side_effect(cmd, parse_json=False):
268268
self.assertTrue(found, f"Expected metric '{expected}' not found")
269269

270270
# Check that smartctl_version metric is present
271-
version_found = any(line.startswith("smartctl_version{") for line in metrics_lines)
272-
self.assertTrue(version_found, "Expected 'smartctl_version' metric not found in output file.")
271+
version_found = any(line.startswith("smartmon_smartctl_version{") for line in metrics_lines)
272+
self.assertTrue(version_found, "Expected 'smartmon_smartctl_version' metric not found in output file.")
273273

274274
# Check that the output file is not empty
275275
self.assertTrue(metrics_lines, "Metrics output file is empty.")

0 commit comments

Comments
 (0)