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
69 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx,
70 multiid=-1, prefix=''):
71 ''' Build the graphing commands for this graphpoint
72 '''
73 graph = []
74
75 rrdFile = os.path.join(rrdDir, self.dpName) + ".rrd"
76
77
78
79 if not getattr(context, 'isFake', False):
80 if not os.path.isfile(rrdFile):
81 desc = context.device().id
82 if context.meta_type != 'Device':
83 desc += ' %s' % context.name()
84 desc += ' %s' % self.dpName
85 cmds.append('COMMENT:MISSING\: data file for %s' % desc)
86 return cmds
87
88
89 rawName = self.getDsName('%s-raw' % self.id, multiid, prefix)
90 graph.append("DEF:%s=%s:%s:%s" % (rawName, rrdFile, 'ds0', self.cFunc))
91
92
93 if self.rpn:
94 rpnName = self.getDsName('%s-rpn' % self.id, multiid, prefix)
95 graph.append("CDEF:%s=%s,%s" % (rpnName, rawName, self.rpn))
96
97
98 if self.limit > -1:
99 src = self.rpn and rpnName or rawName
100 limitName = self.getDsName('%s-limit' % self.id, multiid, prefix)
101 graph.append("CDEF:%s=%s,%s,GT,UNKN,%s,IF"%
102 (limitName,src,self.limit,src))
103
104 if self.limit > -1:
105 src = limitName
106 elif self.rpn:
107 src = rpnName
108 else:
109 src = rawName
110
111
112 graph.append('CDEF:%s=%s' %
113 (self.getDsName(self.id, multiid, prefix), src))
114
115
116 if self.lineType != self.LINETYPE_DONTDRAW:
117 if multiid != -1:
118 fname = os.path.basename(rrdDir)
119 if fname.find('.rrd') > -1: fname = fname[:-4]
120 legend = "%s-%s" % (self.id, fname)
121 else:
122 legend = self.talesEval(self.legend, context) or self.id
123 legend = self.escapeForRRD(legend)
124 drawCmd ='%s:%s%s' % (
125 self.lineType,
126 src,
127 self.getColor(idx))
128 drawCmd += ':%s' % legend.ljust(14)
129 if self.stacked:
130 drawCmd += ':STACK'
131 graph.append(drawCmd)
132
133
134 if addSummary:
135 graph.extend(self._summary(src, self.format, ongraph=1))
136
137 return cmds + graph
138
139
140 - def _summary(self, src, format="%5.2lf%s", ongraph=1):
141 """Add the standard summary opts to a graph"""
142 gopts = []
143 funcs = ("LAST", "AVERAGE", "MAX")
144 tags = ("cur\:", "avg\:", "max\:")
145 for i in range(len(funcs)):
146 label = "%s%s" % (tags[i], format or self.DEFAULT_FORMAT)
147 gopts.append(self.summElement(src, funcs[i], label, ongraph))
148 gopts[-1] += "\j"
149 return gopts
150
151
152 - def summElement(self, src, function, format="%5.2lf%s", ongraph=1):
153 """Make a single summary element"""
154 if ongraph: opt = "GPRINT"
155 else: opt = "PRINT"
156 return ":".join((opt, src, function, format))
157
158
159 InitializeClass(DataPointGraphPoint)
160