/[pdpsoft]/nl.nikhef.ndpf.groupviews/trunk/ndpf-gv-mkplots
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/trunk/ndpf-gv-mkplots

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2623 - (show annotations) (download)
Wed May 22 14:50:02 2013 UTC (8 years, 8 months ago) by templon
File size: 11673 byte(s)
make changes to have sections on the plot (and associated colors)
for "unused" capacity, "offline" capacity, and "other" jobs not
represented in the top 8 groups.

1 #! /usr/bin/env python
2 # $Id$
3 # Source: $URL$
4 # J. A. Templon, NIKHEF/PDP 2011
5
6 import optparse
7
8 p = optparse.OptionParser(description="Program to make rrdtool plots " + \
9 "of job running jobs by unix group")
10
11 # p.add_option("-r",action="store",dest="minsize",default='0',help="minimum size of dirs considered; can use suffixes k,M,G for multiples of 1000**{1,2,3} bytes")
12 # p.add_option("--qdel",action="store_true",dest="deljobs",help="delete jobs for which TMPDIR is larger than MINSIZE",default=False)
13
14 p.add_option("--rank-only",action="store_true",dest="rankonly",
15 help="don't plot, just print ranking of groups",default=False)
16
17 debug = 0
18
19 opts, args = p.parse_args()
20
21 import os
22
23 NUMGROUPS=8
24 DATADIR=os.environ['HOME'] + '/ndpfdata/'
25 PLOTDIR=os.environ['HOME'] + '/public_html/'
26 # 8 class qualitative paired color scheme
27
28 colors = [ "#A6CEE3", "#1F77B4", "#B2DF8A", "#33A02C",
29 "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00" ]
30
31 colors.reverse()
32
33 # for reference : ranges of the RRAs
34 # base step size 60 sec
35 # step 1 : 60 sec x 1600 points : 1600 min : 26,67 hr : 1.11 days
36 # step 2 : 120 sec x 1200 points : 2400 min : 40 hr : 1,67 days
37 # step 10 : 600 sec x 1800 points : 18 000 min : 300 hr : 12,5 days
38 # step 30 : 1800 sec x 2500 points : 75 000 min : 1250 hr : 52.08 days
39 # step 120 : 7200 sec x 1000 points : 120 000 min : 2000 hr : 83.33 days
40 # step 480 : 28800 sec x 1000 points : 480 000 min : 8000 hr : 333.33 days
41 # step 1440 : 86400 sec x 3650 points : 3650 days : 10 years
42
43 # resolutions of RRAs
44
45 # 1 : 60 sec : 1 min
46 # 2 : 120 sec : 2 min
47 # 3 : 600 sec : 10 min
48 # 4 : 1 800 sec : 30 min
49 # 5 : 7 200 sec : 120 min : 2 hr
50 # 6 : 28 800 sec : 480 min : 8 hr
51 # 7 : 86 400 sec : 1440 min : 24 hr : 1 day
52
53 plotrangedef = {
54 'hr' : { 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
55 'timetag' : 'hr',
56 'avrange' : 24*3600,
57 'avres' : 60,
58 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
59 '--x-grid',
60 'MINUTE:20:HOUR:1:HOUR:1:0:%H:00'
61 ],
62 'large' : [ '--width', '800', '--height', '500' ]
63 },
64 },
65 'day' : { 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
66 'timetag' : 'day',
67 'avrange' : 24*3600,
68 'avres' : 60,
69 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
70 '--x-grid',
71 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00'
72 ],
73 'large' : [ '--width', '1000', '--height', '625' ]
74 },
75 },
76 'week' : { 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
77 'timetag' : 'week',
78 'avrange' : 7*24*3600,
79 'avres' : 600,
80 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
81 'large' : [ '--width', '1728', '--height', '375',
82 '-n', 'DEFAULT:16:']
83 },
84 },
85
86 # note the construction "repr(576*n)" here --- this is because the plot is
87 # (a multiple of) 576 pixels, and 120 min is one of the RRAs, so choosing
88 # a lower limit of 576*120 gives us a plot with one pixel per RRA bin.
89
90 'month' : { 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
91 'timetag' : 'month',
92 'avrange' : 31*24*3600,
93 'avres' : 1800,
94 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
95 'large' : [ '--width', '2304', '--height', '420',
96 '-n', 'DEFAULT:18:',
97 '--x-grid',
98 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
99 ]
100 },
101 },
102
103 'year' : { 'timeargs' : [ '-s', 'n-'+repr(576*1440)+'min', '-e', 'n'],
104 'timetag' : 'year',
105 'avrange' : 365*24*3600,
106 'avres' : 86400,
107 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
108 'large' : [ '--width', '2304', '--height', '420']
109 },
110 },
111
112 'alltime' : { 'timeargs' : [ '-s', 'n-'+repr(2*365*1440)+'min', '-e', 'n'],
113 'timetag' : 'alltime',
114 'avrange' : 2*365*24*3600,
115 'avres' : 86400,
116 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105',
117 '--x-grid',
118 'MONTH:3:YEAR:1:YEAR:1:31536000:%Y'
119 ],
120 'large' : [ '--width', '2304', '--height', '420',
121 '--x-grid',
122 'MONTH:1:YEAR:1:MONTH:3:2592000:%b-%Y'
123 ]
124 },
125 },
126
127
128 }
129
130 commonargs = ['--imgformat', 'PNG',
131 '--legend-position=east', '--legend-direction=bottomup']
132
133 import rrdtool
134 import time
135 import glob
136
137 ### function definitions
138
139 def doplot(grouplist, dbtype, psize, timetag, sizeargs, timeargs, pcents):
140
141 defs = list()
142 plots = list()
143
144 data_defs = list()
145 plot_defs = list()
146
147 for group in (grouplist + ['total']):
148 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
149 otherstring = 'CDEF:other=total,'
150 for group in grouplist:
151 otherstring += group + ','
152 otherstring += (len(grouplist)-1) * '+,' + '-'
153
154 # print otherstring
155 data_defs.append(otherstring)
156
157 sumshown = 0
158 for idx in range(len(grouplist)):
159 group = grouplist[idx]
160 if group == 'unused':
161 acolor = '#858885'
162 elif group == "offline":
163 acolor = "#790ead"
164 else:
165 acolor = colors[idx]
166 pdefstr = 'AREA' ':' + group + acolor + ':' + group
167 if pcents:
168 pdefstr = pdefstr + ' (' + "%4.1f" % (pcents[group]) + ')'
169 sumshown += float(pcents[group])
170 pdefstr = pdefstr + '\\n'
171 pdefstr = pdefstr + ':STACK'
172 plot_defs.append(pdefstr)
173
174 pdefstr = 'AREA' ':' + 'other' + '#794044' + ':' + 'other'
175 if pcents:
176 pdefstr = pdefstr + ' (' + "%4.1f" % (100 - sumshown) + ')'
177 pdefstr = pdefstr + '\\n'
178 # pdefstr = pdefstr + ':STACK'
179
180 plot_defs.insert(0,pdefstr)
181 # if pcents:
182 # plot_defs.append("LINE:total#000000:total (+%2.1f)" % (100 - sumshown))
183 # else:
184 plot_defs.append("LINE:total#000000") # :total")
185
186 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
187 commonargs + ['-l', '0'] + sizeargs[psize] + timeargs + \
188 data_defs + plot_defs
189 rrdtool.graph( *pargs )
190
191 def doplot_wait(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
192
193 defs = list()
194 plots = list()
195
196 data_defs = list()
197 plot_defs = list()
198
199 for group in (grouplist + ['rollover','lastroll']):
200 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
201
202 for idx in range(len(grouplist)):
203 group = grouplist[idx]
204 if group == 'unused':
205 acolor = '#858885'
206 elif group == "offline":
207 acolor = "#790ead"
208 else:
209 acolor = colors[idx]
210 pdefstr = 'LINE3' ':' + group + acolor + ':' + group
211 pdefstr = pdefstr + '\\n'
212 plot_defs.append(pdefstr)
213
214 plot_defs.append('LINE2:rollover#660198')
215 plot_defs.append('LINE2:lastroll#000000')
216
217 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
218 ['--slope-mode', '-o'] + \
219 commonargs + sizeargs[psize] + timeargs + \
220 data_defs + plot_defs
221 rrdtool.graph( *pargs )
222
223 def makeplots(prangedef):
224
225 resolu = prangedef['avres']
226
227 # first need to find "top eight" list
228 # base it on running jobs
229
230 now=int(time.mktime(time.localtime()))
231 end = (now / resolu) * resolu
232 start = end - (prangedef['avrange']) + resolu
233
234 ### block finding 'top N' group list ###
235
236 tgroup = dict() # structure tgroup[groupname] = total of hourly average
237
238 running_files = glob.glob(DATADIR+'*.running.rrd')
239 for db in running_files:
240 group = db[len(DATADIR):db.find('.running.rrd')]
241 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
242 '-s', repr(start), '-e', repr(end))
243 vallist = [0] # start with zero, in case no vals returned, get zero as answer
244 for tup2 in tup[2]:
245 val = tup2[0]
246 if val:
247 vallist.append(val)
248
249 # put numbers in meaningful units now. result returned is an integration over the time range, of
250 # averages over "resolu" ... native resolution is in minutes, so multiplying by (resolu / 60)
251 # puts the answer in core-minutes; dividing by the number of minutes in the range gives the
252 # average number of cores occupied, over the range
253
254 if group == "total":
255 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
256 else:
257 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
258
259 pgroup = dict()
260 for g in tgroup.keys():
261 pgroup[g] = 100*tgroup[g]/totval
262
263 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False)
264 topgroups=groups_sorted[-NUMGROUPS:]
265 if 'unused' in topgroups:
266 topgroups.remove('unused')
267 topgroups.append('unused') # makes it always appear at top of plot (except see offline)
268 if 'offline' in topgroups:
269 topgroups.remove('offline')
270 topgroups.append('offline') # makes it always appear at top of plot
271
272 if opts.rankonly and prangedef['timetag'] != 'hr' :
273 print "Ranked average running jobs over period", prangedef['timetag']
274 print "%10s %12d" % ('total', totval)
275 rank = 0
276 for g in reversed(groups_sorted):
277 if tgroup[g] > 0:
278 rank += 1
279 print "%2d. %10s %9.4f %9.4f%%" % (rank, g, tgroup[g], pgroup[g])
280 return
281
282 ### end block 'top N' group list ###
283
284 ### block generating plots ###
285
286
287 for dbtype in ['queued', 'running', 'waittime']:
288
289 ### this is a bit of a hack : we only want pgroups for when it's
290 ### a 'running' database and we don't want it for timetag hour.
291 ### fix this up here
292
293 if dbtype == 'running' and prangedef['timetag'] != 'hr':
294 percents = pgroup
295 else:
296 percents = None
297 for psize in ['small', 'large']:
298 if dbtype == 'waittime':
299 doplot_wait(topgroups, dbtype, psize, prangedef['timetag'],
300 prangedef['sizeargs'],
301 prangedef['timeargs'],
302 )
303 else:
304 doplot(topgroups, dbtype, psize, prangedef['timetag'],
305 prangedef['sizeargs'],
306 prangedef['timeargs'],
307 percents
308 )
309
310 for k in ['hr', 'day', 'week', 'month', 'year', 'alltime']: # plotrangedef.keys():
311 makeplots(plotrangedef[k])
312
313 import sys
314 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28