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