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

# Source Code for Module Products.ZenModel.DataPointGraphPoint

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, Zenoss Inc.
      5  #
      6  # This program is free software; you can redistribute it and/or modify it
      7  # under the terms of the GNU General Public License version 2 as published by
      8  # the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     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
     25 -def manage_addDataPointGraphPoint(context, id, REQUEST = None):
     26      ''' This is here so than zope will let us copy/paste/rename
     27      graphpoints.
     28      '''
     29      gp = DataPointGraphPoint(id)
     30      context._setObject(gp.id, gp)
     31      if REQUEST:
     32          return context.callZenScreen(REQUEST)
     33
     34
     35 -class DataPointGraphPoint(ComplexGraphPoint):
     36      '''
     37      '''
     38      meta_type = 'DataPointGraphPoint'
     39
     40      limit = -1
     41      rpn = ''
     42      dpName = ''
     43      cFunc = 'AVERAGE'
     44
     45
     46  # rpn:     Reverse Polish Notation -- applied to the value for this graph point
     47  #          See Products/ZenRRD/utils.py (rpneval)
     48  # dpName:  The basename of the rrd file (without extension) that has the data
     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  # limit:   Maximum permitted value.  Values in excess of this are NaNed.
     53  #          Not used if negative
     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
     62 -    def getDescription(self):
     63          ''' return a description
     64          '''
     65          return self.dpName
     66
     67
     68 -    def dataPointId(self):
     69          '''
     70          Return the id of the datapoint, without the datasource name
     71          '''
     72          return self.dpName.split('_', 1)[-1]
     73
     74
     75 -    def getType(self):
     76          return 'DataPoint'
     77
     78
     79 -    def isBroken(self):
     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          # Create the base DEF
    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          # If have rpn then create a new CDEF
    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          # If have limit then create a new CDEF
    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          # Create a cdef for the munged value
    129          graph.append('CDEF:%s=%s' %
    130                              (self.getDsName(self.id, multiid, prefix), src))
    131
    132          # Draw
    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              # Add summary
    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