1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""DPGraphPoint
15
16 Handles GraphPoints that refer to RRDDataPoints
17 """
18
19 import os
20 import os.path
21 from ComplexGraphPoint import ComplexGraphPoint
22 from Globals import InitializeClass
23
24
33
34
36 '''
37 '''
38 meta_type = 'DataPointGraphPoint'
39
40 limit = -1
41 rpn = ''
42 dpName = ''
43 cFunc = 'AVERAGE'
44
45
46
47
48
49
50
51
52
53
54
55 _properties = ComplexGraphPoint._properties + (
56 {'id':'limit', 'type':'long', 'mode':'w'},
57 {'id':'rpn', 'type':'string', 'mode':'w'},
58 {'id':'dpName', 'type':'string', 'mode':'w'},
59 {'id':'cFunc', 'type':'string', 'mode':'w'},
60 )
61
63 ''' return a description
64 '''
65 return self.dpName
66
67
69 '''
70 Return the id of the datapoint, without the datasource name
71 '''
72 return self.dpName.split('_', 1)[-1]
73
74
77
78
80 """
81 If this graphpoint's graph definition is associated with a perf
82 template and if the datapoint needed by this gp is not present in
83 the perf template then return True, otherwise false.
84 """
85 if self.graphDef.rrdTemplate():
86 if self.dpName \
87 not in self.graphDef.rrdTemplate.getRRDDataPointNames():
88 return True
89 return False
90
91
92 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx,
93 multiid=-1, prefix=''):
94 ''' Build the graphing commands for this graphpoint
95 '''
96 graph = []
97
98 rrdFile = os.path.join(rrdDir, self.dpName) + ".rrd"
99
100
101 rawName = self.getDsName('%s-raw' % self.id, multiid, prefix)
102 graph.append("DEF:%s=%s:%s:%s" % (rawName, rrdFile, 'ds0', self.cFunc))
103 graph.append("DEF:%s-max=%s:%s:%s" % (rawName, rrdFile, 'ds0', "MAX"))
104
105
106 if self.rpn:
107 rpn = self.talesEval(self.rpn, context)
108 rpnName = self.getDsName('%s-rpn' % self.id, multiid, prefix)
109 graph.append("CDEF:%s=%s,%s" % (rpnName, rawName, rpn))
110 graph.append("CDEF:%s-max=%s-max,%s" % (rpnName, rawName, rpn))
111
112
113 if self.limit > -1:
114 src = self.rpn and rpnName or rawName
115 limitName = self.getDsName('%s-limit' % self.id, multiid, prefix)
116 graph.append("CDEF:%s=%s,%s,GT,UNKN,%s,IF"%
117 (limitName,src,self.limit,src))
118 graph.append("CDEF:%s-max=%s-max,%s,GT,UNKN,%s,IF"%
119 (limitName,src,self.limit,src))
120
121 if self.limit > -1:
122 src = limitName
123 elif self.rpn:
124 src = rpnName
125 else:
126 src = rawName
127
128
129 graph.append('CDEF:%s=%s' %
130 (self.getDsName(self.id, multiid, prefix), src))
131
132
133 if self.lineType != self.LINETYPE_DONTDRAW:
134 if multiid != -1:
135 fname = os.path.basename(rrdDir)
136 if fname.find('.rrd') > -1: fname = fname[:-4]
137 legend = "%s-%s" % (self.id, fname)
138 else:
139 legend = self.talesEval(self.legend, context) or self.id
140 legend = self.escapeForRRD(legend)
141 drawType = self.lineType
142 if self.lineType == self.LINETYPE_LINE:
143 drawType += str(self.lineWidth)
144 drawCmd ='%s:%s%s' % (
145 drawType,
146 src,
147 self.getColor(idx))
148 drawCmd += ':%s' % legend.ljust(14)
149 if self.stacked:
150 drawCmd += ':STACK'
151 graph.append(drawCmd)
152
153
154 if addSummary:
155 graph.extend(self._summary(src, self.format, ongraph=1))
156
157 return cmds + graph
158
159
160 - def _summary(self, src, format="%5.2lf%s", ongraph=1):
161 """Add the standard summary opts to a graph"""
162 gopts = []
163 funcs = ("LAST", "AVERAGE", "MAX")
164 tags = ("cur\:", "avg\:", "max\:")
165 for i in range(len(funcs)):
166 label = "%s%s" % (tags[i], format or self.DEFAULT_FORMAT)
167 if funcs[i] == "MAX":
168 src += "-max"
169 gopts.append(self.summElement(src, funcs[i], label, ongraph))
170 gopts[-1] += "\j"
171 return gopts
172
173
174 - def summElement(self, src, function, format="%5.2lf%s", ongraph=1):
175 """Make a single summary element"""
176 if ongraph: opt = "GPRINT"
177 else: opt = "PRINT"
178 return ":".join((opt, src, function, format))
179
180
181 InitializeClass(DataPointGraphPoint)
182