2023-08-30 23:49:07 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
import psutil
|
|
|
|
|
2023-08-30 22:01:31 +00:00
|
|
|
from .settings import SETTINGS
|
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
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 21:08:16 +00:00
|
|
|
|
2023-08-30 23:49:07 +00:00
|
|
|
# CPU metric
|
|
|
|
print(psutil.cpu_percent(interval=1))
|
|
|
|
|
|
|
|
# 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} %")
|
|
|
|
|
2023-08-30 21:08:16 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|