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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2417 - (show annotations) (download)
Mon Aug 15 11:24:12 2011 UTC (11 years ago) by templon
File size: 6808 byte(s)
update RRA defs in comments

1 #! /usr/bin/env python
2 # $Id$
3 # Source: $URL$
4 # J. A. Templon, NIKHEF/PDP 2011
5
6 debug = 0
7
8 import os
9
10 NUMGROUPS=8
11 DATADIR=os.environ['HOME'] + '/ndpfdata/'
12 PLOTDIR=os.environ['HOME'] + '/public_html/'
13 # 8 class qualitative paired color scheme
14
15 colors = [ "#A6CEE3", "#1F77B4", "#B2DF8A", "#33A02C",
16 "#FB9A99", "#E31A1C", "#FDBF6F", "#FF7F00" ]
17
18 colors.reverse()
19
20 # for reference : resolutions of the RRAs
21 # base step size 60 sec
22 # step 1 : 60 sec x 1600 points : 1600 min : 26,67 hr : 1.11 days
23 # step 2 : 120 sec x 1200 points : 2400 min : 40 hr : 1,67 days
24 # step 10 : 600 sec x 1800 points : 18 000 min : 300 hr : 12,5 days
25 # step 30 : 1800 sec x 2500 points : 75 000 min : 1250 hr : 52.08 days
26 # step 120 : 7200 sec x 1000 points : 120 000 min : 2000 hr : 83.33 days
27 # step 480 : 28800 sec x 1000 points : 480 000 min : 8000 hr : 333.33 days
28 # step 1440 : 86400 sec x 3650 points : 3650 days : 10 years
29
30 plotrangedef = {
31 'hr' : { 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
32 'timetag' : 'hr',
33 'avrange' : 24*3600,
34 'avres' : 60,
35 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
36 '--x-grid',
37 'MINUTE:20:HOUR:1:HOUR:1:0:%H:00'
38 ],
39 'large' : [ '--width', '800', '--height', '500' ]
40 },
41 },
42 'day' : { 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
43 'timetag' : 'day',
44 'avrange' : 24*3600,
45 'avres' : 60,
46 'sizeargs' : { 'small' : [ '--width', '200', '--height', '125',
47 '--x-grid',
48 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00'
49 ],
50 'large' : [ '--width', '1000', '--height', '625' ]
51 },
52 },
53 'week' : { 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
54 'timetag' : 'week',
55 'avrange' : 7*24*3600,
56 'avres' : 600,
57 'sizeargs' : { 'small' : [ '--width', '576', '--height', '125' ],
58 'large' : [ '--width', '1728', '--height', '375',
59 '-n', 'DEFAULT:16:']
60 },
61 },
62
63 'month' : { 'timeargs' : [ '-s', 'n-35days', '-e', 'n'],
64 'timetag' : 'month',
65 'avrange' : 31*24*3600,
66 'avres' : 1800,
67 'sizeargs' : { 'small' : [ '--width', '576', '--height', '105',
68 '--step', '7200'],
69 'large' : [ '--width', '2304', '--height', '420',
70 '-n', 'DEFAULT:18:',
71 '--x-grid',
72 'HOUR:12:DAY:1:DAY:3:86400:%d-%b'
73 ]
74 },
75 },
76 }
77
78 commonargs = ['--imgformat', 'PNG',
79 '--legend-position=east', '--legend-direction=bottomup']
80
81 import rrdtool
82 import time
83 import glob
84
85 ### function definitions
86
87 def doplot(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
88
89 defs = list()
90 plots = list()
91
92 data_defs = list()
93 plot_defs = list()
94
95 for group in (grouplist + ['total']):
96 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
97
98 for idx in range(len(grouplist)):
99 group = grouplist[idx]
100 pdefstr = 'AREA' ':' + group + colors[idx] + ':' + group
101 pdefstr = pdefstr + '\\n'
102 if idx > 0:
103 pdefstr = pdefstr + ':STACK'
104 plot_defs.append(pdefstr)
105
106 plot_defs.append('LINE:total#000000:total')
107
108 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
109 commonargs + ['-l', '0'] + sizeargs[psize] + timeargs + \
110 data_defs + plot_defs
111 rrdtool.graph( *pargs )
112
113 def doplot_wait(grouplist, dbtype, psize, timetag, sizeargs, timeargs):
114
115 defs = list()
116 plots = list()
117
118 data_defs = list()
119 plot_defs = list()
120
121 for group in (grouplist + ['rollover']):
122 data_defs.append('DEF:'+group+'='+DATADIR+group+'.'+dbtype+'.rrd:'+dbtype+':AVERAGE')
123
124 for idx in range(len(grouplist)):
125 group = grouplist[idx]
126 pdefstr = 'LINE3' ':' + group + colors[idx] + ':' + group
127 pdefstr = pdefstr + '\\n'
128 plot_defs.append(pdefstr)
129
130 plot_defs.append('LINE2:rollover#000000:rollover')
131
132 pargs = [ PLOTDIR + dbtype + '-' + timetag + '-' + psize + '.png'] + \
133 ['--slope-mode', '-o'] + \
134 commonargs + sizeargs[psize] + timeargs + \
135 data_defs + plot_defs
136 rrdtool.graph( *pargs )
137
138 def makeplots(prangedef):
139
140 resolu = prangedef['avres']
141
142 # first need to find "top eight" list
143 # base it on running jobs
144
145 now=int(time.mktime(time.localtime()))
146 end = (now / resolu) * resolu
147 start = end - (prangedef['avrange']) + resolu
148
149 ### block finding 'top N' group list ###
150
151 tgroup = dict() # structure tgroup[groupname] = total of hourly average
152
153 running_files = glob.glob(DATADIR+'*.running.rrd')
154 for db in running_files:
155 group = db[len(DATADIR):db.find('.running.rrd')]
156 if group == "total":
157 continue
158 tup = rrdtool.fetch(db,'AVERAGE','-r', repr(resolu),
159 '-s', repr(start), '-e', repr(end))
160 vallist = [0] # start with zero, in case no vals returned, get zero as answer
161 for tup2 in tup[2]:
162 val = tup2[0]
163 if val:
164 vallist.append(val)
165 tgroup[group] = sum(vallist)
166
167 groups_sorted = sorted(tgroup, key=tgroup.get, reverse=False)
168 topgroups=groups_sorted[-NUMGROUPS:]
169
170 if debug:
171 print prangedef['timetag']
172 for g in groups_sorted:
173 print "%10s %12d" % (g, tgroup[g])
174
175 ### end block 'top N' group list ###
176
177 ### block generating plots ###
178
179 for dbtype in ['queued', 'running', 'waittime']:
180 for psize in ['small', 'large']:
181 if dbtype == 'waittime':
182 doplot_wait(topgroups, dbtype, psize, prangedef['timetag'],
183 prangedef['sizeargs'],
184 prangedef['timeargs'],
185 )
186 else:
187 doplot(topgroups, dbtype, psize, prangedef['timetag'],
188 prangedef['sizeargs'],
189 prangedef['timeargs']
190 )
191
192 for k in plotrangedef.keys():
193 makeplots(plotrangedef[k])
194
195 import sys
196 sys.exit(0)

Properties

Name Value
svn:executable *
svn:keywords Id URL

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