mirror of
https://github.com/yavook/kiwi-simple-metrics.git
synced 2024-11-24 08:23:01 +00:00
preliminary metrics "CPU" and "DISK"
This commit is contained in:
parent
a8627bad84
commit
3bc453a56c
2 changed files with 29 additions and 2 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -11,7 +11,7 @@
|
|||
"module": "kiwi_simple_metrics.main",
|
||||
"env": {
|
||||
"METRIC_DISK__THRESHOLD": "85", // workaround!
|
||||
"METRIC_DISK__PARAMS": "[\"/var\", \"/\"]",
|
||||
"METRIC_DISK__PARAMS": "[\"/var\", \"/\", \"/dev\"]",
|
||||
},
|
||||
"justMyCode": true
|
||||
}
|
||||
|
|
|
@ -1,12 +1,39 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import psutil
|
||||
|
||||
from .settings import SETTINGS
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print(psutil.cpu_percent(interval=1))
|
||||
# env parameters
|
||||
print(SETTINGS.model_dump())
|
||||
|
||||
# CPU metric
|
||||
print(psutil.cpu_percent(interval=1))
|
||||
|
||||
# MEM metric
|
||||
|
||||
# DISK metric
|
||||
# TODO test this using timeit
|
||||
for path in SETTINGS.disk.params:
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue