-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcstatus.py
executable file
·39 lines (31 loc) · 942 Bytes
/
pcstatus.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
#!/usr/bin/env python3
'''Functions to extract status of the machine using the `psutil` module.
'''
import psutil
import getpass
import json
def get_status():
'''Extract PC status using `psutil` module
'''
ret = {}
ret['cpu_percent'] = psutil.cpu_percent()
procs = {
proc.pid:{
'cpu_percent': proc.cpu_percent(),
'cmdline': proc.cmdline()
} for proc in psutil.process_iter()
if ('python' in proc.name())
and (proc.username() == getpass.getuser())
}
ret['pyprocs'] = procs
ret['disk_usage'] = {
part.mountpoint:psutil.disk_usage(part.mountpoint).percent
for part in psutil.disk_partitions() if 'rw' in part.opts
}
return ret
def main():
'''Print PC status in json format
'''
print(json.dumps(get_status()))
if __name__ == '__main__':
main()