| Links User Guide Reference Apache Tomcat Development | Monitoring and Managing Tomcat| Introduction |  | 
  Monitoring is a key aspect of system administration. Looking inside a
     running server, obtaining some statistics or reconfiguring some aspects of
     an application are all daily administration tasks. | 
 | Manage Tomcat with JMX remote Ant Tasks |  | 
   To simplify JMX usage with Ant 1.6.x, a set of tasks is provided that may
   be used with antlib. antlib: Copy your catalina-ant.jar from $CATALINA_HOME/lib to $ANT_HOME/lib. The following example shows the JMX Accessor usage: 
   | 
<project name="Catalina Ant JMX"
        xmlns:jmx="antlib:org.apache.catalina.ant.jmx"
        default="state"
        basedir=".">
    <property name="jmx.server.name" value="localhost" />
    <property name="jmx.server.port" value="9012" />
    <property name="cluster.server.address" value="192.168.1.75" />
    <property name="cluster.server.port" value="9025" />
    <target name="state" description="Show JMX Cluster state">
        <jmx:open
            host="${jmx.server.name}"
            port="${jmx.server.port}"
            username="controlRole"
            password="tomcat"/>
        <jmx:get
            name="Catalina:type=IDataSender,host=localhost,senderAddress=${cluster.server.address},senderPort=${cluster.server.port}"
            attribute="connected"
            resultproperty="IDataSender.backup.connected"
            echo="false"
        />
       <jmx:get
            name="Catalina:type=ClusterSender,host=localhost"
            attribute="senderObjectNames"
            resultproperty="senderObjectNames"
            echo="false"
        />
        <!-- get current maxActiveSession from ClusterTest application
             echo it to Ant output and store at
             property <em>clustertest.maxActiveSessions.orginal</em>
        -->
       <jmx:get
            name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
            attribute="maxActiveSessions"
            resultproperty="clustertest.maxActiveSessions.orginal"
            echo="true"
        />
        <!-- set maxActiveSession to 100
        -->
        <jmx:set
            name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
            attribute="maxActiveSessions"
            value="100"
            type="int"
        />
        <!-- get all sessions and split result as delimiter <em>SPACE</em> for easy
             access all session ids directly with Ant property sessions.[0..n].
        -->
        <jmx:invoke
            name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
            operation="listSessionIds"
            resultproperty="sessions"
            echo="false"
            delimiter=" "
        />
        <!-- Access session attribute <em>Hello</em> from first session.
        -->
        <jmx:invoke
            name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
            operation="getSessionAttribute"
            resultproperty="Hello"
            echo="false"
        >
          <arg value="${sessions.0}"/>
          <arg value="Hello"/>
        </jmx:invoke>
        <!-- Query for all application manager.of the server from all hosts
             and bind all attributes from all found manager MBeans.
        -->
        <jmx:query
            name="Catalina:type=Manager,*"
            resultproperty="manager"
            echo="true"
            attributebinding="true"
        />
        <!-- echo the create properties -->
        <echo>
           senderObjectNames: ${senderObjectNames.0}
           IDataSender.backup.connected: ${IDataSender.backup.connected}
           session: ${sessions.0}
           manager.length: ${manager.length}
           manager.0.name: ${manager.0.name}
           manager.1.name: ${manager.1.name}
           hello: ${Hello}
           manager.ClusterTest.0.name: ${manager.ClusterTest.0.name}
           manager.ClusterTest.0.activeSessions: ${manager.ClusterTest.0.activeSessions}
           manager.ClusterTest.0.counterSend_EVT_SESSION_EXPIRED: ${manager.ClusterTest.0.counterSend_EVT_SESSION_EXPIRED}
           manager.ClusterTest.0.counterSend_EVT_GET_ALL_SESSIONS: ${manager.ClusterTest.0.counterSend_EVT_GET_ALL_SESSIONS}
        </echo>
    </target>
</project>
    |  import: Import the JMX Accessor Project with
   <import file="${CATALINA.HOME}/bin/catalina-tasks.xml" /> and
   reference the tasks with jmxOpen, jmxSet, jmxGet,
   jmxQuery, jmxInvoke, jmxEquals and jmxCondition. | 
 | Using the JMXProxyServlet |  | 
    
      Tomcat offers an alternative to using remote (or even local) JMX
      connections while still giving you access to everything JMX has to offer:
      Tomcat's
      JMXProxyServlet.
     
      The JMXProxyServlet allows a client to issue JMX queries via an HTTP
      interface. This technique offers the following advantages over using
      JMX directly from a client program:
     
      You don't have to launch a full JVM and make a remote JMX connection
      just to ask for one small piece of data from a runing serverYou don't have to know how to work with JMX connectionsYou don't need any of the complex configuration covered in the rest
      of this pageYour client program does not have to be written in Java 
      A perfect example of JMX overkill can be seen in the case of popular
      server-monitoring software such as Nagios or Ichinga: if you want to
      monitor 10 items via JMX, you will have to launch 10 JVMs, make 10 JMX
      connections, and then shut them all down every few minutes. With the
      JMXProxyServlet, you can make 10 HTTP connections and be done with it.
     
      You can find out more information about the JMXProxyServlet in the
      documentation for the 
      Tomcat
      manager.
     | 
 |