-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup synthetic metrics and test alerts on COS
- Loading branch information
Showing
4 changed files
with
199 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
# This file is supposed to run on the hardware observer unit. | ||
|
||
import time | ||
|
||
from mock_data import SAMPLE_METRICS | ||
from prometheus_client import REGISTRY, start_http_server | ||
from prometheus_client.core import GaugeMetricFamily | ||
|
||
PORT = 10200 # Default exporter port | ||
|
||
|
||
class SyntheticCollector: | ||
"""Collector for creating synthetic(mock) metrics.""" | ||
|
||
def collect(self): | ||
for sample_metric in SAMPLE_METRICS: | ||
metric = GaugeMetricFamily( | ||
name=sample_metric["name"], | ||
documentation=sample_metric["documentation"], | ||
labels=list(sample_metric["labels"].keys()), | ||
) | ||
metric.add_metric( # type: ignore[attr-defined] | ||
labels=list(sample_metric["labels"].values()), value=sample_metric["value"] | ||
) | ||
yield metric | ||
|
||
|
||
if __name__ == "__main__": | ||
start_http_server(PORT) | ||
REGISTRY.register(SyntheticCollector()) | ||
|
||
while True: | ||
time.sleep(10) # Keep the server running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Metrics | ||
SAMPLE_METRICS = [ | ||
{ | ||
"name": "ipmi_dcmi_command_success", | ||
"documentation": "Indicates if the ipmi dcmi command is successful or not", | ||
"labels": {}, | ||
"value": 0.0, | ||
}, | ||
{ | ||
"name": "redfish_call_success", | ||
"documentation": "Indicates if call to the redfish API succeeded or not", | ||
"labels": {}, | ||
"value": 1.0, | ||
}, | ||
{ | ||
"name": "ipmi_temperature_celsius", | ||
"documentation": "Temperature measure from temperature sensors", | ||
"labels": {"name": "testname", "state": "Critical", "unit": "C"}, | ||
"value": 200, | ||
}, | ||
] | ||
|
||
|
||
# Expected alerts based on above metrics | ||
SAMPLE_ALERTS = [ | ||
{ | ||
"labels": { | ||
"alertname": "IPMIDCMICommandFailed", | ||
"juju_application": "hardware-observer", | ||
"juju_unit": "hardware-observer/0", | ||
"severity": "critical", | ||
}, | ||
"state": "firing", | ||
"value": 0.0, | ||
}, | ||
{ | ||
"labels": { | ||
"alertname": "IPMITemperatureStateNotOk", | ||
"juju_application": "hardware-observer", | ||
"juju_unit": "hardware-observer/0", | ||
"severity": "critical", | ||
}, | ||
"state": "firing", | ||
"value": 200, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
jinja2 | ||
juju~=3.3.0 # must be compatible with the juju CLI version installed by CI | ||
pytest | ||
pytest-operator | ||
pytest-operator | ||
prometheus-client | ||
pyinstaller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters