-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_machine_stats
executable file
·274 lines (249 loc) · 10.2 KB
/
make_machine_stats
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
USAGE="Usage: make_machine_stats < hour | day | week | month | year | from (mon) (day) (year) to (mon) (day) (year) filename >"
LENGTH="-last$1"
case $1 in
hour)
LENGTH="-lasthours 1"
FILENAME="Hour_"
;;
day)
FILENAME="Day_"
;;
week)
FILENAME="Week_"
;;
month)
case $2 in
[1-9]|1[0-2])
THISMONTH="$2" ;;
*)
THISMONTH=`date +%m` ;;
esac
THENEXTMONTH=`echo "$THISMONTH + 1" | bc`
THISYEAR=`date +%Y`
TOYEAR=$THISYEAR
if [ "$THENEXTMONTH" = "13" ]
then
TOYEAR=`echo "$THISYEAR + 1" | bc`
THENEXTMONTH=1
fi
OUTFILE=`date -d "$THISMONTH/01" +%b`
eval "./make_machine_stats from $THISMONTH 1 $THISYEAR to $THENEXTMONTH 1 $TOYEAR Month$OUTFILE"
FILENAME="Month_Current"
;;
year)
if [ -n "$2" ]
then
THISYEAR=$2
if [ $THISYEAR -lt `date +%Y` ]
then
TOYEAR=$THISYEAR
else
TOYEAR=`echo "$THISYEAR + 1" | bc`
fi
else
THISYEAR=`date +%Y`
TOYEAR=`echo "$THISYEAR + 1" | bc`
fi
OUTFILE="Year_"$THISYEAR
eval "./make_machine_stats from 1 1 $THISYEAR to 12 31 $TOYEAR $OUTFILE"
exit
;;
from)
if [ $# != 9 -o $5 != "to" ]
then
echo $USAGE
exit 1
fi
FROMMON=$2
FROMDAY=$3
FROMYEAR=$4
TOMON=$6
TODAY=$7
TOYEAR=$8
FILENAME=$9
LENGTH="-from $2 $3 $4 -to $6 $7 $8"
;;
*)
echo $USAGE
exit 1
;;
esac
RESGROUPS=`condor_stats -pool $POOL $LENGTH -resgrouplist 2>/dev/null`
if [ "$RESGROUPS" = "No Data." -o $? = "1" ]
then
exit 0
fi
DATAFILENAME=$FILENAME-`date +%m%d%y%H%M%S`
touch /tmp/cvw.$$
for group in $RESGROUPS
do
condor_stats -pool $POOL $LENGTH -orgformat -resgroupquery $group >> /tmp/cvw.$$
done
# bgietzel (041107) - The line below where we set $11 to 0 is a workaround for a bug
# fixed in Condor version 6.8.4 where the backfill numbers are not zeroed correctly.
# This results in abnormally large values for backfill and breaks the applet display.
(echo $STATFILE; cat /tmp/cvw.$$) | awk \
'BEGIN { SEP=" A "; numarch=0 }
{ if ( NR == 1 ) {
statfile = $1
} else {
if ( arch != $2 ) {
alltimes[$1]=1
arch=$2
archnames[numarch]=arch
numarch++
for (atime in alltimes) {
archdata[arch SEP atime]="0,0,0,0,0"
}
lasttime=0
}
alltimes[$1]=1
if ($11 > 1000000) {
$11 = 0;
}
archdata[arch SEP $1]=sprintf("%.1f,%.1f,%.1f,%.1f,%.1f",$8,$4+$5+$7,$6,$11,$12)
archdata_owner[arch SEP $1]=sprintf("%.1f",$8)
archdata_idle[arch SEP $1]=sprintf("%.1f",$4+$5+$7)
archdata_condor[arch SEP $1]=sprintf("%.1f",$6)
archdata_backfill[arch SEP $1]=sprintf("%.1f",$11)
archdata_drained[arch SEP $1]=sprintf("%.1f",$12)
if ( lasttime > 0 ) {
total = $4 + $5 + $6 + $7 + $8 + $11 + $12
secs = $1 - lasttime
if ( (secs - lastsecs > 120) && (lastsecs != 0) ) {
total = 0
}
lastsecs = secs
if ( total > 0 ) {
archavetot[arch] += secs
ownerper = ($8 / total) * 100
claimedper = ($6 / total) * 100
backfillper = ($11 / total) * 100
drainedper = ($12 / total) * 100
archrawowner[arch] += $8 * secs
archrawclaimed[arch] += $6 * secs
archrawbackfill[arch] += $11 * secs
archrawdrained[arch] += $12 * secs
archrawunclaimed[arch] += (total - $6 - $8 - $11) * secs
archaveowner[arch] += ownerper * secs
archaveclaimed[arch] += claimedper * secs
archavebackfill[arch] += backfillper * secs
archavedrained[arch] += drainedper * secs
if ( archrawpeakowner[arch] < $8 ) {
archrawpeakowner[arch] = $8
}
if ( archrawpeakclaimed[arch] < $6 ) {
archrawpeakclaimed[arch] = $6
}
if ( archrawpeakbackfill[arch] < $11 ) {
archrawpeakbackfill[arch] = $11
}
if ( archrawpeakdrained[arch] < $12 ) {
archrawpeakdrained[arch] = $12
}
if ( archpeakowner[arch] < ownerper ) {
archpeakowner[arch] = ownerper
}
if ( archpeakclaimed[arch] < claimedper ) {
archpeakclaimed[arch] = claimedper
}
}
}
lasttime=$1
}
}
END {
statTime = systime()
table = ""
for (i=0; i<numarch; i++) {
j=archnames[i]
if ( archavetot[j] > 0 ) {
ownerraw = archrawowner[j] / archavetot[j]
claimedraw = archrawclaimed[j] / archavetot[j]
unclaimedraw = archrawunclaimed[j] / archavetot[j]
backfillraw = archrawbackfill[j] / archavetot[j]
drainedraw = archrawdrained[j] / archavetot[j]
ownerp = archaveowner[j] / archavetot[j]
claimedp = archaveclaimed[j] / archavetot[j]
backfillp = archavebackfill[j] / archavetot[j]
drainedp = archavedrained[j] / archavetot[j]
shadecount++
if ( shadecount % 2 < 1 ) {
class = "class=\\\"even\\\""
} else {
class = "class=\\\"odd\\\""
}
table = table sprintf("<tr %s><td><a href=javascript:chartM.updateChart(\\\"%s\\\")>%s<\\/a>", \
class, j, j)
table = table sprintf("<\\/td><td>%.1f<br>(%.1f%%)<\\/td><td>%.1f<br>(%.1f%%)<\\/td><td>%.1f<br>(%.1f%%)<\\/td><td>%.1f<br>(%.1f%%)<\\/td><td>%.1f<br>(%.1f%%)<\\/td>", \
ownerraw, ownerp, claimedraw, claimedp, unclaimedraw, 100 - ownerp - claimedp - backfillp - drainedp, backfillraw, backfillp, drainedraw, drainedp)
table = table sprintf("<td>%d<br>(%d%%)<\\/td><td>%d<br>(%d%%)<\\/td><\\/tr>", \
archrawpeakowner[j], archpeakowner[j], archrawpeakclaimed[j], archpeakclaimed[j])
}
j_misc[i] = sprintf("\"misc\":{\"arch\":\"%s\",\"oa\":%.1f,\"oap\":%.1f,\"ca\":%.1f,\"cap\":%.1f,\"ia\":%.1f,\"iap\":%.1f,\"ba\":%.1f,\"bap\":%.1f,\"da\":%.1f,\"dap\":%.1f,\"op\":%.1f,\"opp\":%.1f,\"cp\":%.1f,\"cpp\":%.1f}", \
j,ownerraw,ownerp,claimedraw,claimedp,unclaimedraw,100-ownerp-claimedp-backfillp-drainedp,backfillraw,backfillp,drainedraw,drainedp,archrawpeakowner[j],archpeakowner[j],archrawpeakclaimed[j],archpeakclaimed[j])
}
j_chartControls = "\"chartControls\":\"<div id=\\\"controlsLeft\\\">Display series as:<form id=\\\"form_series_display\\\"><input type=\\\"radio\\\" name=\\\"stacked\\\" id=\\\"rbs_yes\\\" value=\\\"Stacked\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"rbs_yes\\\" id=\\\"lbl_stacked\\\" class=\\\"rb_label\\\">Stacked</label><input type=\\\"radio\\\" name=\\\"stacked\\\" id=\\\"rbs_no\\\" value=\\\"Unstacked\\\" onclick=\\\"chartM.updateChart()\\\"/><label for=\\\"rbs_no\\\" id=\\\"lbl_unstacked\\\" class=\\\"rb_label\\\">Unstacked</label></form></div><div id=\\\"controlsRight\\\">Series:<form id=\\\"form_series\\\"><input type=\\\"checkbox\\\" name=\\\"to\\\" id=\\\"cb_owner\\\" value=\\\"owner\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"cb_owner\\\" class=\\\"checkbox\\\" id=\\\"lbl_owner\\\">Total Owner</label><input type=\\\"checkbox\\\" name=\\\"to\\\" id=\\\"cb_idle\\\" value=\\\"idle\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"cb_idle\\\" class=\\\"checkbox\\\" id=\\\"lbl_idle\\\">Total Idle</label><input type=\\\"checkbox\\\" name=\\\"to\\\" id=\\\"cb_condor\\\" value=\\\"condor\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"cb_condor\\\" class=\\\"checkbox\\\" id=\\\"lbl_condor\\\">Total Condor</label><input type=\\\"checkbox\\\" name=\\\"to\\\" id=\\\"cb_backfill\\\" value=\\\"backfill\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"cb_backfill\\\" class=\\\"checkbox\\\" id=\\\"lbl_backfill\\\">Total Backfill</label><input type=\\\"checkbox\\\" name=\\\"to\\\" id=\\\"cb_drained\\\" value=\\\"drained\\\" checked onclick=\\\"chartM.updateChart()\\\" /><label for=\\\"cb_drained\\\" class=\\\"checkbox\\\" id=\\\"lbl_drained\\\">Total Drained</label></form></div>\""
j_table = "\"table\":\"<table cellspacing=\\\"0\\\" cellpadding=\\\"0\\\"><thead><tr><td>Arch</td><td>Owner Average</td><td>Condor Average</td><td>Idle Average</td><td>Backfill Average</td><td>Drained Average</td><td>Owner Peak</td><td>Condor Peak</td></tr></thead>" table "<\\/table>\""
for (atime in alltimes) {
times[atime] = atime;
}
n = asort(times);
j_time = "\"time\":["
for (i = 1; i <= n; i++) {
j_time = j_time times[i] ","
}
j_time = substr(j_time, 0, length(j_time)-1)
j_time = j_time "]"
j_arch = "\"arch\":{"
for (i = 0; i < numarch; i++) {
if ( archavetot[archnames[i]] > 0 ) {
j_arch = j_arch "\"" archnames[i] "\":{\"series\":["
j_owner = "{\"uid\":\"" archnames[i] "_o\",\"name\":\"Total Owner\",\"data\":["
j_idle = "{\"uid\":\"" archnames[i] "_i\",\"name\":\"Total Idle\",\"data\":["
j_condor = "{\"uid\":\"" archnames[i] "_c\",\"name\":\"Total Condor\",\"data\":["
j_backfill = "{\"uid\":\"" archnames[i] "_b\",\"name\":\"Total Backfill\",\"data\":["
j_drained = "{\"uid\":\"" archnames[i] "_d\",\"name\":\"Total Drained\",\"data\":["
for (j = 1; j<=n; j++) {
if(archnames[i] SEP times[j] in archdata_owner)
j_owner = j_owner archdata_owner[archnames[i] SEP times[j]] ","
else
j_owner = "null,"
if(archnames[i] SEP times[j] in archdata_idle)
j_idle = j_idle archdata_idle[archnames[i] SEP times[j]] ","
else
j_idle = "null,"
if(archnames[i] SEP times[j] in archdata_condor)
j_condor = j_condor archdata_condor[archnames[i] SEP times[j]] ","
else
j_condor = "null,"
if(archnames[i] SEP times[j] in archdata_backfill)
j_backfill = j_backfill archdata_backfill[archnames[i] SEP times[j]] ","
else
j_backfill = "null,"
if(archnames[i] SEP times[j] in archdata_drained)
j_drained = j_drained archdata_drained[archnames[i] SEP times[j]] ","
else
j_drained = "null,"
}
j_owner = substr(j_owner, 0, length(j_owner)-1) "]}"
j_idle = substr(j_idle, 0, length(j_idle)-1) "]}"
j_condor = substr(j_condor, 0, length(j_condor)-1) "]}"
j_backfill = substr(j_backfill, 0, length(j_backfill)-1) "]}"
j_drained = substr(j_drained, 0, length(j_drained)-1) "]}"
j_arch = j_arch j_owner "," j_idle "," j_condor "," j_backfill "," j_drained "]," j_misc[i]
j_arch = j_arch "},"
}
}
j_arch = substr(j_arch, 0, length(j_arch)-1)
j_arch = j_arch "}"
j_statTime = "\"statTime\":" statTime
json = "{" j_statTime "," j_time "," j_arch "," j_chartControls "," j_table "}"
printf"%s",json
}' - >> $1.$$
rm -f /tmp/cvw.$$
DATAFOLDER=./data/machine/
mv -f $DATAFOLDER$FILENAME*.data $DATAFOLDER$FILENAME.data.old 1> /dev/null 2>&1
mv -f $1.$$ $DATAFOLDER$DATAFILENAME.data
chmod 644 $DATAFOLDER$DATAFILENAME.data