-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcap-loss.py
95 lines (73 loc) · 1.83 KB
/
cap-loss.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
#!/usr/bin/python
#
# green
# <low threshold>
# yellow
# <med threshold>
# purple
# <high threshold>
# red
#
import datetime
### ---------------------
data_file = '/home/bro/logs/current/capture_loss.log'
lowThresh = 0.2
medThresh = 1.0
highThresh = 3.0
### ---------------------
os = open(data_file)
avgStore = {}
runAvg = 0
hour_set = []
host_set = []
CSI="\x1B["
reset=CSI+"m"
for l in os.readlines():
if ( not l.startswith("#") ):
ll = l.split('\t')
hour = datetime.datetime.fromtimestamp( float(ll[0]) ).hour
host = ll[2]
value = float(ll[5])
if ( host not in host_set ):
host_set.append(host)
if ( hour not in hour_set ):
hour_set.append(hour)
try:
runAvg = avgStore[host, hour]
except KeyError:
runAvg = value
avgStore[host, hour] = (runAvg + value) / 2
# now loop through the data matrix and
# print out the results
#
x_host = ""
y_hour = ""
test_val = 0.00
retValue = ""
host_set.sort()
hour_set.sort()
print
for x_host in host_set:
print x_host, "x_host",
for y_hour in hour_set:
try:
test_val = avgStore[x_host,y_hour]
except:
retVal = CSI+"30;40m" + u"\u2588" + CSI + "0m"
if test_val < highThresh:
# purple
retVal = CSI+"35;40m" + u"\u2588" + CSI + "0m"
if test_val < medThresh:
# yellow
retVal = CSI+"33;40m" + u"\u2588" + CSI + "0m"
if test_val < lowThresh:
# green
retVal = CSI+"32;40m" + u"\u2588" + CSI + "0m"
if test_val >= highThresh:
# red
retVal = CSI+"31;40m" + u"\u2588" + CSI + "0m"
print retVal.encode('utf-8'),
print
print " Hour: ",
for y_hour in hour_set:
print y_hour,