kiwi-simple-metrics/kiwi_simple_metrics/main.py

39 lines
785 B
Python
Raw Normal View History

2023-08-30 23:49:07 +00:00
import os
import shutil
2023-08-31 09:00:22 +00:00
from .metrics import cpu_metric
2023-08-30 22:01:31 +00:00
from .settings import SETTINGS
def main() -> None:
2023-08-30 23:49:07 +00:00
# env parameters
2023-08-30 22:01:31 +00:00
print(SETTINGS.model_dump())
2023-08-30 23:49:07 +00:00
# CPU metric
2023-08-31 09:00:22 +00:00
print(cpu_metric())
2023-08-30 23:49:07 +00:00
# MEM metric
# DISK metric
# TODO test this using timeit
2023-08-31 09:00:02 +00:00
for path in SETTINGS.disk.paths:
2023-08-30 23:49:07 +00:00
try:
sv = os.statvfs(path)
percent = sv.f_bavail / sv.f_blocks * 100
except ZeroDivisionError:
percent = 0
print(f"{path} Free (sv): {percent:.2f} %")
try:
total, _, free = shutil.disk_usage(path)
percent = free / total * 100
except ZeroDivisionError:
percent = 0
print(f"{path} Free (du): {percent:.2f} %")
if __name__ == "__main__":
main()