forked from kallimachos/cookbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.py
executable file
·40 lines (33 loc) · 1.14 KB
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Print system stats."""
import platform
import psutil
from psutil._common import bytes2human
def print_stats(stats):
"""Print system stats."""
print()
for key, value in stats.items():
print(f"{key}: {value}")
return
def system_stats():
"""Get stats."""
while True:
stats = {}
if platform.system() == "Darwin":
stats["IP"] = psutil.net_if_addrs()["en0"][0].address
stats["Battery"] = f"{psutil.sensors_battery().percent}%"
else:
stats["IP"] = psutil.net_if_addrs()["eth0"][0].address
stats["Temp"] = f"{psutil.sensors_temperatures()['cpu-thermal'][0].current} C"
stats["CPU"] = f"{psutil.cpu_percent(interval=1.0)}%"
mem = psutil.virtual_memory()
stats["Mem used"] = f"{bytes2human(mem.used)}/{bytes2human(mem.total)} - {mem.percent}%"
disk = psutil.disk_usage("/")
stats[
"Disk used"
] = f"{bytes2human(disk.used)}/{bytes2human(disk.total)} - {disk.percent}%"
print_stats(stats)
return
if __name__ == "__main__":
system_stats()