Example #1
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)