mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-25 00:43:01 +00:00
periodic task using asyncio
This commit is contained in:
parent
862e78eec0
commit
8f6a7a37fd
3 changed files with 23 additions and 5 deletions
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -10,6 +10,7 @@
|
|||
"request": "launch",
|
||||
"module": "kiwi_simple_metrics.main",
|
||||
"env": {
|
||||
"METRIC__INTERVAL": "5",
|
||||
"METRIC__DISK__PATHS": "[\"/var\", \"/\", \"/dev\"]",
|
||||
},
|
||||
"justMyCode": true
|
||||
|
|
|
@ -1,14 +1,28 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import asyncio
|
||||
|
||||
from . import metrics
|
||||
from .settings import SETTINGS
|
||||
|
||||
|
||||
async def run_metrics() -> None:
|
||||
while True:
|
||||
interval = asyncio.sleep(SETTINGS.interval)
|
||||
|
||||
print(metrics.Report.concat(
|
||||
metrics.cpu(),
|
||||
metrics.memory(),
|
||||
metrics.disk(),
|
||||
))
|
||||
|
||||
await interval
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print(metrics.Report.concat(
|
||||
metrics.cpu(),
|
||||
metrics.memory(),
|
||||
metrics.disk(),
|
||||
))
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(run_metrics())
|
||||
loop.run_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -88,6 +88,9 @@ class Settings(BaseSettings):
|
|||
env_nested_delimiter="__",
|
||||
)
|
||||
|
||||
# time between gathering reports
|
||||
interval: float = 600
|
||||
|
||||
# separates metrics and values in reports
|
||||
separator: str = ", "
|
||||
|
||||
|
|
Loading…
Reference in a new issue