mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-24 16:33:01 +00:00
44 lines
914 B
Python
44 lines
914 B
Python
#!/usr/bin/python3
|
|
|
|
import asyncio
|
|
|
|
from . import metrics
|
|
from .settings import SETTINGS
|
|
|
|
|
|
def run_metrics(*_metrics: metrics.Metric) -> None:
|
|
reports = (metric() for metric in _metrics)
|
|
|
|
# create single report from metrics
|
|
report = metrics.Report.summary(*reports)
|
|
|
|
# maybe print this to stdout
|
|
if SETTINGS.log.enabled:
|
|
print(report)
|
|
|
|
# maybe push this to the configured webhook
|
|
report.push_webhook()
|
|
|
|
|
|
async def async_main() -> None:
|
|
loop = asyncio.get_running_loop()
|
|
|
|
while True:
|
|
await asyncio.gather(
|
|
asyncio.sleep(SETTINGS.interval),
|
|
loop.run_in_executor(
|
|
None, run_metrics,
|
|
metrics.cpu,
|
|
metrics.memory,
|
|
metrics.disk,
|
|
metrics.external,
|
|
),
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
asyncio.run(async_main())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|