add new scripts
[monitor.git] / statistics / bm_reboot_unique.r
1
2 source("functions.r");
3
4 # system("parse_rt_data.py > rt_data.csv");
5 # ./bmevents.py events.1-18-10 BootUpdateNode > bm_reboot_2010-01-18.csv
6 # ./bmevents.py events.10-08-09 BootUpdateNode > bm_reboot_2009-10-08.csv 
7 # ./bmevents.py events.29.12.08.dump BootUpdateNode > bm_reboot_2008-12-29.csv
8 # ./bmevents.py events.8-25-09.dump BootUpdateNode > bm_reboot_2009-08-25.csv
9
10 bm <- read.csv('bm_reboot.csv', sep=',', header=TRUE)
11 bm_api <- read.csv('bm_reboot_2008-12-29.csv', sep=',', header=TRUE)
12
13 bm2<-bm
14
15 tstamp_78 <-unclass(as.POSIXct("2008-01-01", origin="1960-01-01"))[1]
16 tstamp_89 <-unclass(as.POSIXct("2009-01-01", origin="1960-01-01"))[1]
17
18 bm_7 <- bm2[which( bm2$start < tstamp_78 ),]
19 bm_8 <- bm2[which( bm2$start >= tstamp_78 & bm2$start < tstamp_89 ),]
20 bm_9 <- bm2[which( bm2$start >= tstamp_89 ),]
21
22 tstamp <-unclass(as.POSIXct("2008-01-01", origin="1960-01-01"))
23 bm_67 <- bm2[which( bm2$start <  tstamp[1] ),]
24 bm_89 <- bm2[which( bm2$start >= tstamp[1] ),]
25
26
27 #start_image("bm_reboot.png")
28
29 par(mfrow=c(2,1))
30 par(mai=c(.5,.4,.5,.4))
31 #year_hist(bm_9, "2009", "2009/06/21", "2010/2/10", 500, 'day', "Daily Reboot Rates")
32 #rows <- year_hist_unique(bm_9, "2009", "2009/06/21", "2010/2/10", 100, 'day', "Unique Daily Reboots")
33 #end_image()
34
35 if ( TRUE )
36 {
37     rows_blocks <- year_hist_unique_recent(bm_9, "2009", "2009/06/21", "2010/2/10", 100, c(1,3,7,14,30), 'day', "Unique Daily Reboots")
38
39     x<-NULL
40     blocks <- c(0,1,3,7,14,30)
41     for ( b in blocks ) { x<- c(x, paste("X", b, sep="")) }
42
43     par(mfrow=c(1,1))
44     par(mai=c(1,.7,.5,.4))
45     start_image("bm_reboot_color.png", width=900)
46
47     barplot(t(rows_blocks[x]), border=NA, col=c('purple', 'blue', 'green', 'red', 'pink', 'orange', 'yellow'), ylim=c(0,100), main="How Recently Node were Rebooted", xlab="Days from June-2009 to Jan-2010", space=0, legend=c("Only today", "Also within 1 day", "Also within 3 days", "Also within 7 days", "Also within 14 days", "Also within 30 days"), ylab="Frequency")
48     end_image()
49
50     #barplot(rows_blocks$X0, border=NA, col=c('purple', 'blue', 'green', 'red', 'pink', 'orange', 'yellow'), ylim=c(0,100))
51
52     #par(mfrow=c(6,1))
53     #par(mai=c(.1,.7,.1,.1))
54     #barplot(rows_blocks$X0, border=NA, col=c('purple'), ylim=c(0,100))
55     #barplot(rows_blocks$X1, border=NA, col=c('blue'), ylim=c(0,100))
56     #barplot(rows_blocks$X3, border=NA, col=c('green'), ylim=c(0,100))
57     #barplot(rows_blocks$X7, border=NA, col=c('red'), ylim=c(0,100))
58     #barplot(rows_blocks$X14, border=NA, col=c('pink'), ylim=c(0,100))
59     #barplot(rows_blocks$X30, border=NA, col=c('orange'), ylim=c(0,100))
60
61     shapiro.test(rows_blocks$X0[ rows_blocks$X0 < 50 ])
62     shapiro.test(rows_blocks$X1[ rows_blocks$X1 < 50 ])
63     shapiro.test(rows_blocks$X3[ rows_blocks$X3 < 50 ])
64     shapiro.test(rows_blocks$X7[ rows_blocks$X7 < 50 ])
65     shapiro.test(rows_blocks$X14[ rows_blocks$X14 < 50 ])
66     shapiro.test(rows_blocks$X30[ rows_blocks$X30 < 50 ])
67 }
68
69
70 #image <- reboot_image(t_9, "2009", "2009/06/21", "2010/2/10", 0, 'day')
71 #myImagePlot(image)
72
73 start_image("st_bm_reboots.png", width=400, height=600)
74 image <- reboot_image(bm_9, "2009", "2009/06/21", "2010/2/10", 0, 'day', title="BootManager Reboots for all Nodes")
75 end_image()
76
77 start_image("st_api_event_reboots.png", width=800, height=600)
78 image2 <- reboot_image(bm_api, "2009", "2008/06/21", "2010/2/10", 0, 'day', title= "API Reboot Events for all Nodes")
79 end_image()
80
81 reboot_frequency <- function ( img )
82 {
83     d <- dim(img)
84     # for each row
85     f <- NULL
86     for ( i in seq(1:d[1]) )
87     {
88         r <- img[i,]
89         f <- c(f, sum(r))
90     }
91     return (f);
92 }
93
94 reboot_events <- function ( img )
95 {
96     d <- dim(img)
97     # for each row
98     f <- NULL
99     for ( i in seq(1:d[2]) )
100     {
101         c <- img[,i]
102         f <- c(f, sum(c))
103     }
104     return (f);
105 }
106
107 time_to_reboot <- function (img, first=0, last=0)
108 {
109     d <- dim(img)
110     # for each row
111     f <- NULL
112     for ( i in seq(1:d[1]) )
113     {
114         if (last == 0 ) { last <- length(img[i,]) }
115         r <- img[i,first:last]
116         # find  first reboot
117         start_i <- 1
118         while ( start_i < length(r) && r[start_i] != 1 ) 
119         { 
120             start_i <- start_i + 1 
121         }
122         end_i <- start_i
123
124         while ( start_i < length(r) )
125         {
126             if ( r[start_i] == 1 && start_i != end_i)
127             {
128                 f <- c(f, start_i-end_i)
129                 while ( start_i < length(r) && r[start_i] == 1 ) { start_i <- start_i + 1 }
130                 end_i <- start_i
131             }
132             start_i <- start_i + 1
133         }
134     }
135     return (f);
136 }
137
138 find_95 <- function (cdf, low=0, high=1000) 
139 {
140     # find the lowest point past the 95th percentile.
141     while ( high - low > 1)
142     {
143         c_low <- cdf(low)
144         c_mid <- cdf(low+floor((high-low)/2))
145         c_high <- cdf(high)
146
147         c_min <- min(min(abs(0.95-c_low), abs(0.95-c_mid)), abs(0.95-c_high))
148
149         if ( c_mid > 0.95 ) {
150             high <- high - floor((high-low)/2)
151             print (sprintf("adjust high: %s\n", high));
152         } else if ( c_mid <= 0.95 ) {
153             low <- low + floor((high-low)/2)
154             print (sprintf("adjust low: %s\n", low));
155         }
156
157         #swap<-0
158         #if ( c_min == abs(0.95-c_mid) ) {
159         #    # is it in top half or bottom half?
160         #    print (sprintf("middle\n"));
161         #    if ( abs(0.95-c_low) < abs(0.95-c_high) ) {
162         #        low <- low + floor((high-low)/2)
163         #        print (sprintf("adjust low: %s\n", low));
164         #    } else { #if ( c_min == abs(0.95-c_high) ) {
165         #        high <- high - floor((high-low)/2)
166         #        print (sprintf("adjust high: %s\n", high));
167         #    }
168         #} else {
169         #    if ( c_min == abs(0.95-c_low) ) {
170         #        high <- high - floor((high-low)/2)
171         #        print (sprintf("adjust high: %s\n", high));
172         #    } else { #if ( c_min == abs(0.95-c_high) ) {
173         #        low <- low + floor((high-low)/2)
174         #        print (sprintf("adjust low: %s\n", low));
175         #    }
176         #}
177     }
178     return (low)
179 }
180
181 #0,193-402,length(r)
182 ttr1 <- time_to_reboot(image,9,122)
183 ttr2 <- time_to_reboot(image,131,223)
184
185 ttr8 <- time_to_reboot(image2,0,193)
186 ttr9 <- time_to_reboot(image2,402)
187
188 x1 <- ecdf(c(ttr1, ttr2))
189 x2 <- ecdf(c(ttr8,ttr9))
190 start_image("reboot_ttr_cdf.png")
191 plot(x1, col.vert='red', col.hor="red", col.points="red", pch='*', xlab="Days to Reboot", ylab="Percentile", verticals=TRUE, xlim=c(0,170), main="CDF of Days to Reboot for BM & API Events")
192 plot(x2, col.vert='blue', col.hor="blue", col.points="blue", pch=20, verticals=TRUE, add=TRUE)
193 legend(130, 0.15, legend=c("BM Uploads", "API Events"), col=c('red', 'blue'), pch=c(42, 20))
194 abline(0.95,0)
195 v1<-find_95(x1)
196 v2<-find_95(x2)
197 abline(v=v1, col="pink")
198 abline(v=v2, col="light blue")
199 axis(1, labels=c(v1,v2), at=c(v1,v2))
200
201 abline(v=7, col="grey")
202 abline(v=14, col="grey")
203 abline(v=21, col="grey")
204 abline(v=28, col="grey")
205 abline(v=42, col="grey")
206 abline(v=56, col="grey")
207 end_image()
208
209 e <- reboot_events(image)
210 e2 <- reboot_events(image2)
211 x1 <- ecdf(e)
212 x2 <- ecdf(e2)
213
214 start_image("reboot_days_cdf.png")
215 plot(x1, col.vert='red', col.hor="red", col.points="red", pch='*', xlab="Reboots in a Single Day", ylab="Percentile", verticals=TRUE, xlim=c(0,100), main="CDF of Reboots per Day for BM & API Events")
216 plot(x2, col.vert='blue', col.hor="blue", col.points="blue", pch=20, verticals=TRUE, add=TRUE)
217 legend(75, 0.15, legend=c("BM Uploads", "API Events"), col=c('red', 'blue'), pch=c(42, 20))
218 abline(0.95,0)
219 v1<-find_95(x1)
220 v2<-find_95(x2)
221 abline(v=v1, col="pink")
222 abline(v=v2, col="light blue")
223 axis(1, labels=c(v1,v2), at=c(v1,v2))
224 end_image()
225
226
227
228 f <- reboot_frequency(image)
229 f2 <- reboot_frequency(image2)
230 x1 <- ecdf(f)
231 x2 <- ecdf(f2)
232
233 start_image("reboot_node_cdf.png")
234 par(mfrow=c(1,1))
235 par(mai=c(.9,.8,.5,.4))
236 plot(x1, col.vert='red', col.hor="red", col.points="red", pch='*', xlab="Reboots per Node", ylab="Percentile", verticals=TRUE, xlim=c(0,100), main="CDF of Reboot per Node for BM & API Events")
237 plot(x2, col.vert='blue', col.hor="blue", col.points="blue", pch=20, verticals=TRUE, add=TRUE)
238 legend(75, 0.15, legend=c("BM Uploads", "API Events"), col=c('red', 'blue'), pch=c(42, 20))
239 abline(0.95,0)
240 v1<-find_95(x1)
241 v2<-find_95(x2)
242 abline(v=v1, col="pink")
243 abline(v=v2, col="light blue")
244 axis(1, labels=c(v1,v2), at=c(v1,v2))
245 end_image()
246
247
248
249 par(mfrow=c(1,1))
250 par(mai=c(.7,.7,.7,.7))