2023-08-31 22:10:40 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2023-08-31 22:55:31 +00:00
|
|
|
import asyncio
|
2023-08-31 23:49:02 +00:00
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
import requests
|
2023-08-31 22:55:31 +00:00
|
|
|
|
2023-08-31 11:17:19 +00:00
|
|
|
from . import metrics
|
2023-08-31 22:55:31 +00:00
|
|
|
from .settings import SETTINGS
|
|
|
|
|
|
|
|
|
|
|
|
async def run_metrics() -> None:
|
|
|
|
while True:
|
|
|
|
interval = asyncio.sleep(SETTINGS.interval)
|
|
|
|
|
2023-08-31 23:49:02 +00:00
|
|
|
# create single report from metrics
|
|
|
|
report = metrics.Report.summary(
|
2023-08-31 22:55:31 +00:00
|
|
|
metrics.cpu(),
|
|
|
|
metrics.memory(),
|
|
|
|
metrics.disk(),
|
2023-08-31 23:09:50 +00:00
|
|
|
)
|
|
|
|
|
2023-08-31 23:49:02 +00:00
|
|
|
# maybe print this to stdout
|
2023-08-31 23:29:27 +00:00
|
|
|
if SETTINGS.log.enabled:
|
2023-08-31 23:09:50 +00:00
|
|
|
print(report)
|
2023-08-31 22:55:31 +00:00
|
|
|
|
2023-08-31 23:49:02 +00:00
|
|
|
# maybe push this to a webhook
|
|
|
|
if (url := SETTINGS.webhook.get_url(failed=report.failed)) is not None:
|
|
|
|
requests.get(
|
|
|
|
url=str(url).format(
|
|
|
|
urllib.parse.quote_plus(report.result)
|
|
|
|
),
|
|
|
|
verify=not SETTINGS.webhook.insecure,
|
|
|
|
)
|
|
|
|
|
2023-08-31 22:55:31 +00:00
|
|
|
await interval
|
2023-08-30 22:01:31 +00:00
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
def main() -> None:
|
2023-08-31 22:55:31 +00:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.create_task(run_metrics())
|
|
|
|
loop.run_forever()
|
2023-08-30 23:49:07 +00:00
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|