/[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 2402 - (show annotations) (download)
Tue Aug 9 11:58:55 2011 UTC (10 years, 10 months ago) by templon
File size: 5739 byte(s)
delete old unused code.

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

Properties

Name Value
svn:executable *
svn:keywords Id URL

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