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

# Source Code for Module Products.ZenModel.PerformanceView

      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 or (at your
      8  # option) any later version as published by the Free Software Foundation.
      9  #
     10  # For complete information please visit: http://www.zenoss.com/oss/
     11  #
     12  ###########################################################################
     13
     14  __doc__="""CricketView
     15
     16  $Id: CricketView.py,v 1.13 2004/04/06 21:05:03 edahl Exp $"""
     17
     18  __version__ = "$Revision: 1.13 $"[11:-2]
     19
     20 -class PerformanceView:
     21      """
     22      Mixin to provide hooks to performance management functions
     23      which allow targetmap management and graphing
     24      configuration generation is in PerformanceDevice and PerformanceServer
     25      """
     26
     27 -    def performanceGraphUrl(self, target=None, targettype=None,
     28                          view=None, drange=None):
     29          """resolve targettype and view names to objects
     30          and pass to performanceconf"""
     31          from Products.ZenRRD.utils import getRRDView
     32          if not drange: drange = self.defaultDateRange
     33          if target: targettype = self.getPerformanceTypeForTarget(target)
     34          if not target: target = self.id
     35          if not targettype: targettype = self.getPerformanceTargetType()
     36          targetpath = self.performanceTargetPath() + '/' + target.lower()
     37          if targetpath[-4:] != '.rrd': targetpath+='.rrd'
     38          objpaq = self.primaryAq()
     39          targettype = self.getPerformanceTarget(targettype)
     40          if not view:
     41              view = targettype.getDefaultView(objpaq)
     42          else:
     43              view = getRRDView(objpaq, view)
     44          performanceserver = objpaq.getPerformanceServer()
     45          if performanceserver:
     46              return performanceserver.performanceGraphUrl(objpaq, targetpath,
     47                                               targettype, view, drange)
     48
     49
     50 -    def performanceMGraphUrl(self, targetsmap, view=None, drange=None):
     51          """resolve targetsmap and view and send to perfconf"""
     52          from Products.ZenRRD.utils import getRRDView
     53          if not drange: drange = self.defaultDateRange
     54          objpaq = self.primaryAq()
     55          view = getRRDView(objpaq, view)
     56          performanceserver = objpaq.getPerformanceServer()
     57          ntm = []
     58          for target, targettype in targetsmap:
     59              targettype = self.getPerformanceTarget(targettype)
     60              ntm.append((target, targettype))
     61          if performanceserver:
     62              return performanceserver.performanceMGraphUrl(objpaq, ntm, view, drange)
     63
     64
     65 -    def setPerformanceTargetMap(self, targetpath, targets):
     66          """build the performance target map for an object
     67          used when we want to draw graphs for the object"""
     68          tm = {}
     69          if not isinstance(targets, (list, tuple)):
     70              targets = (targets,)
     71          for targetdata in targets:
     72              name = targetdata['target']
     73              if name == '--default--': continue
     74              ttype = targetdata['target-type']
     75              tm[name] = ttype
     76          if tm != self._performanceTargetMap:
     77              self._performanceTargetMap = tm
     78              self._p_changed = 1
     79          if self._performanceTargetPath != targetpath:
     80              self._performanceTargetPath = targetpath
     81
     82
     83 -    def performanceTargetPath(self):
     84          """Return the performance target path set for this object.
     85          """
     86          return self._performanceTargetPath
     87
     88
     89 -    def clearPerformanceMGraph(self):
     90          self._mgraphs = []
     91
     92
     93 -    def addPerformanceMGraph(self, mgraph):
     94          """add a RRDMGraph to the mgraph list for this object"""
     95          self._mgraphs.append(mgraph)
     96
     97
     98 -    def getPerformanceMGraphs(self):
     99          """returns a list of RRDMGraphs"""
    100          return self._mgraphs
    101
    102
    103 -    def checkPerformanceData(self):
    104          """check to see if there is performance data for this object"""
    105          return self.getPerformanceTargetMap() or self.getPerformanceMGraphs()
    106
    107
    108 -    def getDefaultGraphs(self, drange=None):
    109          """get the default graph list for this object"""
    110          targets = self.getPerformanceTargets()
    111          graphs = []
    112          if len(targets) == 1:
    113              targettype = self.getPerformanceTargetType()
    114              views = self.getPerformanceViewsForTarget(targettype)
    115              for view in views:
    116                  graph = {}
    117                  graph['title'] = view
    118                  graph['url'] = self.performanceGraphUrl(view=view,drange=drange)
    119                  if graph['url']:
    120                      graphs.append(graph)
    121          else:
    122              for target in targets:
    123                  graph = {}
    124                  graph['title'] = target
    125                  graph['url'] = self.performanceGraphUrl(target=target,drange=drange)
    126                  if graph['url']:
    127                      graphs.append(graph)
    128          for mgraph in self.getPerformanceMGraphs():
    129              for view in mgraph.getViews():
    130                  graph = {}
    131                  graph['title'] = view
    132                  graph['url'] = self.performanceMGraphUrl(mgraph.getMTargets(),
    133                                                      view, drange=drange)
    134                  graphs.append(graph)
    135          return graphs
    136
    137
    138 -    def getPerformanceTargets(self):
    139          """return list of target names for a performance object"""
    140          return self._performanceTargetMap.keys()
    141
    142
    143 -    def getPerformanceTargetMap(self):
    144          """return the entire targetmap"""
    145          if not hasattr(self, '_performanceTargetMap'):
    146              self._performanceTargetMap = {}
    147          return self._performanceTargetMap
    148
    149
    150 -    def getPerformanceTargetType(self):
    151          """return the target type of this instnace
    152          if there is more than one will return but which is arbitrary"""
    153          if len(self._performanceTargetMap) > 0:
    154              return self._performanceTargetMap.values()[0]
    155
    156
    157 -    def getPerformanceTypeForTarget(self, target):
    158          """lookup the type of a target for this object we try
    159          both the full target passed as well as the last section
    160          when split by a '/'"""
    161          return self._performanceTargetMap.get(target, None)
    162
    163
    164 -    def getPerformanceTarget(self, targettypename):
    165          """lookup a targettype from its name"""
    166          from Products.ZenRRD.utils import getRRDTargetType
    167          return getRRDTargetType(self.primaryAq(), targettypename)
    168
    169
    170 -    def getPerformanceViewsForTarget(self, targettypename):
    171          """get the views for a particular targetname"""
    172          target = self.getPerformanceTarget(targettypename)
    173          return target.getViewNames()
    174
    175
    176 -    def lookupPerformanceInterfaceGraphs(self, id):
    177          """lookup performance"""
    178          if hasattr(self, 'interfaces'):
    179              intrel = self.interfaces
    180              for att in intrel.objectIds():
    181                  if att.lower() == id:
    182                      obj = intrel._getOb(att)
    183                      #return obj.viewPerformanceDetail(self.REQUEST)
    184                      return obj.viewPerformanceDetail()
    185