|
localhost
</tr>
<tr>
<td>port
<td>Set the remote connection port
</td>
<td>8050
</tr>
<tr>
<td>username
<td>remote jmx connection user name.
</td>
<td>
</tr>
<tr>
<td>password
<td>remote jmx connection password.
</td>
<td>
</tr>
<tr>
<td>ref
<td>Name of the internal connection referenz. With this attribute you can
configure more the one connection inside the same ant projekt.
</td>
<td>jmx.server
</tr>
<tr>
<td>echo
<td>Echo the command usage (for analyse access or debugging)
</td>
<td>false
</tr>
<tr>
<td>if
<td>Only execute if a property of the given name exists in the current project.
</td>
<td>
</tr>
<tr>
<td>unless
<td>Only execute if a property of the given name not exists in the current project.
</td>
<td>
</tr>
</table>
</p>
<p>
Example to open a new jmx connection<br/>
<source>
<jmx:open
host="${jmx.server.name}"
port="${jmx.server.port}"
/>
</source>
</p>
<p>
Example to open a jmx connection from url, with authorisation and
store at other reference <br/>
<source>
<jmx:open
url="service:jmx:rmi:///jndi/rmi://localhost:9024/jmxrmi"
ref="jmx.server.9024"
username="controlRole"
password="tomcat"
/>
</source>
</p>
<p>
Example to open a jmx connection from url, with authorisation and
store at other reference, but only when property <em>jmx.if exists and
<em>jmx.unless not existsjmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
<tr>
<td>resultproperty
<td>Save result at this project property
</td>
<td>
</tr>
<tr>
<td>delimiter
<td>Split result with delimiter (java.util.StringTokenizier)
and use resultproperty as prefix to store tokens.
</td>
<td>
</tr>
<tr>
<td>separatearrayresults
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N] and $resultproperty.lenght)
</td>
<td>true
</tr>
</table>
</p>
<p>
Example to get remote mbean attribute from default jmx connection <br/>
<source>
<jmx:get
name="Catalina:type=Manager,path=/servlets-examples,host=localhost"
attribute="maxActiveSessions"
resultproperty="servlets-examples.maxActiveSessions"
/>
</source>
</p>
<p>
Example to get and result array and split it at separate properties<br/>
<source>
<jmx:get
name="Catalina:type=ClusterSender,host=localhost"
attribute="senderObjectNames"
resultproperty="senderObjectNames"
/>
</source>
Access the senderObjectNames properties with:
<source>
${senderObjectNames.lenght} give the number of returned sender list.
${senderObjectNames.[0..N]} found all sender object names
</source>
</p>
<p>
Example to get IDataSender attribute connected only when cluster is configured.
<source>
<jmx:query
failonerror="false"
name="Catalina:type=Cluster,host=${tomcat.application.host}"
resultproperty="cluster"
/>
<jmx:get
name="Catalina:type=IDataSender,host=${tomcat.application.host},senderAddress=${cluster.backup.address},senderPort=${cluster.backup.port}"
attribute="connected"
resultproperty="datasender.connected"
if="cluster.0.name" />
</source>
</p>
</section>
<!-- Set #########################################################################
-->
<section name="JMXAccessorSetTask: set attribute value ant task">
<p>
List of Attributes<br/>
<table border="1" cellpadding="5">
<tr>
<th align="center" bgcolor="aqua">Attribute
<th align="center" bgcolor="aqua">Description
<th align="center" bgcolor="aqua">Default value
</tr>
<tr>
<td>name
<td>Full qualified JMX ObjectName -- Catalina:type=Server
</td>
<td>
</tr>
<tr>
<td>attribute
<td>Existing Mbean attribute (see Tomcat mbean description above)
</td>
<td>
</tr>
<tr>
<td>value
<td>value that set to attribute
</td>
<td>
</tr>
<tr>
<td>type
<td>type of the attribute.
</td>
<td>java.lang.String
</tr>
<tr>
<td>ref
<td>JMX Connection reference
</td>
<td>jmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
</table>
</p>
<p>
Example to set remote mbean attribute value<br/>
<source>
<jmx:set
name="Catalina:type=Manager,path=/servlets-examples,host=localhost"
attribute="maxActiveSessions"
value="500"
type="int"
/>
</source>
</p>
</section>
<!-- Invoke #########################################################################
-->
<section name="JMXAccessorInvokeTask: invoke Mbean operation ant task">
<p>
List of Attributes<br/>
<table border="1" cellpadding="5">
<tr>
<th align="center" bgcolor="aqua">Attribute
<th align="center" bgcolor="aqua">Description
<th align="center" bgcolor="aqua">Default value
</tr>
<tr>
<td>name
<td>Full qualified JMX ObjectName -- Catalina:type=Server
</td>
<td>
</tr>
<tr>
<td>operation
<td>Existing Mbean operation (see Tomcat
<a href="funcspecs/fs-admin-opers.html">funcspecs/fs-admin-opers.html.
</td>
<td>
</tr>
<tr>
<td>ref
<td>JMX Connection reference
</td>
<td>jmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
<tr>
<td>resultproperty
<td>Save result at this project property
</td>
<td>
</tr>
<tr>
<td>delimiter
<td>Split result with delimiter (java.util.StringTokenizier)
and use resultproperty as prefix to store tokens.
</td>
<td>
</tr>
<tr>
<td>separatearrayresults
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N] and $resultproperty.lenght)
</td>
<td>true
</tr>
</table>
</p>
<p>
stop an application <br/>
<source>
<jmx:invoke
name="Catalina:type=Manager,path=/servlets-examples,host=localhost"
operation="stop"/>
</source>
Now you can find the sessionid at <em>${sessions.[0..N} properties and access the count
with ${sessions.lenght} property.
</p>
<p>
Example to get all sessionids <br/>
<source>
<jmx:invoke
name="Catalina:type=Manager,path=/servlets-examples,host=localhost"
operation="listSessionIds"
resultproperty="sessions"
delimiter=" "
/>
</source>
Now you can find the sessionid at <em>${sessions.[0..N} properties and access the count
with ${sessions.lenght} property.
</p>
<p>
Example to get remote mbean session attribute from session ${sessionid.0}<br/>
<source>
<jmx:invoke
name="Catalina:type=Manager,path=/ClusterTest,host=localhost"
operation="getSessionAttribute"
resultproperty="hello">
<arg value="${sessionid.0}"/>
<arg value="Hello" />
</jmx:invoke>
</source>
</p>
<p>
Example to create a new access logger valve at vhost <em>localhost
<source>
<jmx:invoke
name="Catalina:type=MBeanFactory"
operation="createAcccesLoggerValve"
resultproperty="acccesLoggerObjectName"
>
<arg value="Catalina:type=Host,host=localhost"/>
</jmx:invoke>
</source>
Now you can find new Mbean with name stored at <em>${acccesLoggerObjectName}
proeprty.
</p>
</section>
<!-- Query #########################################################################
-->
<section name="JMXAccessorQueryTask: query Mbean ant task">
<p>
List of Attributes<br/>
<table border="1" cellpadding="5">
<tr>
<th align="center" bgcolor="aqua">Attribute
<th align="center" bgcolor="aqua">Description
<th align="center" bgcolor="aqua">Default value
</tr>
<tr>
<td>name
<td>JMX ObjectName query string -- Catalina:type=Manager,*
</td>
<td>
</tr>
<tr>
<td>ref
<td>JMX Connection reference
</td>
<td>jmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
<tr>
<td>resultproperty
<td>Prefix project property name to all founded Mbeans (mbeans.[0..N].objectname)
</td>
<td>
</tr>
<tr>
<td>attributebinduing
<td>bind ALL MBean attributes in addition to name
</td>
<td>false
</tr>
<tr>
<td>delimiter
<td>Split result with delimiter (java.util.StringTokenizier)
and use resultproperty as prefix to store tokens.
</td>
<td>
</tr>
<tr>
<td>separatearrayresults
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N] and $resultproperty.lenght)
</td>
<td>true
</tr>
</table>
</p>
<p>
Get all Manager ObjectNames from all services and Hosts <br/>
<source>
<jmx:query
name="Catalina:type=Manager,*
resultproperty="manager" />
</source>
Now you can find the Session Manager at <em>${manager.[0..N].name}
properties and access the result object counter with ${manager.length} property.
</p>
<p>
Example to get the Manager from <em>servlet-examples application an bind all mbean propertiesjmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
</table>
</p>
<p>
Example to create remote mbean<br/>
<source>
<jmx:create
ref="${jmx.reference}"
name="Catalina:type=MBeanFactory"
className="org.apache.commons.modeler.BaseModelMBean"
classLoader="Catalina:type=ServerClassLoader,name=server">
<Arg value="org.apache.catalina.mbeans.MBeanFactory" />
</jmx:create>
</source>
</p>
<p>
<b>Warning: A lot of tomcat mbeans can't be really create and connect with jmx.server
</tr>
<tr>
<td>echo
<td>Echo command usage (access and result)
</td>
<td>false
</tr>
</table>
</p>
<p>
Example to unregister remote mbean<br/>
<source>
<jmx:unregister
name="Catalina:type=MBeanFactory"
/>
</source>
</p>
<p>
<b>Warning: A lot of tomcat mbeans can't be really unregister. localhost
</tr>
<tr>
<td>port
<td>Set the remote connection port
</td>
<td>8050
</tr>
<tr>
<td>username
<td>remote jmx connection user name.
</td>
<td>
</tr>
<tr>
<td>password
<td>remote jmx connection password.
</td>
<td>
</tr>
<tr>
<td>ref
<td>Name of the internal connection reference. With this attribute you can
configure more the one connection inside the same ant projekt.
</td>
<td>jmx.server
</tr>
<tr>
<td>name
<td>Full qualified JMX ObjectName -- Catalina:type=Server
</td>
<td>
</tr>
<tr>
<td>echo
<td>Echo condition usage (access and result)
</td>
<td>false
</tr>
<tr>
<td>if
<td>Only execute if a property of the given name exists in the current project.
</td>
<td>
</tr>
<tr>
<td>unless
<td>Only execute if a property of the given name not exists in the current project.
</td>
<td>
</tr>
<tr>
<td>value (requiered)
<td>Second arg for operation
</td>
<td>
</tr>
<tr>
<td>type
<td>Value type to express operation (support long and double)
</td>
<td>long
</tr>
<tr>
<td>operation
<td> express one
<ul>
<li>== equals
<li>!= not equals
<li>> greater than (>)
<li>>= greater than or equals (>=)
<li>< lesser than (<)
<li><= lesser than or equals (<=)
</ul>
</td>
<td>==
</tr>
</table>
</p>
<p>
Wait for server connection and that cluster backup node is accessable<br/>
<source>
<target name="wait">
<waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" >
<and>
<socket server="${server.name}" port="${server.port}"/>
<http url="${url}"/>
<jmx:condition
operation="=="
host="localhost"
port="9014"
username="controlRole"
password="tomcat"
name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
attribute="connected"
value="true"
/>
</and>
</waitfor>
<fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" />
<echo message="Server ${url} alive" />
</target>
</source>
</p>
</section>
<!-- Equals #########################################################################
-->
<section name="JMXAccessorEqualsCondition: equals Mbean ant condition">
<p>
List of Attributes<br/>
<table border="1" cellpadding="5">
<tr>
<th align="center" bgcolor="aqua">Attribute
<th align="center" bgcolor="aqua">Description
<th align="center" bgcolor="aqua">Default value
</tr>
<tr>
<td>url
<td>Set jmx connection url - service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi
</td>
<td>
</tr>
<tr>
<td>host
<td>Set the host, shortcut the very long url syntax.
</td>
<td>localhost
</tr>
<tr>
<td>port
<td>Set the remote connection port
</td>
<td>8050
</tr>
<tr>
<td>username
<td>remote jmx connection user name.
</td>
<td>
</tr>
<tr>
<td>password
<td>remote jmx connection password.
</td>
<td>
</tr>
<tr>
<td>ref
<td>Name of the internal connection referenz. With this attribute you can
configure more the one connection inside the same ant projekt.
</td>
<td>jmx.server
</tr>
<tr>
<td>name
<td>Full qualified JMX ObjectName -- Catalina:type=Server
</td>
<td>
</tr>
<tr>
<td>echo
<td>Echo condition usage (access and result)
</td>
<td>false
</tr>
</table>
</p>
<p>
Wait for server connection and that cluster backup node is accessable<br/>
<source>
<target name="wait">
<waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" >
<and>
<socket server="${server.name}" port="${server.port}"/>
<http url="${url}"/>
<jmx:equals
host="localhost"
port="9014"
username="controlRole"
password="tomcat"
name="Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
attribute="connected"
value="true"
/>
</and>
</waitfor>
<fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" />
<echo message="Server ${url} alive" />
</target>
</source>
</p>
</section>
</body>
</document>
Here is a short list of links related to this Tomcat monitoring.xml source code file:
Tomcat example source code file (monitoring.xml)
The Tomcat monitoring.xml source code<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE document [
<!ENTITY project SYSTEM "project.xml">
]>
<document url="monitoring.html">
&project;
<properties>
<author email="pero@apache.org">Peter Rossbach
<author email="remm@apache.org">Remy Maucherat
<title>Monitoring and Managing Tomcat
</properties>
<body>
<section name="Introduction">
<p>Monitoring is a very important question today. Looking inside the running
server, grab some statistic data or reconfigure some aspects are
daliy adminstration tasks.</p>
</section>
<section name="Enabling JMX Remote">
<p>The Sun website includes the list of options and how to configure JMX Remote on Java 5:
<a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html">
http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html</a>.
</p>
<p>For quick installation you find here a short installation guide:
<p>Add the following parameters to your tomcat startup script:
<source>
set CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=%my.jmx.port% \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false"
</source>
</p>
<p>
<ol>
<li>When you think authorisation is a good, add and change this :
<source>
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password \
-Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access \
</source>
</li>
<li>edit the access allow file $CATALINA_BASE/conf/jmxremote.access :
<source>
monitorRole readonly
controlRole readwrite
</source>
</li>
<li>edit the password file $CATALINA_BASE/conf/jmxremote.password :
<source>
monitorRole tomcat
controlRole tomcat
</source>
<b>Tipp: Password File must be readonly and not accessable from every
other user! Remove all other users under windows to access this file.
</li>
</ol>
<b>Note:The JSR 160 JMX-Adaptor opens a second data protocol port. That is a problem
when you have installed a local firewall.<br/>
</p>
<p>Activate JMX MX4J Http Adaptor with Java 1.4:
<ol>
<li>Install the tomcat compat package
<li>Install the mx4j-tools.jar at common/lib. Please, use the same MX4j
version as your tomcat release</li>
<li>Configure a MX4J JMX HTTP Adaptor at your AJP Connector
<p>
<source>
<Connector port="${AJP.PORT}"
handler.list="mx"
mx.enabled="true"
mx.httpHost="${JMX.HOST}"
mx.httpPort="${JMX.PORT}"
protocol="AJP/1.3" />
</source>
</p>
<p>Tipp: With ${AJP.PORT}=0 no ajp connection where started.
</p>
<p>Note: MX4J JSR 160 RMI Adaptor to support JDK 1.4 currently not integrated.
</p>
</li>
<li>Start your tomcat and look with a browser at http://${JMX.HOST}:${JMX.PORT}
<li>With the mx connector parameter | <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,path=/ClusterTest,host=localhost" attribute="maxActiveSessions" resultproperty="clustertest.maxActiveSessions.orginal" echo="true" /> <!-- set maxActiveSession to 100 --> <jmx:set name="Catalina:type=Manager,path=/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,path=/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,path=/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> </pre> </td> |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.