2023-08-31 22:10:40 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2023-08-31 22:55:31 +00:00
|
|
|
import asyncio
|
|
|
|
|
2023-08-31 11:17:19 +00:00
|
|
|
from . import metrics
|
2023-08-31 22:55:31 +00:00
|
|
|
from .settings import SETTINGS
|
|
|
|
|
|
|
|
|
2023-09-02 01:56:20 +00:00
|
|
|
def run_metrics(*_metrics: metrics.Metric) -> None:
|
|
|
|
reports = (metric() for metric in _metrics)
|
|
|
|
|
2023-09-01 00:19:04 +00:00
|
|
|
# create single report from metrics
|
2023-09-02 01:56:20 +00:00
|
|
|
report = metrics.Report.summary(*reports)
|
2023-09-01 00:19:04 +00:00
|
|
|
|
|
|
|
# maybe print this to stdout
|
|
|
|
if SETTINGS.log.enabled:
|
|
|
|
print(report)
|
|
|
|
|
2023-09-01 22:56:20 +00:00
|
|
|
# maybe push this to the configured webhook
|
|
|
|
report.push_webhook()
|
2023-08-31 23:09:50 +00:00
|
|
|
|
2023-08-31 22:55:31 +00:00
|
|
|
|
2023-09-02 01:56:20 +00:00
|
|
|
async def async_main() -> None:
|
2023-09-01 00:19:04 +00:00
|
|
|
loop = asyncio.get_running_loop()
|
2023-08-31 23:49:02 +00:00
|
|
|
|
2023-09-01 00:19:04 +00:00
|
|
|
while True:
|
|
|
|
await asyncio.gather(
|
|
|
|
asyncio.sleep(SETTINGS.interval),
|
2023-09-02 01:56:20 +00:00
|
|
|
loop.run_in_executor(
|
|
|
|
None, run_metrics,
|
|
|
|
metrics.cpu,
|
|
|
|
metrics.memory,
|
|
|
|
metrics.disk,
|
|
|
|
metrics.external,
|
|
|
|
),
|
2023-09-01 00:19:04 +00:00
|
|
|
)
|
2023-08-30 22:01:31 +00:00
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
def main() -> None:
|
2023-09-02 01:56:20 +00:00
|
|
|
asyncio.run(async_main())
|
2023-08-30 23:49:07 +00:00
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|