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