838e0b1dc2e4412a802f3997e882998fe11ff9df
[monitor.git] / statistics / myops_restoration.r
1 source("functions.r");
2
3
4 nsh <- read.csv('node_status_history.csv', sep=',', header=TRUE)
5
6 # system("./harvest_nodehistory.py > node_status_history_nopcu.csv")
7 nsh_nopcu <- read.csv('node_status_history_nopcu.csv', sep=',', header=TRUE)
8
9 nsh_m1 <- read.csv('node_status_history_m1.csv', sep=',', header=TRUE)
10 # system("stats-m1/harvest_nodehistory_m1.py > ./node_status_history_m1_nopcu.csv")
11 nsh_m1_nopcu_total <- read.csv('node_status_history_m1_nopcu_total.csv', sep=',', header=TRUE)
12 nsh_m1_nopcu_notice <- read.csv('node_status_history_m1_nopcu.csv', sep=',', header=TRUE)
13 nsh_m1_nopcu_kernel <- read.csv('node_status_history_m1_nopcu_may08sep08.csv', sep=',', header=TRUE)
14
15 node_hist_image <- function (t, year, from, to, max=0, type="week", title="")
16 {
17     dates <-seq(as.Date(from), as.Date(to), type)
18     months <- format(dates, "%b-%d")
19     hbreaks<-unclass(as.POSIXct(dates))
20
21     image <- matrix(data=0, nrow=max(as.numeric(t$hostname)), ncol=length(hbreaks))
22
23     for ( i in seq(1, length(hbreaks)) )
24     {
25         # find the range : d plus a day
26         d <- hbreaks[i]
27         d_end <- d+60*60*24
28         # find unique hosts in this day range
29         t_sub <- t[which(t$start > d & t$start <= d_end & t$status == 'down'),]
30         unique_hosts <- unique(t_sub$hostname)
31         if (length(unique_hosts) == 0 ) { next }
32
33         host_n_list <- unique_hosts
34         host_s_list <- as.character(unique_hosts)
35
36         for ( hi in seq(1, length(unique_hosts))  ) 
37         {
38             host_s <- host_s_list[hi]
39             host_n <- host_n_list[hi]
40             # events for this host after d (to avoid already identified events)
41             ev <- t[which(t$hostname == host_s & t$start > d ),]
42             print (sprintf("events length for host %s %s", host_s, length(ev$start)));
43             # get down events for this host
44             down_ev_index_list <- which(ev$status == 'down')
45             for ( e_i in down_ev_index_list )
46             {
47                 if ( e_i == length(ev$status) ) { 
48                     # then the node ends down, so fill in the rest with 1.
49                     for ( j in seq(i,length(hbreaks)) ) {
50                         image[host_n,j] <- 1
51                     }
52                 } else {
53                     # then there is a subsequent 'good' event
54                     good_ev <- ev[e_i+1,]
55                     down_ev <- ev[e_i,]
56                     dbreaks <- seq(d,good_ev$start+60*60*24,60*60*24)
57                     # for every index for time d, to good_ev$start
58                     l<-length(dbreaks)
59                     print (sprintf("length %s",l));
60                     for ( j in seq(i,i+l) )
61                     {
62                         image[host_n,j] <- 1
63                     }
64                 }
65             }
66         }
67     }
68     myImagePlot(image, xLabels=months, yLabels=c(""), title=title)
69     return (image);
70 }
71
72
73
74 node_hist_dist <- function (t, year, from, to, max=0, type="week", title="")
75 {
76     dates <-seq(as.Date(from), as.Date(to), type)
77     months <- format(dates, "%b-%d")
78     hbreaks<-unclass(as.POSIXct(dates))
79     current_ts <- unclass(as.POSIXct(Sys.Date()))
80
81     dist <- NULL
82
83     unique_hosts <- unique(t$hostname)
84     host_n_list <- unique_hosts
85     host_s_list <- as.character(unique_hosts)
86
87     down <- 0
88
89     for ( hi in seq(1, length(unique_hosts))  ) 
90     {
91         host_s <- host_s_list[hi]
92         host_n <- host_n_list[hi]
93         # events for this host after d (to avoid already identified events)
94         ev <- t[which( t$hostname == host_s ),]
95         print (sprintf("events length for host %s %s", host_s, length(ev$start)));
96         # get down events for this host
97         down_ev_index_list <- which(ev$status == 'down')
98         for ( e_i in down_ev_index_list )
99         {
100             # when equal, there is no resolution so leave it as down
101             if ( e_i != length(ev$status) ) { 
102                 good_ev <- ev[e_i+1,]
103                 down_ev <- ev[e_i,]
104                 dist <- c(dist, good_ev$start - down_ev$start)
105             } else if ( e_i == length(ev$status) && length(ev$status) == 1) { 
106                 print (sprintf("DOWN FOREVER! %s", length(ev$start) ))
107                 down <- down + 1
108                 dist <- c(dist, 10*current_ts - ev$start)
109             }
110         }
111     }
112     print(down);
113     return (dist);
114 }
115
116
117
118 # data collected from M2 pickle files
119 dnc <- read.csv('daily-available-node-count.csv', sep=',', header=TRUE)
120
121 dnc2<-add_timestamp(dnc)
122
123 tstamp_08 <-unclass(as.POSIXct("2008-05-07", origin="1970-01-01"))[1]
124 dnc2 <- dnc2[which( dnc2$start >  tstamp_08 ),]
125
126
127 dates <-seq(as.Date('2008-05-07'), as.Date('2009-05-07'), 'week')
128 months <- format(dates, "%b")
129 hbreaks<-unclass(as.POSIXct(dates))
130
131 x_start<-unclass(as.POSIXct("2008-05-01", origin="1970-01-01"))[1]
132 x_end  <-unclass(as.POSIXct("2009-06-1", origin="1970-01-01"))[1]
133
134
135 tstamp_0510 <-abline_at_date("2008-05-10", col='grey20', lty=0, height=570)
136 # dates takes from reboot_image() output for API events.
137 # green
138 tstamp_0610 <-abline_at_date("2008-06-10", col='grey40', lty=5, height=570)
139 tstamp_0815 <-abline_at_date("2008-08-15", col='grey70', lty=1, height=570)
140
141 # red
142 #tstamp_0905 <-abline_at_date("2008-09-05", col='grey70', height=570)
143 tstamp_0924 <-abline_at_date("2008-09-24", col='grey70', lty=1, height=570)
144 tstamp_1015 <-abline_at_date("2008-10-15", col='grey40', lty=5, height=570)
145 # blue
146 #tstamp_1105 <-abline_at_date("2008-11-05", col='white', lty=2, height=570)
147 #tstamp_1214 <-abline_at_date("2008-12-14", col='grey70', height=570)
148 tstamp_0223 <-abline_at_date("2009-02-23", col='grey70', height=570)
149 # red
150 #tstamp_0313 <-abline_at_date("2009-03-13", col='grey70', height=570)
151
152 start_image("myops_restore_nopcu.png")
153 par(mfrow=c(2,1))
154 par(mai=c(.9,.8,.1,.1))
155 plot(dnc2$start[which(!is.na(dnc2$available) & (dnc2$start > tstamp_0815 & dnc2$start <= tstamp_1015) )], 
156     dnc2$available[which(!is.na(dnc2$available) & (dnc2$start > tstamp_0815 & dnc2$start <= tstamp_1015) )], 
157     type='l', col='red', ylim=c(0,600), xlim=c(x_start, x_end),
158     xlab="", ylab="Online Node Count", axes=F)
159
160 lines(dnc2$start[which(!is.na(dnc2$available) & (dnc2$start > tstamp_0223) )], 
161     dnc2$available[which(!is.na(dnc2$available) & (dnc2$start > tstamp_0223) )], 
162     type='l', col='red')
163
164 lines(dnc2$start[which(!is.na(dnc2$available) & dnc2$start > tstamp_1015 & dnc2$start <= tstamp_0223)], dnc2$available[which(!is.na(dnc2$available)& dnc2$start > tstamp_1015 & dnc2$start <= tstamp_0223)], lty=2, type='l', col='blue')
165
166 lines(dnc2$start[which(!is.na(dnc2$available) & dnc2$start > tstamp_0510 & dnc2$start <= tstamp_0815)], dnc2$available[which(!is.na(dnc2$available)& dnc2$start > tstamp_0510 & dnc2$start <= tstamp_0815)], lty=3, type='l', col='darkgreen')
167
168 #lines(dnc2$start[which(!is.na(dnc2$available))], dnc2$available[which(!is.na(dnc2$available))], 
169 #type='l', col='red', ylim=c(0,1000))
170 axis(2, las=1)
171 axis(1, cex.axis=0.7, labels=months, at=hbreaks)
172        
173
174
175 tstamp_0510 <-abline_at_date("2008-05-10", col='grey20', lty=0, height=570)
176 # dates takes from reboot_image() output for API events.
177 # green
178 tstamp_0610 <-abline_at_date("2008-06-10", col='grey40', lty=5, height=570)
179 tstamp_0815 <-abline_at_date("2008-08-15", col='grey70', lty=1, height=570)
180
181 # red
182 #tstamp_0905 <-abline_at_date("2008-09-05", col='grey70', height=570)
183 tstamp_0924 <-abline_at_date("2008-09-24", col='grey70', lty=1, height=570)
184 tstamp_1015 <-abline_at_date("2008-10-15", col='grey40', lty=5, height=570)
185 # blue
186 #tstamp_1105 <-abline_at_date("2008-11-05", col='white', lty=2, height=570)
187 #tstamp_1214 <-abline_at_date("2008-12-14", col='grey70', height=570)
188 tstamp_0223 <-abline_at_date("2009-02-23", col='grey70', height=570)
189 # red
190 #tstamp_0313 <-abline_at_date("2009-03-13", col='grey70', height=570)
191
192 #text(x=c(tstamp_0610+(tstamp_0815-tstamp_0610)/2,
193 #         tstamp_0815+(tstamp_0905-tstamp_0815)/2,
194 #         tstamp_0924+(tstamp_1015-tstamp_0924)/2, 
195 #         tstamp_1015+(tstamp_1214-tstamp_1015)/2, 
196 #         tstamp_1214+(tstamp_0223-tstamp_1214)/2, 
197 #         tstamp_0223+(tstamp_0313-tstamp_0223)/2), 
198 #     y=c(0),
199 #     labels=c("bug1", 'fix1', 'fix2', 'fix3', 'bug2', 'fix4')) #, 'fix 2', 'fix 3', 'fix 4'))
200
201 text(x=c( tstamp_0815,
202          tstamp_0924,
203          tstamp_0223),
204      y=c(610),
205      adj=c(1, 0.5),
206      labels=c('fix1', 'fix2', 'fix3'))
207
208
209 text(x=c(tstamp_0510-(60*60*24*10), 
210         tstamp_0610,
211         tstamp_1015),
212      adj=c(0, 0.5),
213      y=c(610),
214      labels=c('Events:', 'bug1', 'bug2'))
215
216 mtext("2008                                 2009", 1,2)
217 legend(unclass(as.POSIXct("2009-02-23", origin="1970-01-01"))[1], 200,
218         cex=0.7,
219         legend=c("Typical MyOps", "Bug1", "Bug2", 'Bug Added', 'Fix Added'),
220         pch=c('-', '-', '-'),
221         col=c('red', 'darkgreen', 'blue', 'grey20', 'grey70'),
222         lty=c(1, 3, 2, 5, 1), merge=T)
223
224         #legend=c("Registered", "Online", 'Kernel Update', 'MyOps Event'),
225         #pch=c('-', '-', '-', '-'),
226         #col=c('blue', 'red', 'grey20', 'grey70'),
227         #lty=c(1, 1, 2, 1), merge=T)
228
229 ###################################
230
231 t_0815 <- unclass(as.POSIXct("2008-08-15", origin="1970-01-01"))[1]
232 t_0905 <- unclass(as.POSIXct("2008-09-05", origin="1970-01-01"))[1]
233
234 t_0924 <- unclass(as.POSIXct("2008-09-24", origin="1970-01-01"))[1]
235 t_1015 <- unclass(as.POSIXct("2008-10-15", origin="1970-01-01"))[1]
236
237 t_0223 <- unclass(as.POSIXct("2009-02-23", origin="1970-01-01"))[1]
238 t_0313 <- unclass(as.POSIXct("2009-03-13", origin="1970-01-01"))[1]
239
240 nsh_m1_short <- nsh_m1_nopcu_total[which( 
241         (nsh_m1_nopcu_total$start > t_0815 & nsh_m1_nopcu_total$start <= t_0313) ),]
242 nsh_dist_m1 <- node_hist_dist(nsh_m1_short, '2008', '2008-05-01', '2009-05-22', 0, 'day')
243 d_m1_total<- ecdf(nsh_dist_m1/(60*60*24))
244
245 # NOTE: something happened betweeen 10-2 and 10-3
246 # NOTICE BUG
247 t_1015 <- unclass(as.POSIXct("2008-10-15", origin="1970-01-01"))[1]
248 t_0224 <- unclass(as.POSIXct("2009-02-24", origin="1970-01-01"))[1]
249 nsh_m1_short <- nsh_m1_nopcu_notice[which(nsh_m1_nopcu_notice$start > t_1015 & nsh_m1_nopcu_notice$start <= t_0224),]
250 nsh_dist_m1 <- node_hist_dist(nsh_m1_short, '2008', '2008-10-01', '2009-03-22', 0, 'day')
251 d_m1_notice_bug <- ecdf(nsh_dist_m1/(60*60*24))
252
253
254 # KERNEL BUG
255 t_0530 <- unclass(as.POSIXct("2008-05-30", origin="1970-01-01"))[1]
256 t_0815 <- unclass(as.POSIXct("2008-08-15", origin="1970-01-01"))[1]
257 nsh_m1_short <- nsh_m1_nopcu_kernel[which(nsh_m1_nopcu_kernel$start > t_0530 & nsh_m1_nopcu_kernel$start <= t_0815),]
258 nsh_dist_m1 <- node_hist_dist(nsh_m1_short, '2008', '2008-05-10', '2008-08-15', 0, 'day')
259 d_m1_kernel_bug <- ecdf(nsh_dist_m1/(60*60*24))
260
261
262 # d<-ecdf(nsh_dist[which(nsh_dist/(60*60*24) < 90 )]/(60*60*24)), 
263 # 180 ~= 6 months.
264 par(mai=c(.9,.9,.1,.3))
265 #plot(d, xlim=c(0,180), ylim=c(0,1), axes=F, xlab="Days to Resolve", ylab="Percentile",
266 #   col.hor='red', col.vert='red', pch='.', col.points='red', main="")
267
268 x_lim_max <- 150
269
270 plot(d_m1_total, xlim=c(0,x_lim_max), ylim=c(0,1), axes=F, xlab="Days to Resolve", 
271     ylab="Fraction of Offline Nodes Restored", col.hor='red', col.vert='red', pch='.', 
272     col.points='red', main="")
273
274 plot(d_m1_notice_bug, xlim=c(0,x_lim_max), ylim=c(0,1), xlab="Days to Resolve", 
275     col.hor='blue', col.vert='blue', pch='.', 
276     col.points='blue', lty=2, add=TRUE)
277
278 plot(d_m1_kernel_bug, xlim=c(0,x_lim_max), ylim=c(0,1), xlab="Days to Resolve", 
279     col.hor='darkgreen', col.vert='darkgreen', pch='.', 
280     col.points='darkgreen', lty=3, add=TRUE)
281
282 weeks <- c(0,7,14,21,28,60,90,120,150,180)
283 axis(1, labels=weeks, at=weeks)
284 percentages <- c(0,0.25, 0.5, 0.75, 0.85, 0.95, 1)
285 axis(2, las=1, labels=percentages, at=percentages)
286
287 abline(v=c(7,14,21,28), col='grey80', lty=2)
288 abline(h=c(0.5, 0.6, 0.75, 0.85, 0.95 ), col='grey80', lty=2)
289 abline(v=c(91), col='grey80', lty=2)
290
291
292 legend(92, 0.25,
293        cex=0.7,
294        legend=c("Typical MyOps", "Only Notices", "No Notices"),
295        pch=c('-', '-', '-'),
296        col=c('red', 'blue', 'darkgreen'),
297        lty=c(1, 2, 3), merge=T)
298
299 end_image()