-
Notifications
You must be signed in to change notification settings - Fork 0
/
saranalyze
executable file
·139 lines (120 loc) · 4 KB
/
saranalyze
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
#! /usr/bin/python
# saranalyze: For the analysis of sar files to help diagnose issues
# Written by: Kyle Walker kwalker@redhat.com
#Importing libraries and functionality
import sys, os, numpy, pdb
#Setting global lists that will be accessible between the functions below
column = []
linuxVer = ""
cpuCount = 0; stdSel = 2 #Defaults to datapoints beyond 2 STD Deviations
headTemplate = ["CPU","proc/s","pswpin/s","pgpgin/s","tps","frmpg/s","kbmemfree","kbswpfree","kbhugfree","dentunusd","runq-sz","rxpck/s", "rxerr/s","call/s","scall/s","totsck"]
dataSet = []
stdDev = []
Averages = []
avgLoc = []
Headers = []
headLoc = []
footLoc = []
restarts = [0]
printLines = []
#Responsible for initially opening the sar file passed and parsing contents
def sarLoad():
global iSar, inputFile, printLines, restarts, column, dataSet, Headers, headLoc, avgLoc, cpuCount
iSar = open(inputFile)
placeHolder=0
counter = 0
for line in iSar:
column = filter(None, line.split(" "))
if len(column) > 1:
column[-1] = column[-1].strip()
column.insert(0, counter)
if "Linux" in column[1]:
linuxVer = column[2]
elif placeHolder == 0 and (column[2] in headTemplate or column[3] in headTemplate):
Headers.append(line)
headLoc.append(counter)
placeHolder = 1
elif "Average" in column[1]:
Averages.append(filter(None, line.split(" ")))
Averages[-1][-1] = Averages[-1][-1].strip()
avgLoc.append(counter)
placeHolder = 0
elif "RESTART" in column[3]:
restarts.append(counter)
dataSet.append(column)
elif len(column) == 1 and placeHolder == 0:
footLoc.append(counter)
counter+=1
restarts.append(counter)
#Figure out how many CPUs are in the source sar file
for x in range(0,len(avgLoc)):
try:
if avgLoc[x] == (avgLoc[(x+1)]-1):
cpuCount+=1
break
except ValueError:
pass
iSar.close()
printLines = headLoc+avgLoc+footLoc
#Works through the provided data looking for datapoints that should be printed
def sarAnalyze():
global printLines, dataSet, headLoc, footLoc
cpuArray = []; tempArray = []
for entry in range(headLoc[0],avgLoc[0]):
if not (len(dataSet[entry]) < 12 or dataSet[entry][2] in headTemplate):
cpuArray.append(dataSet[entry][2:])
cpuArray.sort()
for CPU in range(0, (cpuCount+1)):
for iteration in range(CPU,(len(cpuArray)/(cpuCount+1))):
tempArray.append(map(float, cpuArray[iteration][1:]))
stdDev.append(numpy.std(tempArray,axis=0))
tempArray=[]
cpuSelected = cpuCount
for entry in range(headLoc[0],avgLoc[0]):
for columnTemp in range(3, (len(dataSet[(headLoc[0])])-1)):
try:
if float(dataSet[entry][columnTemp]) > round((float(Averages[cpuSelected][(columnTemp-1)])+(stdDev[0][(columnTemp-3)]*stdSel)),2):
printLines.append(dataSet[entry][0])
elif float(dataSet[entry][columnTemp]) < round((float(Averages[cpuSelected][(columnTemp-1)])-(stdDev[0][(columnTemp-3)]*stdSel)),2):
printLines.append(dataSet[entry][0])
except ValueError:
pass
if (cpuSelected + 1) > cpuCount:
cpuSelected = 0
else:
cpuSelected+= 1
pdb.set_trace()
#Prints the lines in the passed file that are deemed interesting
def sarPrint(selRestart):
counter2 = 0
selRestart = (int(selRestart))
printLines.sort()
global iSar, inputFile
iSar = open(inputFile)
for output in iSar:
if counter2 in printLines:
if len(restarts) > 0:
if counter2 < restarts[selRestart] and counter2 > restarts[selRestart-1]:
print output[:-1]
counter2+=1
else:
counter2+=1
else:
print output[:-1]
counter2+=1
else:
counter2+=1
iSar.close()
#Check how we were invoked.
if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
inputFile = sys.argv[1]
os.system("clear")
print "Welcome to saranalyze! Parsing the information in "+inputFile
sarLoad()
sarAnalyze()
if len(restarts) > 0:
print "\nThere are %d restart(s) in the source sar file.\n" % (len(restarts)-2)
selRestart = raw_input("Which data section would you like analyzed for output [1-9]: ")
sarPrint(selRestart)
else:
exit