clearer names for actions, and infer actions better
[monitor.git] / statistics / site_scores_bw.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 > ./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
12 f<-slices_3
13
14 s2<- f(mdrc, FALSE);
15 mdrc$score <- s2;
16 b<-30;
17
18 # ----------------------
19 ### LOGINBASE
20 unique_loginbase_length <- length(unique(mdrc$loginbase));
21 unique_lb <- list(loginbase=array(0,c(unique_loginbase_length)), 
22                                   score=array(0,c(unique_loginbase_length)),
23                                   memsize=array(0,c(unique_loginbase_length)),
24                                   disksize=array(0,c(unique_loginbase_length)),
25                                   cpuspeed=array(0,c(unique_loginbase_length)),
26                                   bwlimit=array(0,c(unique_loginbase_length))
27                           )
28
29 for ( i in 1:length(mdrc$loginbase) )
30 {
31     r <- mdrc[i,];
32         unique_lb$loginbase[r$loginbase] <- r$loginbase;
33         unique_lb$score[r$loginbase]     <- unique_lb$score[r$loginbase] + r$score;
34
35         v <- f(r, TRUE);
36         unique_lb$memsize[r$loginbase]  <- unique_lb$memsize[r$loginbase]  + v[1];
37         unique_lb$disksize[r$loginbase] <- unique_lb$disksize[r$loginbase]  + v[2];
38         unique_lb$cpuspeed[r$loginbase] <- unique_lb$cpuspeed[r$loginbase]  + v[3];
39         unique_lb$bwlimit[r$loginbase] <- unique_lb$bwlimit[r$loginbase]  + v[4];
40 }
41
42 df<- data.frame(unique_lb)
43
44 h<- hist(df$score, breaks=b);
45 bins<-length(h$breaks);
46 c<- array(0,c(bins));
47 d<- array(0,c(bins));
48 m<- array(0,c(bins));
49 b<- array(0,c(bins));
50 # foreach score value, find which range it falls into, 
51 # then in three columns for cpu, mem, disk, record the fraction of each.
52 # then plot each sequence in a stacked graph, perhaps beside h$counts
53 for ( i in 1:length(df$cpuspeed) )
54 {
55     r <- df[i,];
56     s <- index_of_bin(h, r$score); # find bin position...
57     # take fraction that each component contributes to the total, and add to sum
58
59     m[s] <- m[s] + unique_lb$memsize[r$loginbase]/r$score;
60     d[s] <- d[s] + unique_lb$disksize[r$loginbase]/r$score;
61     c[s] <- c[s] + unique_lb$cpuspeed[r$loginbase]/r$score;
62     b[s] <- b[s] + unique_lb$bwlimit[r$loginbase]/r$score;
63 }
64
65 #vals <- list(bwlimit=b,cpuspeed=c,disksize=d,memsize=m)
66 a <- array(c(b,c,d,m), dim=c(bins, 4));
67
68 png("/Users/soltesz/Downloads/slice_policy_4.png")
69 par(mfrow=c(2,1))
70 par(mai=c(0.5,1,0.5,0.2))
71 barplot(c(0,h$counts), 
72     xlab="slice count", 
73     main="Distribution of Site Scores", 
74     ylab="Total Frequency", 
75     ylim=c(0,70))
76 par(mai=c(1.0,1,0,0.2));
77 barplot(t(a), 
78     legend=c("BWlimit (Mbps)", "CPUspeed (GHz)", "DISKsize (GB)", "MEMsize (GB)"), 
79     col=c("lightyellow", "pink", "lightblue", "lightgreen"), 
80     ylim=c(0,70),
81     ylab="Break-down by Resource",
82     xlab="Site Score",
83     names.arg=c(0,h$breaks[1:length(h$breaks)-1]),
84 );
85 dev.off()
86
87