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      _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
     52 -    def getDescription(self):
     53          ''' return a description
     54          '''
     55          return self.dpName
     56
     57
     58 -    def dataPointId(self):
     59          '''
     60          Return the id of the datapoint, without the datasource name
     61          '''
     62          return self.dpName.split('_', 1)[-1]
     63
     64
     65 -    def getType(self):
     66          return 'DataPoint'
     67
     68
     69 -    def isBroken(self):
     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          # Create the base DEF
     91          rawName = self.getDsName('%s-raw' % self.id, multiid, prefix)
     92          graph.append("DEF:%s=%s:%s:%s" % (rawName, rrdFile, 'ds0', self.cFunc))
     93          graph.append("DEF:%s-max=%s:%s:%s" % (rawName, rrdFile, 'ds0', "MAX"))
     94
     95          # If have rpn then create a new CDEF
     96          if self.rpn:
     97              rpn = self.talesEval(self.rpn, context)
     98              rpnName = self.getDsName('%s-rpn' % self.id, multiid, prefix)
     99              graph.append("CDEF:%s=%s,%s" % (rpnName, rawName, rpn))
    100              graph.append("CDEF:%s-max=%s-max,%s" % (rpnName, rawName, rpn))
    101
    102          # If have limit then create a new CDEF
    103          if self.limit > -1:
    104              src = self.rpn and rpnName or rawName
    105              limitName = self.getDsName('%s-limit' % self.id, multiid, prefix)
    106              graph.append("CDEF:%s=%s,%s,GT,UNKN,%s,IF"%
    107                          (limitName,src,self.limit,src))
    108              graph.append("CDEF:%s-max=%s-max,%s,GT,UNKN,%s,IF"%
    109                          (limitName,src,self.limit,src))
    110
    111          if self.limit > -1:
    112              src = limitName
    113          elif self.rpn:
    114              src = rpnName
    115          else:
    116              src = rawName
    117
    118          # Create a cdef for the munged value
    119          graph.append('CDEF:%s=%s' %
    120                              (self.getDsName(self.id, multiid, prefix), src))
    121
    122          # Draw
    123          if self.lineType != self.LINETYPE_DONTDRAW:
    124              if multiid != -1:
    125                  fname = os.path.basename(rrdDir)
    126                  if fname.find('.rrd') > -1: fname = fname[:-4]
    127                  legend = "%s-%s" % (self.id, fname)
    128              else:
    129                  legend = self.talesEval(self.legend, context) or self.id
    130              legend = self.escapeForRRD(legend)
    131              drawType = self.lineType
    132              if self.lineType == self.LINETYPE_LINE:
    133                  drawType += str(self.lineWidth)
    134              drawCmd ='%s:%s%s' % (
    135                          drawType,
    136                          src,
    137                          self.getColor(idx))
    138              drawCmd += ':%s' % legend.ljust(14)
    139              if self.stacked:
    140                  drawCmd += ':STACK'
    141              graph.append(drawCmd)
    142
    143              # Add summary
    144              if addSummary:
    145                  graph.extend(self._summary(src, self.format, ongraph=1))
    146
    147          return cmds + graph
    148
    149
    150 -    def _summary(self, src, format="%5.2lf%s", ongraph=1):
    151          """Add the standard summary opts to a graph"""
    152          gopts = []
    153          funcs = ("LAST", "AVERAGE", "MAX")
    154          tags = ("cur\:", "avg\:", "max\:")
    155          for i in range(len(funcs)):
    156              label = "%s%s" % (tags[i], format or self.DEFAULT_FORMAT)
    157              if funcs[i] == "MAX":
    158                  src += "-max"
    159              gopts.append(self.summElement(src, funcs[i], label, ongraph))
    160          gopts[-1] += "\j"
    161          return gopts
    162
    163
    164 -    def summElement(self, src, function, format="%5.2lf%s", ongraph=1):
    165          """Make a single summary element"""
    166          if ongraph: opt = "GPRINT"
    167          else: opt = "PRINT"
    168          return ":".join((opt, src, function, format))
    169
    170
    171  InitializeClass(DataPointGraphPoint)
    172