/[pdpsoft]/nl.nikhef.ndpf.groupviews/branches/RB-2.1.1/ndpf-gv-mkplots
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/branches/RB-2.1.1/ndpf-gv-mkplots

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2438 - (show annotations) (download)
Thu Sep 29 20:51:31 2011 UTC (10 years, 8 months ago) by templon
File size: 8721 byte(s)
temp change (will be awhile before a year is relevant).

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 'month' : { 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
87 'timetag' : 'month',
88 'avrange' : 31*24*3600,
89 'avres' : 1800,
90 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
91 'large' : [ '--width', '2304', '--height', '420',
92 '-n', 'DEFAULT:18:',
93 '--x-grid',
94 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
95 ]
96 },
97 },
98
99 'year' : { 'timeargs' : [ '-s', 'n-'+repr((576/4)*1440)+'min', '-e', 'n'],
100 'timetag' : 'year',
101 'avrange' : 365*24*3600,
102 'avres' : 86400,
103 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105'],
104 'large' : [ '--width', '2304', '--height', '420']
105 },
106 },
107 }
108
109 commonargs = ['--imgformat', 'PNG',
110 '--legend-position=east', '--legend-direction=bottomup']
111
112 import rrdtool
113 import time
114 import glob
115
116 ### function definitions
117
118 def doplot(grouplist, dbtype, psize, timetag, sizeargs, timeargs, pcents):
119
120 defs = list()
121 plots = list()
122
123 data_defs = list()
124 plot_defs = list()
125
126 for group in (grouplist + ['total']):
127 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
128
129 for idx in range(len(grouplist)):
130 group = grouplist[idx]
131 pdefstr = 'AREA' ':' + group + colors[idx] + ':' + group
132 if pcents:
133 pdefstr = pdefstr + ' (' + "%4.1f" % (pcents[group]) + ')'
134 pdefstr = pdefstr + '\\n'
135 if idx > 0:
136 pdefstr = pdefstr + ':STACK'
137 plot_defs.append(pdefstr)
138
139 plot_defs.append('LINE:total#000000:total')
140
141 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
142 commonargs + ['-l', '0'] + sizeargs[psize] + timeargs + \
143 data_defs + plot_defs
144 rrdtool.graph( *pargs )
145
146 def doplot_wait(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
147
148 defs = list()
149 plots = list()
150
151 data_defs = list()
152 plot_defs = list()
153
154 for group in (grouplist + ['rollover']):
155 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
156
157 for idx in range(len(grouplist)):
158 group = grouplist[idx]
159 pdefstr = 'LINE3' ':' + group + colors[idx] + ':' + group
160 pdefstr = pdefstr + '\\n'
161 plot_defs.append(pdefstr)
162
163 plot_defs.append('LINE2:rollover#000000:rollover')
164
165 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
166 ['--slope-mode', '-o'] + \
167 commonargs + sizeargs[psize] + timeargs + \
168 data_defs + plot_defs
169 rrdtool.graph( *pargs )
170
171 def makeplots(prangedef):
172
173 resolu = prangedef['avres']
174
175 # first need to find "top eight" list
176 # base it on running jobs
177
178 now=int(time.mktime(time.localtime()))
179 end = (now / resolu) * resolu
180 start = end - (prangedef['avrange']) + resolu
181
182 ### block finding 'top N' group list ###
183
184 tgroup = dict() # structure tgroup[groupname] = total of hourly average
185
186 running_files = glob.glob(DATADIR+'*.running.rrd')
187 for db in running_files:
188 group = db[len(DATADIR):db.find('.running.rrd')]
189 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
190 '-s', repr(start), '-e', repr(end))
191 vallist = [0] # start with zero, in case no vals returned, get zero as answer
192 for tup2 in tup[2]:
193 val = tup2[0]
194 if val:
195 vallist.append(val)
196 if group == "total":
197 totval = sum(vallist)
198 else:
199 tgroup[group] = sum(vallist)
200
201 pgroup = dict()
202 for g in tgroup.keys():
203 pgroup[g] = 100*tgroup[g]/totval
204
205 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False)
206 topgroups=groups_sorted[-NUMGROUPS:]
207
208 if opts.rankonly:
209 print "Ranks for", prangedef['timetag'], " resolution is", resolu
210 for g in reversed(groups_sorted):
211 if tgroup[g] > 0:
212 print "%10s %12d" % (g, tgroup[g])
213 return
214
215 ### end block 'top N' group list ###
216
217 ### block generating plots ###
218
219
220 for dbtype in ['queued', 'running', 'waittime']:
221
222 ### this is a bit of a hack : we only want pgroups for when it's
223 ### a 'running' database and we don't want it for timetag hour.
224 ### fix this up here
225
226 if dbtype == 'running' and prangedef['timetag'] != 'hr':
227 percents = pgroup
228 else:
229 percents = None
230 for psize in ['small', 'large']:
231 if dbtype == 'waittime':
232 doplot_wait(topgroups, dbtype, psize, prangedef['timetag'],
233 prangedef['sizeargs'],
234 prangedef['timeargs'],
235 )
236 else:
237 doplot(topgroups, dbtype, psize, prangedef['timetag'],
238 prangedef['sizeargs'],
239 prangedef['timeargs'],
240 percents
241 )
242
243 for k in plotrangedef.keys():
244 makeplots(plotrangedef[k])
245
246 import sys
247 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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