forked from ljb-2000/Devops-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.py
71 lines (62 loc) · 1.72 KB
/
monitor.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
#!/usr/bin/env python
import socket,psutil,subprocess
def command_result(cmd):
output = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE)
ret = output.stdout.readlines()
return ret
def get_hostname():
return socket.gethostname()
def get_ipinfo():
dict = {}
data = psutil.net_if_addrs()
for key in data:
ip = psutil.net_if_addrs()[key][0][1]
if ip.startswith("1"):
dict[key]=ip
return dict
def get_Memtotal():
with open('/proc/meminfo') as mem_open:
a = int(mem_open.readline().split()[1])
return a / 1025
def get_Disktotal():
dict = {}
cmd = "fdisk -l"
line = command_result(cmd)
for i in line:
disk = i.strip('\n')
if "/dev" in disk and disk.startswith("Disk"):
data=disk.split()
dict[data[1]]=data[2]
return dict
def get_cpuinfo():
dict = {}
cpu_count = psutil.cpu_count()
cmd = "cat /proc/cpuinfo | grep name"
ret = command_result(cmd)
data = list(set(ret))
dict["cpu_logic_num"]=cpu_count
dict[data[0].split(":")[0]]=data[0].split(":")[1]
return dict
def get_hardware():
dict = {}
cmd = "dmidecode | grep -A6 'System Information'"
ret = command_result(cmd)
del ret[0]
for i in ret:
i = i.strip("\n,\t")
ret_list = i.split(":")
dict[ret_list[0]]=ret_list[1]
return dict
def get_release():
list = []
cmd = "dmidecode | grep -i release"
ret = command_result(cmd)
data = ret[0].split(":")[1]
rel = data.split("/")
for i in rel:
list.append(i.strip('\n,\t'))
a,b,c = list
r_list = [c,a,b]
return "/".join(r_list)
if __name__ == "__main__":
print get_release()