-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverseer.py
152 lines (112 loc) · 3.24 KB
/
Overseer.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
'''
Created on Oct 28, 2018
@author: Kyle Santiago
'''
#Start
import asyncio
import os
import sys
import psutil
import time
# CPU
def cpu_status():
value1 = psutil.cpu_count()
print('Number of CPUs:', value1)
value2 = psutil.cpu_percent(interval=2,percpu=True)
print('Percent in use:',value2)
def inefficient():
print(cpu_status())
def cpu_stat():
cpu_status()
inefficient()
if __name__ == '__cpu_stat__':
cpu_stat()
#Temp
'''
Having a difficult time accessing hardware temperature.
I'll come back to this later.
'''
# RAM
def v_mem():
mem = psutil.virtual_memory()
breakingPoint = (100 * 1024 * 1024) * 10 #1000mb
if mem.available <= breakingPoint:
print("WARNING: less than 1000mb of ram available")
def mem_Readability(n):
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
prefix[s] = 1 << (i + 1) * 10
for s in reversed(symbols):
if n >= prefix[s]:
value = float(n) / prefix[s]
return '%.1f%s' % (value, s)
return "%sB" % n
def pprint_ntuple(nt):
for name in nt._fields:
value = getattr(nt, name)
if name != 'percent':
value = mem_Readability(value)
print('%-10s : %7s' % (name.capitalize(), value))
def main_Memory():
print('MEMORY\n------')
pprint_ntuple(psutil.virtual_memory())
print('\nSWAP\n----')
pprint_ntuple(psutil.swap_memory())
if __name__ == '__main_Memory__':
main_Memory()
#HDD and SSD
def forHumans(n):
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
prefix[s] = 1 << (i + 1) * 10
for s in reversed(symbols):
if n >= prefix[s]:
value = float(n) / prefix[s]
return '%.1f%s' % (value, s)
return "%sB" % n
def main_Storage():
templ = "%-17s %8s %8s %8s %5s%% %9s %s"
print(templ % ("Device", "Total", "Used", "Free", "Use ", "Type",
"Mount"))
for part in psutil.disk_partitions(all=False):
if os.name == 'nt':
if 'cdrom' in part.opts or part.fstype == '':
continue
usage = psutil.disk_usage(part.mountpoint)
print(templ % (
part.device,
forHumans(usage.total),
forHumans(usage.used),
forHumans(usage.free),
int(usage.percent),
part.fstype,
part.mountpoint))
if __name__ == '__main_Storage__':
main_Storage()
#Hello There
def welcome():
print("Overseer: Online...")
print("Always Watching:")
#Exit
async def main_closing():
async def closing():
input('Press any key to terminate')
return input
task = asyncio.create_task(closing())
done, pending = await asyncio.wait({task})
if task in done:
print('Closing...')
await asyncio.sleep(1)
print('Closed')
sys.exit()
def main():
welcome()
cpu_stat()
main_Storage()
main_Memory()
asyncio.run(main_closing())
welcome()
sys.exit(app.exec_())
main()