-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·59 lines (51 loc) · 2.14 KB
/
main.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
#!/users/zfbharwa/.pyenv/shims/python3
from DataProcessor import *
from HTMLGenerator import *
from constants import machines, port, refreshRate
from getpass import getpass
import threading
import paramiko
import time
import sys
class Manager:
def __init__(self, username, password):
self.username = username
self.password = password
self.threads = [ ]
self.dataProcessor = DataProcessor()
"""
ssh into target machine and fetch data
"""
def getMachineActivity(self, i):
machine = machines[i]
command = f"top -b -n 1 > top_{i}.txt && cat top_{i}.txt"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(machine, port, self.username, self.password)
stdin, stdout, stderr = ssh.exec_command(command)
machineActivity = stdout.readlines()
ssh.close()
self.dataProcessor.process(machine, machineActivity[0:5])
except Exception as e:
print(f'Failed to ssh into {machine} with error:\n{e}')
sys.exit()
"""
Starting point to get the program running
"""
def run(self):
while True:
for i in range(len(machines)):
thread = threading.Thread(target = self.getMachineActivity, args=(i,))
self.threads.append(thread)
thread.start()
for thread in self.threads:
thread.join()
self.dataProcessor.updateCharts()
time.sleep(refreshRate)
self.threads.clear()
if __name__ == "__main__":
username = input("Enter your quest user ID:\n")
password = getpass("Enter the corresponding password:\n")
manager = Manager(username,password)
manager.run()