diff --git a/.vscode/launch.json b/.vscode/launch.json index b77d253..3049ac8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,7 @@ "METRIC__INTERVAL": "5", "METRIC__LOG__ENABLED": "True", "METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]", + "METRIC__EXTERNAL__EXECUTABLES": "[\"${workspaceFolder}/dummy-metric\"]", }, "justMyCode": true } diff --git a/dummy-metric b/dummy-metric new file mode 100755 index 0000000..3e761d3 --- /dev/null +++ b/dummy-metric @@ -0,0 +1,6 @@ +#!/bin/sh + +echo "Dummy" +echo "95" +echo "normal" +awk "BEGIN{srand(); r=rand(); print r * 100}" diff --git a/kiwi_simple_metrics/main.py b/kiwi_simple_metrics/main.py index 5bedeff..5f6445f 100644 --- a/kiwi_simple_metrics/main.py +++ b/kiwi_simple_metrics/main.py @@ -15,6 +15,7 @@ def handle_report() -> None: metrics.cpu(), metrics.memory(), metrics.disk(), + metrics.external(), ) # maybe print this to stdout diff --git a/kiwi_simple_metrics/metrics/__init__.py b/kiwi_simple_metrics/metrics/__init__.py index 5eac512..cf1a0c0 100644 --- a/kiwi_simple_metrics/metrics/__init__.py +++ b/kiwi_simple_metrics/metrics/__init__.py @@ -1,6 +1,7 @@ from ._report import Report from .cpu import cpu from .disk import disk +from .external import external from .memory import memory __all__ = [ @@ -8,5 +9,6 @@ __all__ = [ "cpu", "disk", + "external", "memory", ] diff --git a/kiwi_simple_metrics/metrics/external.py b/kiwi_simple_metrics/metrics/external.py new file mode 100644 index 0000000..681a6df --- /dev/null +++ b/kiwi_simple_metrics/metrics/external.py @@ -0,0 +1,18 @@ +from typing import Iterator + +from ..settings import SETTINGS +from ._report import Report, ReportData + + +def _hwdata() -> Iterator[ReportData]: + yield ReportData( + name="Foo", + value=69.42, + ) + + +def external() -> Report | None: + return Report.aggregate( + settings=SETTINGS.external, + get_data=_hwdata, + ) diff --git a/kiwi_simple_metrics/settings/__init__.py b/kiwi_simple_metrics/settings/__init__.py index 4a2a6a0..a2fbf0a 100644 --- a/kiwi_simple_metrics/settings/__init__.py +++ b/kiwi_simple_metrics/settings/__init__.py @@ -23,6 +23,7 @@ class Settings(BaseSettings): cpu: metric.CpuMS = metric.CpuMS() memory: metric.MemoryMS = metric.MemoryMS() disk: metric.DiskMS = metric.DiskMS() + external: metric.ExternalMS = metric.ExternalMS() # pinging webhooks webhook: misc.WebhookSettings = misc.WebhookSettings()