/[pdpsoft]/nl.nikhef.ndpf.groupviews/trunk/ndpf_gv_plots_common.py
ViewVC logotype

Contents of /nl.nikhef.ndpf.groupviews/trunk/ndpf_gv_plots_common.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3328 - (show annotations) (download) (as text)
Tue Mar 30 09:03:58 2021 UTC (15 months, 1 week ago) by templon
File MIME type: application/x-python
File size: 8666 byte(s)
various commits


1 # std groupviews colors
2
3 colors = { 'lightblue' : "#A6CEE3", 'darkblue' : "#1F77B4",
4 'lightgreen' : "#B2DF8A", 'darkgreen' : "#33A02C",
5 'lightred' : "#FB9A99", 'darkred' : "#E31A1C",
6 'lightorange' : "#FDBF6F", 'darkorange' : "#FF7F00",
7 'stdgray' : "#d8d8d8", 'purple' : "#790EAD",
8 'black' : "#000000" }
9
10 colormap = { 0 : 'darkorange',
11 1 : 'lightorange',
12 2 : 'darkred',
13 3 : 'lightred',
14 4 : 'darkgreen',
15 5 : 'lightgreen',
16 6 : 'darkblue',
17 7 : 'lightblue'
18 }
19
20 # for reference : ranges 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 # resolutions of RRAs
31
32 # 1 : 60 sec : 1 min
33 # 2 : 120 sec : 2 min
34 # 3 : 600 sec : 10 min
35 # 4 : 1 800 sec : 30 min
36 # 5 : 7 200 sec : 120 min : 2 hr
37 # 6 : 28 800 sec : 480 min : 8 hr
38 # 7 : 86 400 sec : 1440 min : 24 hr : 1 day
39
40 NUMQS = 27 # number of quarters for "alltime" plot
41
42 pdefs = {
43 'hour' : {
44 'range' : 24*3600,
45 'res' : 60,
46 'timeargs' : [ '-s', 'n-200min', '-e', 'n' ],
47 'small' : {
48 'width' : 200,
49 'height' : 125,
50 'opts' : ['--x-grid', 'MINUTE:20:HOUR:1:HOUR:1:0:%H:00' ]
51 },
52 'large' : {
53 'width' : 800,
54 'height' : 500,
55 'opts' : [ ],
56 },
57 },
58 'day' : {
59 'range' : 24*3600,
60 'res' : 60,
61 'timeargs' : [ '-s', 'n-2000min', '-e', 'n' ],
62 'small' : {
63 'width' : 200,
64 'height' : 125,
65 'opts' : ['--x-grid', 'HOUR:6:DAY:1:HOUR:12:0:%a %H:00' ]
66 },
67 'large' : {
68 'width' : 1000,
69 'height' : 625,
70 'opts' : [ ],
71 },
72 },
73
74 'week' : {
75 'range' : 7*24*3600,
76 'res' : 600,
77 'timeargs' : [ '-s', 'n-288hr', '-e', 'n' ],
78 'small' : {
79 'width' : 576,
80 'height' : 125,
81 'opts' : [ ]
82 },
83 'large' : {
84 'width' : 1728,
85 'height' : 375,
86 'opts' : ['-n', 'DEFAULT:16' ],
87 },
88 },
89
90 'month' : {
91 ## # note the construction "repr(576*n)" here --- this is because the plot is
92 ## # (a multiple of) 576 pixels, and 120 min is one of the RRAs, so choosing
93 ## # a lower limit of 576*120 gives us a plot with one pixel per RRA bin.
94 'range' : 31*24*3600,
95 'res' : 1800,
96 'timeargs' : [ '-s', 'n-'+repr(576*120)+'min', '-e', 'n'],
97 'small' : {
98 'width' : 576,
99 'height' : 105,
100 'opts' : [ ]
101 },
102 'large' : {
103 'width' : 2304,
104 'height' : 420,
105 'opts' : [ '-n', 'DEFAULT:18:', '--x-grid',
106 'HOUR:12:DAY:1:DAY:3:86400:%d-%b' ]
107 },
108 },
109 'year' : {
110 'range' : 365*24*3600,
111 'res' : 86400,
112 'timeargs' : [ '-s', 'n-'+repr(576*1440)+'min', '-e', 'n'],
113 'small' : {
114 'width' : 576,
115 'height' : 105,
116 'opts' : [ ]
117 },
118 'large' : {
119 'width' : 2304,
120 'height' : 420,
121 'opts' : [ ],
122 },
123 },
124
125 ## # adjusting for nice plot ... now 12/4 of a year
126
127 'alltime' : {
128 'range' : NUMQS*365*24*3600/4,
129 'res' : 86400,
130 'timeargs' : [ '-s', 'n-'+repr(NUMQS*365*1440/4)+'min', '-e', 'n'],
131 'small' : {
132 'width' : 576,
133 'height' : 105,
134 'opts' : ['--x-grid', 'MONTH:3:YEAR:1:YEAR:1:31536000:%Y' ]
135 },
136 'large' : {
137 'width' : 2304,
138 'height' : 420,
139 'opts' : [ '--x-grid', 'MONTH:1:YEAR:1:MONTH:3:2592000:%b-%Y']
140 }
141 }
142 }
143
144 import rrdtool
145 import time
146
147 ### function definitions
148
149 def getfracs(groupsdict, totaldb, range, resolu):
150
151 now=int(time.mktime(time.localtime()))
152 end = (now / resolu) * resolu
153 start = end - range + resolu # adding resolu avoids worry about off by one?
154 # first do total capacity (need for dividing into each component result)
155
156 tup = rrdtool.fetch(totaldb[1],'AVERAGE','-r', repr(resolu),
157 '-s', repr(start), '-e', repr(end))
158 vallist = [0] # start with zero, in case no vals returned, get zero as answer
159 for tup2 in tup[2]:
160 val = tup2[0]
161 if val:
162 vallist.append(val)
163
164 # put numbers in meaningful units now. after summing vallist,
165 # result is an
166 # sum over the time range, of data averages over "resolu"
167 # ... native resolution is in minutes, so multiplying by
168 # (resolu / 60) puts the answer in core-minutes; dividing by
169 # the number of minutes in the range gives the average number
170 # of cores occupied, over the range
171
172 totval = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
173
174 ### now find same for each component
175
176 tgroup = dict() # structure tgroup[groupname] = averages over interval
177
178 for group in groupsdict:
179 tup = rrdtool.fetch(groupsdict[group][1],'AVERAGE','-r', repr(resolu),
180 '-s', repr(start), '-e', repr(end))
181 vallist = [0] # start with zero, in case no vals returned, get zero as answer
182 for tup2 in tup[2]:
183 val = tup2[0]
184 if val:
185 vallist.append(val)
186
187 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
188
189 pgroup = dict() # percentages over interval
190 if totval == 0.0 : return
191 for g in tgroup.keys():
192 pgroup[g] = 100*tgroup[g]/totval
193
194 return (tgroup, pgroup)
195
196 def getqueued(groupsdict, range, resolu):
197
198 now=int(time.mktime(time.localtime()))
199 end = (now / resolu) * resolu
200 start = end - range + resolu # adding resolu avoids worry about off by one?
201
202 tgroup = dict() # structure tgroup[groupname] = averages over interval
203
204 for group in groupsdict:
205 tup = rrdtool.fetch(groupsdict[group][1],'AVERAGE','-r', repr(resolu),
206 '-s', repr(start), '-e', repr(end))
207 vallist = [0] # start with zero, in case no vals returned, get zero as answer
208 for tup2 in tup[2]:
209 val = tup2[0]
210 if val:
211 vallist.append(val)
212
213 # put numbers in meaningful units now. after summing vallist,
214 # result is an
215 # sum over the time range, of data averages over "resolu"
216 # ... native resolution is in minutes, so multiplying by
217 # (resolu / 60) puts the answer in core-minutes; dividing by
218 # the number of minutes in the range gives the average number
219 # of cores occupied, over the range
220
221 tgroup[group] = sum(vallist) * (resolu / 60) / ( (end-start) / 60. )
222
223 return tgroup
224
225 class Plot:
226 def __init__(self):
227 self.bands = list()
228 self.lines = None # optional
229 self.labels = None # optional
230 self.colors = list()
231 self.datafile = dict()
232 self.size = None
233 self.opts = None
234 self.range = None
235 def generate(self, file=None):
236 data_defs = list()
237 for group in self.bands + self.lines:
238 data_defs.append('DEF:%s=%s:%s:AVERAGE' % (group, self.datafile[group][1], self.datafile[group][0]))
239
240 plot_defs = list()
241 if not self.labels:
242 self.labels = dict()
243 for g in self.bands + self.lines:
244 self.labels[g] = g
245 for g in self.bands:
246 plot_defs.append('AREA:%s%s:%s\\n:STACK' % (g, self.colors[g], self.labels[g]))
247 for g in self.lines:
248 plot_defs.append('LINE:%s%s:%s\\n' % (g, self.colors[g], self.labels[g]))
249
250 dbtype = 'run'
251 timetag = 'tst'
252 ranktype = 'tstrank'
253 psize = 'tstp'
254 pargs = [ self.plotfile ] + \
255 ['--imgformat', 'PNG', '--legend-position=east', \
256 '--legend-direction=bottomup', '-l', '0'] + \
257 ['--width', str(self.width), '--height', str(self.height) ] + \
258 self.opts + self.timeargs + [data_defs + plot_defs]
259
260
261 rrdtool.graph( *pargs )

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