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 _properties = ComplexGraphPoint._properties + (
46 {'id':'limit', 'type':'long', 'mode':'w'},
47 {'id':'rpn', 'type':'string', 'mode':'w'},
48 {'id':'dpName', 'type':'string', 'mode':'w'},
49 {'id':'cFunc', 'type':'string', 'mode':'w'},
50 )
51
53 ''' return a description
54 '''
55 return self.dpName
56
57
59 '''
60 Return the id of the datapoint, without the datasource name
61 '''
62 return self.dpName.split('_', 1)[-1]
63
64
67
68
70 """
71 If this graphpoint's graph definition is associated with a perf
72 template and if the datapoint needed by this gp is not present in
73 the perf template then return True, otherwise false.
74 """
75 if self.graphDef.rrdTemplate():
76 if self.dpName \
77 not in self.graphDef.rrdTemplate.getRRDDataPointNames():
78 return True
79 return False
80
81
82 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx,
83 multiid=-1, prefix=''):
84 ''' Build the graphing commands for this graphpoint
85 '''
86 graph = []
87
88 rrdFile = os.path.join(rrdDir, self.dpName) + ".rrd"
89
90
91 rawName = self.getDsName('%s-raw' % self.id, multiid, prefix)
92 graph.append("DEF:%s=%s:%s:%s" % (rawName, rrdFile, 'ds0', self.cFunc))
93
94
95 if self.rpn:
96 rpn = self.talesEval(self.rpn, context)
97 rpnName = self.getDsName('%s-rpn' % self.id, multiid, prefix)
98 graph.append("CDEF:%s=%s,%s" % (rpnName, rawName, rpn))
99
100
101 if self.limit > -1:
102 src = self.rpn and rpnName or rawName
103 limitName = self.getDsName('%s-limit' % self.id, multiid, prefix)
104 graph.append("CDEF:%s=%s,%s,GT,UNKN,%s,IF"%
105 (limitName,src,self.limit,src))
106
107 if self.limit > -1:
108 src = limitName
109 elif self.rpn:
110 src = rpnName
111 else:
112 src = rawName
113
114
115 graph.append('CDEF:%s=%s' %
116 (self.getDsName(self.id, multiid, prefix), src))
117
118
119 if self.lineType != self.LINETYPE_DONTDRAW:
120 if multiid != -1:
121 fname = os.path.basename(rrdDir)
122 if fname.find('.rrd') > -1: fname = fname[:-4]
123 legend = "%s-%s" % (self.id, fname)
124 else:
125 legend = self.talesEval(self.legend, context) or self.id
126 legend = self.escapeForRRD(legend)
127 drawType = self.lineType
128 if self.lineType == self.LINETYPE_LINE:
129 drawType += str(self.lineWidth)
130 drawCmd ='%s:%s%s' % (
131 drawType,
132 src,
133 self.getColor(idx))
134 drawCmd += ':%s' % legend.ljust(14)
135 if self.stacked:
136 drawCmd += ':STACK'
137 graph.append(drawCmd)
138
139
140 if addSummary:
141 graph.extend(self._summary(src, self.format, ongraph=1))
142
143 return cmds + graph
144
145
146 - def _summary(self, src, format="%5.2lf%s", ongraph=1):
147 """Add the standard summary opts to a graph"""
148 gopts = []
149 funcs = ("LAST", "AVERAGE", "MAX")
150 tags = ("cur\:", "avg\:", "max\:")
151 for i in range(len(funcs)):
152 label = "%s%s" % (tags[i], format or self.DEFAULT_FORMAT)
153 gopts.append(self.summElement(src, funcs[i], label, ongraph))
154 gopts[-1] += "\j"
155 return gopts
156
157
158 - def summElement(self, src, function, format="%5.2lf%s", ongraph=1):
159 """Make a single summary element"""
160 if ongraph: opt = "GPRINT"
161 else: opt = "PRINT"
162 return ":".join((opt, src, function, format))
163
164
165 InitializeClass(DataPointGraphPoint)
166