]>
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. Note: This configuration is needed only if you are
going to monitor Tomcat remotely. It is not needed if you are going
to monitor it locally, using the same user that Tomcat runs with. The Oracle website includes the list of options and how to configure
JMX Remote on Java 6:
http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html.
The following is a quick configuration guide for Java 6: Add the following parameters to Note: The JSR 160 JMX-Adaptor opens a second data channel
on a random port. That is a problem when you have a local firewall installed.
To fix it, configure a 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: 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.
List of Attributessetenv.bat script of your
Tomcat (see RUNNING.txt for details).
Note: This syntax is for Microsoft Windows. The command has
to be on the same line. It is wrapped to be more readable. If Tomcat is
running as a Windows service, use its configuration dialog to set
java options for the service.
For un*xes remove "set " from beginning of the line.
JmxRemoteLifecycleListener, as described
in listeners documentation.
Note: The name attribute value was wrapped here to be
more readable. It has to be all on the same line, without spaces.
<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>
Attribute
Description
Default value
url
Set JMX connection URL - service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi
host
Set the host, shortcut the very long URL syntax.
localhost
port
Set the remote connection port
8050
username
remote JMX connection user name.
password
remote JMX connection password.
ref
Name of the internal connection reference. With this attribute you can
configure more the one connection inside the same Ant project.
jmx.server
echo
Echo the command usage (for access analysis or debugging)
false
if
Only execute if a property of the given name exists in the current project.
unless
Only execute if a property of the given name not exists in the current project.
Example to open a new JMX connection
Example to open a JMX connection from URL, with authorization and
store at other reference
Example to open a JMX connection from URL, with authorization and
store at other reference, but only when property jmx.if exists and
jmx.unless not exists
Note: All properties from jmxOpen task also exists at all other tasks and conditions.
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | Full qualified JMX ObjectName -- Catalina:type=Server | |
| attribute | Existing MBean attribute (see Tomcat MBean description above) | |
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
| resultproperty | Save result at this project property | |
| delimiter | Split result with delimiter (java.util.StringTokenizier) and use resultproperty as prefix to store tokens. | |
| separatearrayresults | When return value is an array, save result as property list ($resultproperty.[0..N] and $resultproperty.length) | true |
Example to get remote MBean attribute from default JMX connection
Example to get and result array and split it at separate properties
Example to get IDataSender attribute connected only when cluster is configured.
Note: The name attribute value was wrapped here to be
more readable. It has to be all on the same line, without spaces.
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | Full qualified JMX ObjectName -- Catalina:type=Server | |
| attribute | Existing MBean attribute (see Tomcat MBean description above) | |
| value | value that set to attribute | |
| type | type of the attribute. | java.lang.String |
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
Example to set remote MBean attribute value
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | Full qualified JMX ObjectName -- Catalina:type=Server | |
| operation | Existing MBean operation (see Tomcat funcspecs/fs-admin-opers.html). | |
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
| resultproperty | Save result at this project property | |
| delimiter | Split result with delimiter (java.util.StringTokenizier) and use resultproperty as prefix to store tokens. | |
| separatearrayresults | When return value is an array, save result as property list ($resultproperty.[0..N] and $resultproperty.length) | true |
stop an application
Example to get all sessionids
Example to get remote MBean session attribute from session ${sessionid.0}
Example to create a new access logger valve at vhost localhost
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | JMX ObjectName query string -- Catalina:type=Manager,* | |
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
| resultproperty | Prefix project property name to all founded MBeans (mbeans.[0..N].objectname) | |
| attributebinduing | bind ALL MBean attributes in addition to name | false |
| delimiter | Split result with delimiter (java.util.StringTokenizier) and use resultproperty as prefix to store tokens. | |
| separatearrayresults | When return value is an array, save result as property list ($resultproperty.[0..N] and $resultproperty.length) | true |
Get all Manager ObjectNames from all services and Hosts
Example to get the Manager from servlet-examples application an bind all MBean properties
Example to get all MBeans from a server and store inside an external XML property file
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | Full qualified JMX ObjectName -- Catalina:type=MBeanFactory | |
| className | Existing MBean full qualified class name (see Tomcat MBean description above) | |
| classLoader | ObjectName of server or web application classloader ( Catalina:type=ServerClassLoader,name=[server,common,shared] or Catalina:type=WebappClassLoader,context=/myapps,host=localhost) |
|
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
Example to create remote MBean
Warning: Many Tomcat MBeans can't be linked to their parent once
created. The Valve, Cluster and Realm MBeans are not automatically
connected with their parent. Use the MBeanFacrory create
operation instead.
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| name | Full qualified JMX ObjectName -- Catalina:type=MBeanFactory | |
| ref | JMX Connection reference | jmx.server |
| echo | Echo command usage (access and result) | false |
Example to unregister remote MBean
Warning: A lot of Tomcat MBeans can't be unregister.
The MBeans are not unlinked from their parent. Use MBeanFacrory
remove operation instead.
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| url | Set JMX connection URL - service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi | |
| host | Set the host, shortcut the very long URL syntax. | localhost |
| port | Set the remote connection port | 8050 |
| username | remote JMX connection user name. | |
| password | remote JMX connection password. | |
| ref | Name of the internal connection reference. With this attribute you can configure more the one connection inside the same Ant project. | jmx.server |
| name | Full qualified JMX ObjectName -- Catalina:type=Server | |
| echo | Echo condition usage (access and result) | false |
| if | Only execute if a property of the given name exists in the current project. | |
| unless | Only execute if a property of the given name not exists in the current project. | |
| value (requiered) | Second arg for operation | |
| type | Value type to express operation (support long and double) | long |
| operation | express one
|
== |
Wait for server connection and that cluster backup node is accessable
List of Attributes
| Attribute | Description | Default value |
|---|---|---|
| url | Set JMX connection URL - service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi | |
| host | Set the host, shortcut the very long URL syntax. | localhost |
| port | Set the remote connection port | 8050 |
| username | remote JMX connection user name. | |
| password | remote JMX connection password. | |
| ref | Name of the internal connection reference. With this attribute you can configure more the one connection inside the same Ant project. | jmx.server |
| name | Full qualified JMX ObjectName -- Catalina:type=Server | |
| echo | Echo condition usage (access and result) | false |
Wait for server connection and that cluster backup node is accessible
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:
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.