-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_cpu_avg_usr.py
48 lines (37 loc) · 1.3 KB
/
check_cpu_avg_usr.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
#!/usr/bin/python
import sys,commands
#################
#Set variables
critical = 95.0
warning = 85.0
Number_of_Cores = commands.getstatusoutput("cat /proc/cpuinfo | grep -i processor | wc -l")
#################
Number_of_Cores_int = int(Number_of_Cores[1])
CPU = []
for value in range(0, Number_of_Cores_int):
CPU.append(commands.getstatusoutput("sar -P '%i' | tail -2 |head -1" %value))
CPU = [x[1] for x in CPU]
CPU_value = []
for line in CPU:
CPU_value.append(line.split()[2])
CPU_value = [float(x) for x in CPU_value]
if any(t > critical for t in CPU_value):
print "CRITICAL",
print "CPU Number " + str(CPU_value.index(max(CPU_value))) + " ,%User is " + str(max(CPU_value)),
print "|",
for x in range(len(CPU_value)):
print "CPU_" + str(x) + "=" + str(CPU_value[x]),
sys.exit(2)
elif max(CPU_value)> warning:
print "WARNING",
print "CPU Number " + str(CPU_value.index(max(CPU_value))) + " ,%User is " + str(max(CPU_value)),
print "|",
for x in range(len(CPU_value)):
print "CPU_" + str(x) + "=" + str(CPU_value[x]),
sys.exit(1)
else:
print "OK - Max %User is " + str(max(CPU_value)),
print "|",
for x in range(len(CPU_value)):
print "CPU_" + str(x) + "=" + str(CPU_value[x]),
sys.exit(0)