Package Products :: Package ZenModel :: Module DataPointGraphPoint
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.DataPointGraphPoint

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  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 
21 22 @deprecated 23 -def manage_addDataPointGraphPoint(context, id, REQUEST = None):
24 ''' This is here so than zope will let us copy/paste/rename 25 graphpoints. 26 ''' 27 gp = DataPointGraphPoint(id) 28 context._setObject(gp.id, gp) 29 if REQUEST: 30 return context.callZenScreen(REQUEST)
31
32 33 -class DataPointGraphPoint(ComplexGraphPoint):
34 ''' 35 ''' 36 meta_type = 'DataPointGraphPoint' 37 38 # limit: Maximum permitted value. Values in excess of this are NaNed. 39 # Not used if negative 40 limit = -1 41 42 # rpn: Reverse Polish Notation -- applied to the value for this graph point 43 # See Products/ZenRRD/utils.py (rpneval) 44 rpn = '' 45 46 # dpName: The basename of the rrd file (without extension) that has the data 47 dpName = '' 48 49 # cFunc: The consolidation function used when that datapoint resolution 50 # exceeds the graph. See Products/ZenModel/RRDGraph dataSourceSum and 51 # http://oss.oetiker.ch/rrdtool/doc/rrdgraph_data.en.html 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
61 - def getDescription(self):
62 ''' return a description 63 ''' 64 return self.dpName
65 66
67 - def dataPointId(self):
68 ''' 69 Return the id of the datapoint, without the datasource name 70 ''' 71 return self.dpName.split('_', 1)[-1]
72 73
74 - def getType(self):
75 return 'DataPoint'
76 77
78 - def isBroken(self):
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 # Create the base DEF 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 # If have rpn then create a new CDEF 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 # If have limit then create a new CDEF 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 # Create a cdef for the munged value 128 graph.append('CDEF:%s=%s' % 129 (self.getDsName(self.id, multiid, prefix), src)) 130 131 # Draw 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 # Add summary 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