add new scripts
[monitor.git] / statistics / site_scores_pcu.r
1
2 source("functions.r");
3
4 #system("../nodequery.py --nodelist > ../nodelist.txt")
5 #system("../comonquery.py --cache --nodelist ../nodelist.txt --select 'resptime>0' --fields='name,cpuspeed,numcores,memsize,disksize,bwlimit' | grep -v null | ./hn2lb.py | ./hn2pcustatus.py | sed -e "s/none/0/g" -e "s/Not_Run/0.5/g" -e "s/error/0.5/g" -e "s/Ok/1/g" > ./out_resources.csv ")
6
7 mdrc <- read.csv("out_resources.csv", TRUE, sep=",")
8
9 # replace all weird numbers with defaults of 100mbps 
10 mdrc$bwlimit <- replace(mdrc$bwlimit, which(mdrc$bwlimit==0 | mdrc$bwlimit==1), 100000)
11 #mdrc$pcus <- replace(mdrc$pcustatus, which(mdrc$pcustatus=="none"), 0);
12 #mdrc$pcus <- replace(mdrc$pcus, which(mdrc$pcus=="error" | mdrc$pcusu=="Not_Run"), 0.5);
13 #mdrc$pcus <- replace(mdrc$pcus, which(mdrc$pcus=="Ok"), 1);
14
15 f<-slices_4
16
17 s2<- f(mdrc, FALSE);
18 mdrc$score <- s2;
19 b<-30;
20
21 # ----------------------
22 ### LOGINBASE
23 unique_loginbase_length <- length(unique(mdrc$loginbase));
24 unique_lb <- list(loginbase=array(0,c(unique_loginbase_length)), 
25                                   score=array(0,c(unique_loginbase_length)),
26                                   memsize=array(0,c(unique_loginbase_length)),
27                                   disksize=array(0,c(unique_loginbase_length)),
28                                   cpuspeed=array(0,c(unique_loginbase_length)),
29                                   bwlimit=array(0,c(unique_loginbase_length)),
30                                   pcustatus=array(0,c(unique_loginbase_length))
31                           )
32
33 for ( i in 1:length(mdrc$loginbase) )
34 {
35     r <- mdrc[i,];
36         unique_lb$loginbase[r$loginbase] <- r$loginbase;
37         unique_lb$score[r$loginbase]     <- unique_lb$score[r$loginbase] + r$score;
38
39         v <- f(r, TRUE);
40         unique_lb$memsize[r$loginbase]  <- unique_lb$memsize[r$loginbase]  + v[1];
41         unique_lb$disksize[r$loginbase] <- unique_lb$disksize[r$loginbase]  + v[2];
42         unique_lb$cpuspeed[r$loginbase] <- unique_lb$cpuspeed[r$loginbase]  + v[3];
43         unique_lb$bwlimit[r$loginbase] <- unique_lb$bwlimit[r$loginbase]  + v[4];
44         unique_lb$pcustatus[r$loginbase] <- unique_lb$pcustatus[r$loginbase]  + v[5];
45 }
46
47 df<- data.frame(unique_lb)
48
49 h<- hist(df$score, breaks=b);
50 bins<-length(h$breaks);
51 c<- array(0,c(bins));
52 d<- array(0,c(bins));
53 m<- array(0,c(bins));
54 b<- array(0,c(bins));
55 p<- array(0,c(bins));
56 # foreach score value, find which range it falls into, 
57 # then in three columns for cpu, mem, disk, record the fraction of each.
58 # then plot each sequence in a stacked graph, perhaps beside h$counts
59 for ( i in 1:length(df$cpuspeed) )
60 {
61     r <- df[i,];
62     s <- index_of_bin(h, r$score); # find bin position...
63     # take fraction that each component contributes to the total, and add to sum
64
65     m[s] <- m[s] + unique_lb$memsize[r$loginbase]/r$score;
66     d[s] <- d[s] + unique_lb$disksize[r$loginbase]/r$score;
67     c[s] <- c[s] + unique_lb$cpuspeed[r$loginbase]/r$score;
68     b[s] <- b[s] + unique_lb$bwlimit[r$loginbase]/r$score;
69     p[s] <- p[s] + unique_lb$pcustatus[r$loginbase]/r$score;
70 }
71
72 #vals <- list(bwlimit=b,cpuspeed=c,disksize=d,memsize=m)
73 a <- array(c(p,b,c,d,m), dim=c(bins, 5));
74
75 #png("/Users/soltesz/Downloads/slice_policy_5.png")
76 par(mfrow=c(2,1))
77 par(mai=c(0.5,1,0.5,0.2))
78 barplot(c(0,h$counts), 
79     xlab="slice count", 
80     main="Distribution of Site Scores", 
81     ylab="Total Frequency", 
82     ylim=c(0,70))
83 par(mai=c(1.0,1,0,0.2));
84 barplot(t(a), 
85     legend=c("PCU Status", "BWlimit (Mbps)", "CPUspeed (GHz)", "DISKsize (GB)", "MEMsize (GB)"), 
86     col=c("orange", "lightyellow", "pink", "lightblue", "lightgreen"), 
87     ylim=c(0,70),
88     ylab="Break-down by Resource",
89     xlab="Site Score",
90     names.arg=c(0,h$breaks[1:length(h$breaks)-1]),
91 );
92 #dev.off()
93
94