示例#1
0
 def __init__(self, argv = (), env = {}):
     """Populate Munin Plugin with MuninGraph instances.
     
     @param argv: List of command line arguments.
     @param env:  Dictionary of environment variables.
     
     """
     MuninPlugin.__init__(self, argv, env)
     
     self.envRegisterFilter('ports', '^\d+$')
     
     self._host = self.envGet('host')
     self._port = self.envGet('port')
     self._user = self.envGet('user')
     self._password = self.envGet('password')
     self._ssl = self.envCheckFlag('ssl', False)
     
     self._tomcatInfo = TomcatInfo(self._host, self._port,
                                   self._user, self._password, self._ssl)
     
     if self.graphEnabled('tomcat_memory'):
         graph = MuninGraph('Apache Tomcat - Memory Usage', 'Tomcat',
             info='Memory Usage Stats for Apache Tomcat Server (bytes).',
             args='--base 1024 --lower-limit 0')
         graph.addField('used', 'used', draw='AREASTACK', type='GAUGE',
                        info="Memory in use (bytes) by Apache Tomcat Server.")
         graph.addField('free', 'free', draw='AREASTACK', type='GAUGE',
                        info="Free memory (bytes) availabe for use by "
                        "Apache Tomcat Server.")
         graph.addField('max', 'max', draw='LINE2', type='GAUGE',
                        info="Maximum memory (bytes) availabe for use by "
                        "Apache Tomcat Server.", colour='FF0000')
         self.appendGraph('tomcat_memory', graph)
         
     for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
         proto = stats['proto']
         if self.portIncluded(port):
             if self.graphEnabled('tomcat_threads'):
                 name = "tomcat_threads_%d" % port
                 title = "Apache Tomcat - %s-%s - Threads" % (proto, port)
                 info = ("Thread stats for Apache Tomcat Connector %s-%s." 
                         % (proto, port))
                 graph = MuninGraph(title, 'Tomcat', info=info, 
                                    args='--base 1000 --lower-limit 0')
                 graph.addField('busy', 'busy', draw='AREASTACK', type='GAUGE',
                                info="Number of busy threads.")
                 graph.addField('idle', 'idle', draw='AREASTACK', type='GAUGE',
                                info="Number of idle threads.")
                 graph.addField('max', 'max', draw='LINE2', type='GAUGE',
                                info="Maximum number of threads permitted.",
                                colour='FF0000')
                 self.appendGraph(name, graph)
             if self.graphEnabled('tomcat_access'):
                 name = "tomcat_access_%d" % port
                 title = ("Apache Tomcat - %s-%s - Requests / sec" 
                          % (proto, port))
                 info = ("Requests per second for Apache Tomcat Connector %s-%s." 
                         % (proto, port))
                 graph = MuninGraph(title, 'Tomcat', info=info,
                                    args='--base 1000 --lower-limit 0')
                 graph.addField('reqs', 'reqs', draw='LINE2', type='DERIVE', 
                                min=0, info="Requests per second.")
                 self.appendGraph(name, graph)
             if self.graphEnabled('tomcat_error'):
                 name = "tomcat_error_%d" % port
                 title = ("Apache Tomcat - %s-%s - Errors / sec" 
                          % (proto, port))
                 info = ("Errors per second for Apache Tomcat Connector %s-%s." 
                         % (proto, port))
                 graph = MuninGraph(title, 'Tomcat', info=info,
                                    args='--base 1000 --lower-limit 0')
                 graph.addField('errors', 'errors', draw='LINE2', 
                                type='DERIVE', min=0, 
                                info="Errors per second.")
                 self.appendGraph(name, graph)
             if self.graphEnabled('tomcat_traffic'):
                 name = "tomcat_traffic_%d" % port
                 title = ("Apache Tomcat - %s-%s - Traffic (bytes/sec)" 
                          % (proto, port))
                 info = ("Traffic in bytes per second for "
                         "Apache Tomcat Connector %s-%s." 
                         % (proto, port))
                 graph = MuninGraph(title, 'Tomcat', info=info,
                                    args='--base 1024 --lower-limit 0',
                                    vlabel='bytes in (-) / out (+) per second')
                 graph.addField('rx', 'bytes', draw='LINE2', type='DERIVE', 
                                min=0, graph=False)
                 graph.addField('tx', 'bytes', draw='LINE2', type='DERIVE', 
                                min=0, negative='rx',
                     info="Bytes In (-) / Out (+) per second.")
                 self.appendGraph(name, graph)
示例#2
0
    def __init__(self, argv=(), env=None, debug=False):
        """Populate Munin Plugin with MuninGraph instances.
        
        @param argv:  List of command line arguments.
        @param env:   Dictionary of environment variables.
        @param debug: Print debugging messages if True. (Default: False)
        
        """
        MuninPlugin.__init__(self, argv, env, debug)

        self.envRegisterFilter('ports', '^\d+$')

        self._host = self.envGet('host')
        self._port = self.envGet('port', None, int)
        self._user = self.envGet('user')
        self._password = self.envGet('password')
        self._ssl = self.envCheckFlag('ssl', False)
        self._category = 'Tomcat'

        self._tomcatInfo = TomcatInfo(self._host, self._port, self._user,
                                      self._password, self._ssl)

        if self.graphEnabled('tomcat_memory'):
            graph = MuninGraph(
                'Apache Tomcat - Memory Usage',
                self._category,
                info='Memory Usage Stats for Apache Tomcat Server (bytes).',
                args='--base 1024 --lower-limit 0')
            graph.addField(
                'used',
                'used',
                draw='AREASTACK',
                type='GAUGE',
                info="Memory in use (bytes) by Apache Tomcat Server.")
            graph.addField('free',
                           'free',
                           draw='AREASTACK',
                           type='GAUGE',
                           info="Free memory (bytes) availabe for use by "
                           "Apache Tomcat Server.")
            graph.addField('max',
                           'max',
                           draw='LINE2',
                           type='GAUGE',
                           info="Maximum memory (bytes) availabe for use by "
                           "Apache Tomcat Server.",
                           colour='FF0000')
            self.appendGraph('tomcat_memory', graph)

        for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
            proto = stats['proto']
            if self.portIncluded(port):
                if self.graphEnabled('tomcat_threads'):
                    name = "tomcat_threads_%d" % port
                    title = "Apache Tomcat - %s-%s - Threads" % (proto, port)
                    info = ("Thread stats for Apache Tomcat Connector %s-%s." %
                            (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('busy',
                                   'busy',
                                   draw='AREASTACK',
                                   type='GAUGE',
                                   info="Number of busy threads.")
                    graph.addField('idle',
                                   'idle',
                                   draw='AREASTACK',
                                   type='GAUGE',
                                   info="Number of idle threads.")
                    graph.addField('max',
                                   'max',
                                   draw='LINE2',
                                   type='GAUGE',
                                   info="Maximum number of threads permitted.",
                                   colour='FF0000')
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_access'):
                    name = "tomcat_access_%d" % port
                    title = ("Apache Tomcat - %s-%s - Requests / sec" %
                             (proto, port))
                    info = (
                        "Requests per second for Apache Tomcat Connector %s-%s."
                        % (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('reqs',
                                   'reqs',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   info="Requests per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_error'):
                    name = "tomcat_error_%d" % port
                    title = ("Apache Tomcat - %s-%s - Errors / sec" %
                             (proto, port))
                    info = (
                        "Errors per second for Apache Tomcat Connector %s-%s."
                        % (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('errors',
                                   'errors',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   info="Errors per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_traffic'):
                    name = "tomcat_traffic_%d" % port
                    title = ("Apache Tomcat - %s-%s - Traffic (bytes/sec)" %
                             (proto, port))
                    info = ("Traffic in bytes per second for "
                            "Apache Tomcat Connector %s-%s." % (proto, port))
                    graph = MuninGraph(
                        title,
                        self._category,
                        info=info,
                        args='--base 1024 --lower-limit 0',
                        vlabel='bytes in (-) / out (+) per second')
                    graph.addField('rx',
                                   'bytes',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   graph=False)
                    graph.addField('tx',
                                   'bytes',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   negative='rx',
                                   info="Bytes In (-) / Out (+) per second.")
                    self.appendGraph(name, graph)
示例#3
0
class MuninTomcatPlugin(MuninPlugin):
    """Multigraph Munin Plugin for monitoring Apache Tomcat Application Server.

    """
    plugin_name = 'tomcatstats'
    isMultigraph = True

    def __init__(self, argv = (), env = {}):
        """Populate Munin Plugin with MuninGraph instances.
        
        @param argv: List of command line arguments.
        @param env:  Dictionary of environment variables.
        
        """
        MuninPlugin.__init__(self, argv, env)
        
        self.envRegisterFilter('ports', '^\d+$')
        
        self._host = self.envGet('host')
        self._port = self.envGet('port')
        self._user = self.envGet('user')
        self._password = self.envGet('password')
        self._ssl = self.envCheckFlag('ssl', False)
        
        self._tomcatInfo = TomcatInfo(self._host, self._port,
                                      self._user, self._password, self._ssl)
        
        if self.graphEnabled('tomcat_memory'):
            graph = MuninGraph('Apache Tomcat - Memory Usage', 'Tomcat',
                info='Memory Usage Stats for Apache Tomcat Server (bytes).',
                args='--base 1024 --lower-limit 0')
            graph.addField('used', 'used', draw='AREASTACK', type='GAUGE',
                           info="Memory in use (bytes) by Apache Tomcat Server.")
            graph.addField('free', 'free', draw='AREASTACK', type='GAUGE',
                           info="Free memory (bytes) availabe for use by "
                           "Apache Tomcat Server.")
            graph.addField('max', 'max', draw='LINE2', type='GAUGE',
                           info="Maximum memory (bytes) availabe for use by "
                           "Apache Tomcat Server.", colour='FF0000')
            self.appendGraph('tomcat_memory', graph)
            
        for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
            proto = stats['proto']
            if self.portIncluded(port):
                if self.graphEnabled('tomcat_threads'):
                    name = "tomcat_threads_%d" % port
                    title = "Apache Tomcat - %s-%s - Threads" % (proto, port)
                    info = ("Thread stats for Apache Tomcat Connector %s-%s." 
                            % (proto, port))
                    graph = MuninGraph(title, 'Tomcat', info=info, 
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('busy', 'busy', draw='AREASTACK', type='GAUGE',
                                   info="Number of busy threads.")
                    graph.addField('idle', 'idle', draw='AREASTACK', type='GAUGE',
                                   info="Number of idle threads.")
                    graph.addField('max', 'max', draw='LINE2', type='GAUGE',
                                   info="Maximum number of threads permitted.",
                                   colour='FF0000')
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_access'):
                    name = "tomcat_access_%d" % port
                    title = ("Apache Tomcat - %s-%s - Requests / sec" 
                             % (proto, port))
                    info = ("Requests per second for Apache Tomcat Connector %s-%s." 
                            % (proto, port))
                    graph = MuninGraph(title, 'Tomcat', info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('reqs', 'reqs', draw='LINE2', type='DERIVE', 
                                   min=0, info="Requests per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_error'):
                    name = "tomcat_error_%d" % port
                    title = ("Apache Tomcat - %s-%s - Errors / sec" 
                             % (proto, port))
                    info = ("Errors per second for Apache Tomcat Connector %s-%s." 
                            % (proto, port))
                    graph = MuninGraph(title, 'Tomcat', info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('errors', 'errors', draw='LINE2', 
                                   type='DERIVE', min=0, 
                                   info="Errors per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_traffic'):
                    name = "tomcat_traffic_%d" % port
                    title = ("Apache Tomcat - %s-%s - Traffic (bytes/sec)" 
                             % (proto, port))
                    info = ("Traffic in bytes per second for "
                            "Apache Tomcat Connector %s-%s." 
                            % (proto, port))
                    graph = MuninGraph(title, 'Tomcat', info=info,
                                       args='--base 1024 --lower-limit 0',
                                       vlabel='bytes in (-) / out (+) per second')
                    graph.addField('rx', 'bytes', draw='LINE2', type='DERIVE', 
                                   min=0, graph=False)
                    graph.addField('tx', 'bytes', draw='LINE2', type='DERIVE', 
                                   min=0, negative='rx',
                        info="Bytes In (-) / Out (+) per second.")
                    self.appendGraph(name, graph)
#                if self.graphEnabled('tomcat_cputime'):
#                    name = "tomcat_cputime_%d" % port
#                    title = ("Apache Tomcat - %s-%s - Processing Time (%%)" 
#                             % (proto, port))
#                    info = ("Processing time for Apache Tomcat Connector %s-%s." 
#                            % (proto, port))
#                    graph = MuninGraph(title, 'Tomcat', info=info,
#                                       args='--base 1000 --lower-limit 0')
#                    graph.addField('cpu', 'cpu', draw='LINE2', type='DERIVE', 
#                                   min=0, cdef='cpu,10,/')
#                    self.appendGraph(name, graph)
        
    def retrieveVals(self):
        """Retrive values for graphs."""
        if self.hasGraph('tomcat_memory'):
            stats = self._tomcatInfo.getMemoryStats()
            self.setGraphVal('tomcat_memory', 'used', 
                             stats['total'] - stats['free'])
            self.setGraphVal('tomcat_memory', 'free', stats['free'])
            self.setGraphVal('tomcat_memory', 'max', stats['max'])
        for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
            thrstats = stats['threadInfo']
            reqstats = stats['requestInfo']
            if self.portIncluded(port):
                name = "tomcat_threads_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'busy', 
                                     thrstats['currentThreadsBusy'])
                    self.setGraphVal(name, 'idle', 
                                     thrstats['currentThreadCount'] 
                                     - thrstats['currentThreadsBusy'])
                    self.setGraphVal(name, 'max', thrstats['maxThreads'])
                name = "tomcat_access_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'reqs', reqstats['requestCount'])
                name = "tomcat_error_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'errors', reqstats['errorCount'])
                name = "tomcat_traffic_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'rx', reqstats['bytesReceived'])
                    self.setGraphVal(name, 'tx', reqstats['bytesSent'])
#                name = "tomcat_cputime_%d" % port
#                if self.hasGraph(name):
#                    self.setGraphVal(name, 'cpu', 
#                                     int(reqstats['processingTime'] * 1000))
    
    def portIncluded(self, port):
        """Utility method to check if connector port is included in monitoring.
        
        @param port: Port number.
        @return:     Returns True if included in graphs, False otherwise.
            
        """
        return self.envCheckFilter('ports', str(port))
示例#4
0
class MuninTomcatPlugin(MuninPlugin):
    """Multigraph Munin Plugin for monitoring Apache Tomcat Application Server.

    """
    plugin_name = 'tomcatstats'
    isMultigraph = True
    isMultiInstance = True

    def __init__(self, argv=(), env=None, debug=False):
        """Populate Munin Plugin with MuninGraph instances.
        
        @param argv:  List of command line arguments.
        @param env:   Dictionary of environment variables.
        @param debug: Print debugging messages if True. (Default: False)
        
        """
        MuninPlugin.__init__(self, argv, env, debug)

        self.envRegisterFilter('ports', '^\d+$')

        self._host = self.envGet('host')
        self._port = self.envGet('port', None, int)
        self._user = self.envGet('user')
        self._password = self.envGet('password')
        self._ssl = self.envCheckFlag('ssl', False)
        self._category = 'Tomcat'

        self._tomcatInfo = TomcatInfo(self._host, self._port, self._user,
                                      self._password, self._ssl)

        if self.graphEnabled('tomcat_memory'):
            graph = MuninGraph(
                'Apache Tomcat - Memory Usage',
                self._category,
                info='Memory Usage Stats for Apache Tomcat Server (bytes).',
                args='--base 1024 --lower-limit 0')
            graph.addField(
                'used',
                'used',
                draw='AREASTACK',
                type='GAUGE',
                info="Memory in use (bytes) by Apache Tomcat Server.")
            graph.addField('free',
                           'free',
                           draw='AREASTACK',
                           type='GAUGE',
                           info="Free memory (bytes) availabe for use by "
                           "Apache Tomcat Server.")
            graph.addField('max',
                           'max',
                           draw='LINE2',
                           type='GAUGE',
                           info="Maximum memory (bytes) availabe for use by "
                           "Apache Tomcat Server.",
                           colour='FF0000')
            self.appendGraph('tomcat_memory', graph)

        for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
            proto = stats['proto']
            if self.portIncluded(port):
                if self.graphEnabled('tomcat_threads'):
                    name = "tomcat_threads_%d" % port
                    title = "Apache Tomcat - %s-%s - Threads" % (proto, port)
                    info = ("Thread stats for Apache Tomcat Connector %s-%s." %
                            (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('busy',
                                   'busy',
                                   draw='AREASTACK',
                                   type='GAUGE',
                                   info="Number of busy threads.")
                    graph.addField('idle',
                                   'idle',
                                   draw='AREASTACK',
                                   type='GAUGE',
                                   info="Number of idle threads.")
                    graph.addField('max',
                                   'max',
                                   draw='LINE2',
                                   type='GAUGE',
                                   info="Maximum number of threads permitted.",
                                   colour='FF0000')
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_access'):
                    name = "tomcat_access_%d" % port
                    title = ("Apache Tomcat - %s-%s - Requests / sec" %
                             (proto, port))
                    info = (
                        "Requests per second for Apache Tomcat Connector %s-%s."
                        % (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('reqs',
                                   'reqs',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   info="Requests per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_error'):
                    name = "tomcat_error_%d" % port
                    title = ("Apache Tomcat - %s-%s - Errors / sec" %
                             (proto, port))
                    info = (
                        "Errors per second for Apache Tomcat Connector %s-%s."
                        % (proto, port))
                    graph = MuninGraph(title,
                                       self._category,
                                       info=info,
                                       args='--base 1000 --lower-limit 0')
                    graph.addField('errors',
                                   'errors',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   info="Errors per second.")
                    self.appendGraph(name, graph)
                if self.graphEnabled('tomcat_traffic'):
                    name = "tomcat_traffic_%d" % port
                    title = ("Apache Tomcat - %s-%s - Traffic (bytes/sec)" %
                             (proto, port))
                    info = ("Traffic in bytes per second for "
                            "Apache Tomcat Connector %s-%s." % (proto, port))
                    graph = MuninGraph(
                        title,
                        self._category,
                        info=info,
                        args='--base 1024 --lower-limit 0',
                        vlabel='bytes in (-) / out (+) per second')
                    graph.addField('rx',
                                   'bytes',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   graph=False)
                    graph.addField('tx',
                                   'bytes',
                                   draw='LINE2',
                                   type='DERIVE',
                                   min=0,
                                   negative='rx',
                                   info="Bytes In (-) / Out (+) per second.")
                    self.appendGraph(name, graph)
#                if self.graphEnabled('tomcat_cputime'):
#                    name = "tomcat_cputime_%d" % port
#                    title = ("Apache Tomcat - %s-%s - Processing Time (%%)"
#                             % (proto, port))
#                    info = ("Processing time for Apache Tomcat Connector %s-%s."
#                            % (proto, port))
#                    graph = MuninGraph(title, self._category, info=info,
#                                       args='--base 1000 --lower-limit 0')
#                    graph.addField('cpu', 'cpu', draw='LINE2', type='DERIVE',
#                                   min=0, cdef='cpu,10,/')
#                    self.appendGraph(name, graph)

    def retrieveVals(self):
        """Retrieve values for graphs."""
        if self.hasGraph('tomcat_memory'):
            stats = self._tomcatInfo.getMemoryStats()
            self.setGraphVal('tomcat_memory', 'used',
                             stats['total'] - stats['free'])
            self.setGraphVal('tomcat_memory', 'free', stats['free'])
            self.setGraphVal('tomcat_memory', 'max', stats['max'])
        for (port, stats) in self._tomcatInfo.getConnectorStats().iteritems():
            thrstats = stats['threadInfo']
            reqstats = stats['requestInfo']
            if self.portIncluded(port):
                name = "tomcat_threads_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'busy',
                                     thrstats['currentThreadsBusy'])
                    self.setGraphVal(
                        name, 'idle', thrstats['currentThreadCount'] -
                        thrstats['currentThreadsBusy'])
                    self.setGraphVal(name, 'max', thrstats['maxThreads'])
                name = "tomcat_access_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'reqs', reqstats['requestCount'])
                name = "tomcat_error_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'errors', reqstats['errorCount'])
                name = "tomcat_traffic_%d" % port
                if self.hasGraph(name):
                    self.setGraphVal(name, 'rx', reqstats['bytesReceived'])
                    self.setGraphVal(name, 'tx', reqstats['bytesSent'])


#                name = "tomcat_cputime_%d" % port
#                if self.hasGraph(name):
#                    self.setGraphVal(name, 'cpu',
#                                     int(reqstats['processingTime'] * 1000))

    def portIncluded(self, port):
        """Utility method to check if connector port is included in monitoring.
        
        @param port: Port number.
        @return:     Returns True if included in graphs, False otherwise.
            
        """
        return self.envCheckFilter('ports', str(port))

    def autoconf(self):
        """Implements Munin Plugin Auto-Configuration Option.
        
        @return: True if plugin can be  auto-configured, False otherwise.
                 
        """
        return self._tomcatInfo is not None