blob: 112a20f654437082cda90a53399725c770892548 [file] [log] [blame]
刘洪青6266f992017-05-15 21:21:03 +08001<html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 7 (7.0.77) - Monitoring and Managing Tomcat</title><style type="text/css" media="print">
2 .noPrint {display: none;}
3 td#mainBody {width: 100%;}
4</style><style type="text/css">
5code {background-color:rgb(224,255,255);padding:0 0.1em;}
6code.attributeName, code.propertyName {background-color:transparent;}
7
8
9table {
10 border-collapse: collapse;
11 text-align: left;
12}
13table *:not(table) {
14 /* Prevent border-collapsing for table child elements like <div> */
15 border-collapse: separate;
16}
17
18th {
19 text-align: left;
20}
21
22
23div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
24 background-color: transparent;
25}
26div.codeBox {
27 overflow: auto;
28 margin: 1em 0;
29}
30div.codeBox pre {
31 margin: 0;
32 padding: 4px;
33 border: 1px solid #999;
34 border-radius: 5px;
35 background-color: #eff8ff;
36 display: table; /* To prevent <pre>s from taking the complete available width. */
37 /*
38 When it is officially supported, use the following CSS instead of display: table
39 to prevent big <pre>s from exceeding the browser window:
40 max-width: available;
41 width: min-content;
42 */
43}
44
45div.codeBox pre.wrap {
46 white-space: pre-wrap;
47}
48
49
50table.defaultTable tr, table.detail-table tr {
51 border: 1px solid #CCC;
52}
53
54table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
55 background-color: #FAFBFF;
56}
57
58table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
59 background-color: #EEEFFF;
60}
61
62table.defaultTable th, table.detail-table th {
63 background-color: #88b;
64 color: #fff;
65}
66
67table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
68 padding: 5px 8px;
69}
70
71
72p.notice {
73 border: 1px solid rgb(255, 0, 0);
74 background-color: rgb(238, 238, 238);
75 color: rgb(0, 51, 102);
76 padding: 0.5em;
77 margin: 1em 2em 1em 1em;
78}
79</style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="./images/tomcat.gif" align="right" alt="
Hongqing Liufd5ee812014-05-10 16:32:51 +080080 The Apache Tomcat Servlet/JSP Container
刘洪青6266f992017-05-15 21:21:03 +080081 " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.77, Mar 28 2017</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="./images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL/TLS</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptors-howto.html">16) MBeans Descriptors</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li><li><a href="security-howto.html">28) Security Considerations</a></li><li><a href="windows-service-howto.html">29) Windows Service</a></li><li><a href="windows-auth-howto.html">30) Windows Authentication</a></li><li><a href="jdbc-pool.html">31) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">32) WebSocket</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.2 Javadocs</a></li><li><a href="elapi/index.html">EL 2.2 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li><li><a href="tribes/introduction.html">Tribes</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Monitoring and Managing Tomcat</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
82<ul><li><a href="#Introduction">Introduction</a></li><li><a href="#Enabling_JMX_Remote">Enabling JMX Remote</a></li><li><a href="#Manage_Tomcat_with_JMX_remote_Ant_Tasks">Manage Tomcat with JMX remote Ant Tasks</a></li><li><a href="#JMXAccessorOpenTask_-_JMX_open_connection_task">JMXAccessorOpenTask - JMX open connection task</a></li><li><a href="#JMXAccessorGetTask:__get_attribute_value_Ant_task">JMXAccessorGetTask: get attribute value Ant task</a></li><li><a href="#JMXAccessorSetTask:__set_attribute_value_Ant_task">JMXAccessorSetTask: set attribute value Ant task</a></li><li><a href="#JMXAccessorInvokeTask:__invoke_MBean_operation_Ant_task">JMXAccessorInvokeTask: invoke MBean operation Ant task</a></li><li><a href="#JMXAccessorQueryTask:__query_MBean_Ant_task">JMXAccessorQueryTask: query MBean Ant task</a></li><li><a href="#JMXAccessorCreateTask:__remote_create_MBean_Ant_task">JMXAccessorCreateTask: remote create MBean Ant task</a></li><li><a href="#JMXAccessorUnregisterTask:__remote_unregister_MBean_Ant_task">JMXAccessorUnregisterTask: remote unregister MBean Ant task</a></li><li><a href="#JMXAccessorCondition:__express_condition">JMXAccessorCondition: express condition</a></li><li><a href="#JMXAccessorEqualsCondition:__equals_MBean_Ant_condition">JMXAccessorEqualsCondition: equals MBean Ant condition</a></li><li><a href="#Using_the_JMXProxyServlet">Using the JMXProxyServlet</a></li></ul>
Hongqing Liufd5ee812014-05-10 16:32:51 +080083</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Introduction"><strong>Introduction</strong></a></font></td></tr><tr><td><blockquote>
84
85 <p>Monitoring is a key aspect of system administration. Looking inside a
86 running server, obtaining some statistics or reconfiguring some aspects of
刘洪青6266f992017-05-15 21:21:03 +080087 an application are all daily administration tasks.</p>
88
Hongqing Liufd5ee812014-05-10 16:32:51 +080089 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Enabling JMX Remote"><!--()--></a><a name="Enabling_JMX_Remote"><strong>Enabling JMX Remote</strong></a></font></td></tr><tr><td><blockquote>
90
刘洪青6266f992017-05-15 21:21:03 +080091 <p><strong>Note:</strong> This configuration is needed only if you are
92 going to monitor Tomcat remotely. It is not needed if you are going
93 to monitor it locally, using the same user that Tomcat runs with.</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +080094
刘洪青6266f992017-05-15 21:21:03 +080095 <p>The Oracle website includes the list of options and how to configure
96 JMX Remote on Java 6:
Hongqing Liufd5ee812014-05-10 16:32:51 +080097 <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html">
98 http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html</a>.
99 </p>
刘洪青6266f992017-05-15 21:21:03 +0800100 <p>The following is a quick configuration guide for Java 6:</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800101 <p>Add the following parameters to <code>setenv.bat</code> script of your
102 Tomcat (see <a href="RUNNING.txt">RUNNING.txt</a> for details).<br>
103 <em>Note:</em> This syntax is for Microsoft Windows. The command has
104 to be on the same line. It is wrapped to be more readable. If Tomcat is
105 running as a Windows service, use its configuration dialog to set
106 java options for the service.
107 For un*xes remove <code>"set "</code> from beginning of the line.
108 </p>
刘洪青6266f992017-05-15 21:21:03 +0800109<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800110set CATALINA_OPTS=-Dcom.sun.management.jmxremote
111 -Dcom.sun.management.jmxremote.port=%my.jmx.port%
112 -Dcom.sun.management.jmxremote.ssl=false
113 -Dcom.sun.management.jmxremote.authenticate=false
刘洪青6266f992017-05-15 21:21:03 +0800114</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800115
116 <ol>
刘洪青6266f992017-05-15 21:21:03 +0800117 <li>If you require authorization, add and change this:
118<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800119 -Dcom.sun.management.jmxremote.authenticate=true
120 -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password
121 -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access
刘洪青6266f992017-05-15 21:21:03 +0800122</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800123 </li>
刘洪青6266f992017-05-15 21:21:03 +0800124 <li>edit the access authorization file <em>$CATALINA_BASE/conf/jmxremote.access</em>:
125<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800126monitorRole readonly
127controlRole readwrite
刘洪青6266f992017-05-15 21:21:03 +0800128</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800129 </li>
刘洪青6266f992017-05-15 21:21:03 +0800130 <li>edit the password file <em>$CATALINA_BASE/conf/jmxremote.password</em>:
131<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800132monitorRole tomcat
133controlRole tomcat
刘洪青6266f992017-05-15 21:21:03 +0800134</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800135 <b>Tip</b>: The password file should be read-only and only accessible by the
136 operating system user Tomcat is running as.
137 </li>
138 </ol>
139 <p><strong>Note:</strong> The JSR 160 JMX-Adaptor opens a second data channel
140 on a random port. That is a problem when you have a local firewall installed.
141 To fix it, configure a <code>JmxRemoteLifecycleListener</code>, as described
142 in <a href="config/listeners.html">listeners</a> documentation.
143 </p>
144
145 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Manage Tomcat with JMX remote Ant Tasks"><!--()--></a><a name="Manage_Tomcat_with_JMX_remote_Ant_Tasks"><strong>Manage Tomcat with JMX remote Ant Tasks</strong></a></font></td></tr><tr><td><blockquote>
146 <p>To simplify JMX usage with Ant 1.6.x, a set of tasks is provided that may
刘洪青6266f992017-05-15 21:21:03 +0800147 be used with antlib.</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800148 <p><b>antlib</b>: Copy your catalina-ant.jar from $CATALINA_HOME/lib to $ANT_HOME/lib.</p>
149 <p>The following example shows the JMX Accessor usage:<br>
150 <em>Note:</em> The <code>name</code> attribute value was wrapped here to be
151 more readable. It has to be all on the same line, without spaces.</p>
152 <table border="1">
153 <tr><td><pre>
154&lt;project name="Catalina Ant JMX"
155 xmlns:jmx="antlib:org.apache.catalina.ant.jmx"
156 default="state"
157 basedir="."&gt;
158 &lt;property name="jmx.server.name" value="localhost" /&gt;
159 &lt;property name="jmx.server.port" value="9012" /&gt;
160 &lt;property name="cluster.server.address" value="192.168.1.75" /&gt;
161 &lt;property name="cluster.server.port" value="9025" /&gt;
162
163 &lt;target name="state" description="Show JMX Cluster state"&gt;
164 &lt;jmx:open
165 host="${jmx.server.name}"
166 port="${jmx.server.port}"
167 username="controlRole"
168 password="tomcat"/&gt;
169 &lt;jmx:get
170 name=
171"Catalina:type=IDataSender,host=localhost,
172senderAddress=${cluster.server.address},senderPort=${cluster.server.port}"
173 attribute="connected"
174 resultproperty="IDataSender.backup.connected"
175 echo="false"
176 /&gt;
177 &lt;jmx:get
178 name="Catalina:type=ClusterSender,host=localhost"
179 attribute="senderObjectNames"
180 resultproperty="senderObjectNames"
181 echo="false"
182 /&gt;
183 &lt;!-- get current maxActiveSession from ClusterTest application
184 echo it to Ant output and store at
185 property &lt;em&gt;clustertest.maxActiveSessions.orginal&lt;/em&gt;
186 --&gt;
187 &lt;jmx:get
刘洪青6266f992017-05-15 21:21:03 +0800188 name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800189 attribute="maxActiveSessions"
190 resultproperty="clustertest.maxActiveSessions.orginal"
191 echo="true"
192 /&gt;
193 &lt;!-- set maxActiveSession to 100
194 --&gt;
195 &lt;jmx:set
刘洪青6266f992017-05-15 21:21:03 +0800196 name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800197 attribute="maxActiveSessions"
198 value="100"
199 type="int"
200 /&gt;
201 &lt;!-- get all sessions and split result as delimiter &lt;em&gt;SPACE&lt;/em&gt; for easy
202 access all session ids directly with Ant property sessions.[0..n].
203 --&gt;
204 &lt;jmx:invoke
刘洪青6266f992017-05-15 21:21:03 +0800205 name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800206 operation="listSessionIds"
207 resultproperty="sessions"
208 echo="false"
209 delimiter=" "
210 /&gt;
211 &lt;!-- Access session attribute &lt;em&gt;Hello&lt;/em&gt; from first session.
212 --&gt;
213 &lt;jmx:invoke
刘洪青6266f992017-05-15 21:21:03 +0800214 name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800215 operation="getSessionAttribute"
216 resultproperty="Hello"
217 echo="false"
218 &gt;
219 &lt;arg value="${sessions.0}"/&gt;
220 &lt;arg value="Hello"/&gt;
221 &lt;/jmx:invoke&gt;
222 &lt;!-- Query for all application manager.of the server from all hosts
223 and bind all attributes from all found manager MBeans.
224 --&gt;
225 &lt;jmx:query
226 name="Catalina:type=Manager,*"
227 resultproperty="manager"
228 echo="true"
229 attributebinding="true"
230 /&gt;
231 &lt;!-- echo the create properties --&gt;
232&lt;echo&gt;
233senderObjectNames: ${senderObjectNames.0}
234IDataSender.backup.connected: ${IDataSender.backup.connected}
235session: ${sessions.0}
236manager.length: ${manager.length}
237manager.0.name: ${manager.0.name}
238manager.1.name: ${manager.1.name}
239hello: ${Hello}
240manager.ClusterTest.0.name: ${manager.ClusterTest.0.name}
241manager.ClusterTest.0.activeSessions: ${manager.ClusterTest.0.activeSessions}
242manager.ClusterTest.0.counterSend_EVT_SESSION_EXPIRED:
243 ${manager.ClusterTest.0.counterSend_EVT_SESSION_EXPIRED}
244manager.ClusterTest.0.counterSend_EVT_GET_ALL_SESSIONS:
245 ${manager.ClusterTest.0.counterSend_EVT_GET_ALL_SESSIONS}
246&lt;/echo&gt;
247
248 &lt;/target&gt;
249
250&lt;/project&gt;
251</pre>
252 </td></tr>
253</table>
刘洪青6266f992017-05-15 21:21:03 +0800254 <p><b>import:</b> Import the JMX Accessor Project with
Hongqing Liufd5ee812014-05-10 16:32:51 +0800255 <em>&lt;import file="${CATALINA.HOME}/bin/catalina-tasks.xml" /&gt;</em> and
256 reference the tasks with <em>jmxOpen</em>, <em>jmxSet</em>, <em>jmxGet</em>,
257 <em>jmxQuery</em>, <em>jmxInvoke</em>, <em>jmxEquals</em> and <em>jmxCondition</em>.</p>
258
259 </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorOpenTask - JMX open connection task"><!--()--></a><a name="JMXAccessorOpenTask_-_JMX_open_connection_task"><strong>JMXAccessorOpenTask - JMX open connection task</strong></a></font></td></tr><tr><td><blockquote>
260<p>
261List of Attributes<br>
262<table border="1" cellpadding="5">
263
264 <tr>
265 <th align="center" bgcolor="aqua">Attribute</th>
266 <th align="center" bgcolor="aqua">Description</th>
267 <th align="center" bgcolor="aqua">Default value</th>
268 </tr>
269
270 <tr>
271 <td>url</td>
272 <td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
273 </td>
274 <td></td>
275 </tr>
276
277 <tr>
278 <td>host</td>
279 <td>Set the host, shortcut the very long URL syntax.
280 </td>
281 <td><code>localhost</code></td>
282 </tr>
283
284 <tr>
285 <td>port</td>
刘洪青6266f992017-05-15 21:21:03 +0800286 <td>Set the remote connection port
Hongqing Liufd5ee812014-05-10 16:32:51 +0800287 </td>
288 <td><code>8050</code></td>
289 </tr>
290
291 <tr>
292 <td>username</td>
293 <td>remote JMX connection user name.
294 </td>
295 <td></td>
296 </tr>
297
298 <tr>
299 <td>password</td>
300 <td>remote JMX connection password.
301 </td>
302 <td></td>
303 </tr>
304
305 <tr>
306 <td>ref</td>
307 <td>Name of the internal connection reference. With this attribute you can
308 configure more the one connection inside the same Ant project.
309 </td>
310 <td><code>jmx.server</code></td>
311 </tr>
312
313 <tr>
314 <td>echo</td>
315 <td>Echo the command usage (for access analysis or debugging)
316 </td>
317 <td><code>false</code></td>
318 </tr>
刘洪青6266f992017-05-15 21:21:03 +0800319
Hongqing Liufd5ee812014-05-10 16:32:51 +0800320 <tr>
321 <td>if</td>
322 <td>Only execute if a property of the given name <b>exists</b> in the current project.
323 </td>
324 <td></td>
325 </tr>
326
327 <tr>
328 <td>unless</td>
329 <td>Only execute if a property of the given name <b>not exists</b> in the current project.
330 </td>
331 <td></td>
332 </tr>
333
334</table>
335</p>
336<p>
337Example to open a new JMX connection<br>
刘洪青6266f992017-05-15 21:21:03 +0800338<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800339 &lt;jmx:open
340 host="${jmx.server.name}"
341 port="${jmx.server.port}"
342 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800343</code></pre></div>
344</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800345<p>
刘洪青6266f992017-05-15 21:21:03 +0800346Example to open a JMX connection from URL, with authorization and
Hongqing Liufd5ee812014-05-10 16:32:51 +0800347store at other reference <br>
刘洪青6266f992017-05-15 21:21:03 +0800348<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800349 &lt;jmx:open
350 url="service:jmx:rmi:///jndi/rmi://localhost:9024/jmxrmi"
351 ref="jmx.server.9024"
352 username="controlRole"
353 password="tomcat"
354 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800355</code></pre></div>
356</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800357
358<p>
刘洪青6266f992017-05-15 21:21:03 +0800359Example to open a JMX connection from URL, with authorization and
360store at other reference, but only when property <em>jmx.if</em> exists and
Hongqing Liufd5ee812014-05-10 16:32:51 +0800361<em>jmx.unless</em> not exists<br>
刘洪青6266f992017-05-15 21:21:03 +0800362<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800363 &lt;jmx:open
364 url="service:jmx:rmi:///jndi/rmi://localhost:9024/jmxrmi"
365 ref="jmx.server.9024"
366 username="controlRole"
367 password="tomcat"
368 if="jmx.if"
369 unless="jmx.unless"
370 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800371</code></pre></div>
372</p>
373<p><b>Note</b>: All properties from <em>jmxOpen</em> task also exists at all
374other tasks and conditions.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800375</p>
376
377</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorGetTask: get attribute value Ant task"><!--()--></a><a name="JMXAccessorGetTask:__get_attribute_value_Ant_task"><strong>JMXAccessorGetTask: get attribute value Ant task</strong></a></font></td></tr><tr><td><blockquote>
378<p>
379List of Attributes<br>
380<table border="1" cellpadding="5">
381
382 <tr>
383 <th align="center" bgcolor="aqua">Attribute</th>
384 <th align="center" bgcolor="aqua">Description</th>
385 <th align="center" bgcolor="aqua">Default value</th>
386 </tr>
387
388 <tr>
389 <td>name</td>
390 <td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
391 </td>
392 <td></td>
393 </tr>
394
395 <tr>
396 <td>attribute</td>
397 <td>Existing MBean attribute (see Tomcat MBean description above)
398 </td>
399 <td></td>
400 </tr>
401
402 <tr>
403 <td>ref</td>
404 <td>JMX Connection reference
405 </td>
406 <td><code>jmx.server</code></td>
407 </tr>
408
409 <tr>
410 <td>echo</td>
411 <td>Echo command usage (access and result)
412 </td>
413 <td><code>false</code></td>
414 </tr>
415
416 <tr>
417 <td>resultproperty</td>
418 <td>Save result at this project property
419 </td>
420 <td></td>
421 </tr>
422
423 <tr>
424 <td>delimiter</td>
刘洪青6266f992017-05-15 21:21:03 +0800425 <td>Split result with delimiter (java.util.StringTokenizer)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800426 and use resultproperty as prefix to store tokens.
427 </td>
428 <td></td>
429 </tr>
430
431 <tr>
432 <td>separatearrayresults</td>
刘洪青6266f992017-05-15 21:21:03 +0800433 <td>When return value is an array, save result as property list
434 (<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800435 </td>
436 <td><code>true</code></td>
437 </tr>
438
439</table>
440</p>
441<p>
442Example to get remote MBean attribute from default JMX connection <br>
刘洪青6266f992017-05-15 21:21:03 +0800443<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800444 &lt;jmx:get
刘洪青6266f992017-05-15 21:21:03 +0800445 name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800446 attribute="maxActiveSessions"
447 resultproperty="servlets-examples.maxActiveSessions"
448 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800449</code></pre></div>
450</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800451<p>
452Example to get and result array and split it at separate properties<br>
刘洪青6266f992017-05-15 21:21:03 +0800453<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800454 &lt;jmx:get
刘洪青6266f992017-05-15 21:21:03 +0800455 name="Catalina:type=ClusterSender,host=localhost"
456 attribute="senderObjectNames"
457 resultproperty="senderObjectNames"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800458 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800459</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800460Access the senderObjectNames properties with:
刘洪青6266f992017-05-15 21:21:03 +0800461<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800462 ${senderObjectNames.length} give the number of returned sender list.
463 ${senderObjectNames.[0..N]} found all sender object names
刘洪青6266f992017-05-15 21:21:03 +0800464</code></pre></div>
465</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800466
467<p>
468Example to get IDataSender attribute connected only when cluster is configured.<br>
469<em>Note:</em> The <code>name</code> attribute value was wrapped here to be
470more readable. It has to be all on the same line, without spaces.
471</p>
刘洪青6266f992017-05-15 21:21:03 +0800472<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800473 &lt;jmx:query
474 failonerror="false"
475 name="Catalina:type=Cluster,host=${tomcat.application.host}"
476 resultproperty="cluster"
477 /&gt;
478 &lt;jmx:get
479 name=
480"Catalina:type=IDataSender,host=${tomcat.application.host},
481senderAddress=${cluster.backup.address},senderPort=${cluster.backup.port}"
482 attribute="connected"
483 resultproperty="datasender.connected"
484 if="cluster.0.name" /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800485</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800486
487</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorSetTask: set attribute value Ant task"><!--()--></a><a name="JMXAccessorSetTask:__set_attribute_value_Ant_task"><strong>JMXAccessorSetTask: set attribute value Ant task</strong></a></font></td></tr><tr><td><blockquote>
488<p>
489List of Attributes<br>
490<table border="1" cellpadding="5">
491
492 <tr>
493 <th align="center" bgcolor="aqua">Attribute</th>
494 <th align="center" bgcolor="aqua">Description</th>
495 <th align="center" bgcolor="aqua">Default value</th>
496 </tr>
497
498 <tr>
499 <td>name</td>
500 <td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
501 </td>
502 <td></td>
503 </tr>
504
505 <tr>
506 <td>attribute</td>
507 <td>Existing MBean attribute (see Tomcat MBean description above)
508 </td>
509 <td></td>
510 </tr>
511
512 <tr>
513 <td>value</td>
刘洪青6266f992017-05-15 21:21:03 +0800514 <td>value that set to attribute
Hongqing Liufd5ee812014-05-10 16:32:51 +0800515 </td>
516 <td></td>
517 </tr>
518
519 <tr>
520 <td>type</td>
521 <td>type of the attribute.
522 </td>
523 <td>java.lang.String</td>
524 </tr>
525
526 <tr>
527 <td>ref</td>
528 <td>JMX Connection reference
529 </td>
530 <td><code>jmx.server</code></td>
531 </tr>
532
533 <tr>
534 <td>echo</td>
535 <td>Echo command usage (access and result)
536 </td>
537 <td><code>false</code></td>
538 </tr>
539
540</table>
541</p>
542<p>
543Example to set remote MBean attribute value<br>
刘洪青6266f992017-05-15 21:21:03 +0800544<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800545 &lt;jmx:set
刘洪青6266f992017-05-15 21:21:03 +0800546 name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800547 attribute="maxActiveSessions"
548 value="500"
549 type="int"
550 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800551</code></pre></div>
552</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800553
554</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorInvokeTask: invoke MBean operation Ant task"><!--()--></a><a name="JMXAccessorInvokeTask:__invoke_MBean_operation_Ant_task"><strong>JMXAccessorInvokeTask: invoke MBean operation Ant task</strong></a></font></td></tr><tr><td><blockquote>
555<p>
556List of Attributes<br>
557<table border="1" cellpadding="5">
558
559 <tr>
560 <th align="center" bgcolor="aqua">Attribute</th>
561 <th align="center" bgcolor="aqua">Description</th>
562 <th align="center" bgcolor="aqua">Default value</th>
563 </tr>
564
565 <tr>
566 <td>name</td>
567 <td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
568 </td>
569 <td></td>
570 </tr>
571
572 <tr>
573 <td>operation</td>
刘洪青6266f992017-05-15 21:21:03 +0800574 <td>Existing MBean operation (see Tomcat
Hongqing Liufd5ee812014-05-10 16:32:51 +0800575 <a href="funcspecs/fs-admin-opers.html">funcspecs/fs-admin-opers.html</a>).
576 </td>
577 <td></td>
578 </tr>
579
580 <tr>
581 <td>ref</td>
582 <td>JMX Connection reference
583 </td>
584 <td><code>jmx.server</code></td>
585 </tr>
586
587 <tr>
588 <td>echo</td>
589 <td>Echo command usage (access and result)
590 </td>
591 <td><code>false</code></td>
592 </tr>
593
594 <tr>
595 <td>resultproperty</td>
596 <td>Save result at this project property
597 </td>
598 <td></td>
599 </tr>
600
601 <tr>
602 <td>delimiter</td>
刘洪青6266f992017-05-15 21:21:03 +0800603 <td>Split result with delimiter (java.util.StringTokenizer)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800604 and use resultproperty as prefix to store tokens.
605 </td>
606 <td></td>
607 </tr>
608
609 <tr>
610 <td>separatearrayresults</td>
刘洪青6266f992017-05-15 21:21:03 +0800611 <td>When return value is an array, save result as property list
612 (<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800613 </td>
614 <td><code>true</code></td>
615 </tr>
616
617</table>
618</p>
619<p>
620stop an application <br>
刘洪青6266f992017-05-15 21:21:03 +0800621<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800622 &lt;jmx:invoke
刘洪青6266f992017-05-15 21:21:03 +0800623 name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800624 operation="stop"/&gt;
刘洪青6266f992017-05-15 21:21:03 +0800625</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800626Now you can find the sessionid at <em>${sessions.[0..N}</em> properties and access the count
627with ${sessions.length} property.
刘洪青6266f992017-05-15 21:21:03 +0800628</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800629<p>
630Example to get all sessionids <br>
刘洪青6266f992017-05-15 21:21:03 +0800631<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800632 &lt;jmx:invoke
刘洪青6266f992017-05-15 21:21:03 +0800633 name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800634 operation="listSessionIds"
635 resultproperty="sessions"
636 delimiter=" "
637 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800638</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800639Now you can find the sessionid at <em>${sessions.[0..N}</em> properties and access the count
640with ${sessions.length} property.
刘洪青6266f992017-05-15 21:21:03 +0800641</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800642<p>
643Example to get remote MBean session attribute from session ${sessionid.0}<br>
刘洪青6266f992017-05-15 21:21:03 +0800644<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800645 &lt;jmx:invoke
刘洪青6266f992017-05-15 21:21:03 +0800646 name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800647 operation="getSessionAttribute"
648 resultproperty="hello"&gt;
649 &lt;arg value="${sessionid.0}"/&gt;
650 &lt;arg value="Hello" /&gt;
651 &lt;/jmx:invoke&gt;
刘洪青6266f992017-05-15 21:21:03 +0800652</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800653</p>
654<p>
655Example to create a new access logger valve at vhost <em>localhost</em>
刘洪青6266f992017-05-15 21:21:03 +0800656<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800657 &lt;jmx:invoke
658 name="Catalina:type=MBeanFactory"
659 operation="createAccessLoggerValve"
660 resultproperty="accessLoggerObjectName"
661 &gt;
662 &lt;arg value="Catalina:type=Host,host=localhost"/&gt;
663 &lt;/jmx:invoke&gt;
刘洪青6266f992017-05-15 21:21:03 +0800664</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800665Now you can find new MBean with name stored at <em>${accessLoggerObjectName}</em>
666property.
刘洪青6266f992017-05-15 21:21:03 +0800667</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800668
669</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorQueryTask: query MBean Ant task"><!--()--></a><a name="JMXAccessorQueryTask:__query_MBean_Ant_task"><strong>JMXAccessorQueryTask: query MBean Ant task</strong></a></font></td></tr><tr><td><blockquote>
670<p>
671List of Attributes<br>
672<table border="1" cellpadding="5">
673
674 <tr>
675 <th align="center" bgcolor="aqua">Attribute</th>
676 <th align="center" bgcolor="aqua">Description</th>
677 <th align="center" bgcolor="aqua">Default value</th>
678 </tr>
679
680 <tr>
681 <td>name</td>
682 <td>JMX ObjectName query string -- <em>Catalina:type=Manager,*</em>
683 </td>
684 <td></td>
685 </tr>
686
687 <tr>
688 <td>ref</td>
689 <td>JMX Connection reference
690 </td>
691 <td><code>jmx.server</code></td>
692 </tr>
693
694 <tr>
695 <td>echo</td>
696 <td>Echo command usage (access and result)
697 </td>
698 <td><code>false</code></td>
699 </tr>
700
701 <tr>
702 <td>resultproperty</td>
703 <td>Prefix project property name to all founded MBeans (<em>mbeans.[0..N].objectname</em>)
704 </td>
705 <td></td>
706 </tr>
707
708 <tr>
刘洪青6266f992017-05-15 21:21:03 +0800709 <td>attributebinding</td>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800710 <td>bind ALL MBean attributes in addition to <em>name</em>
711 </td>
712 <td><code>false</code></td>
713 </tr>
714
715 <tr>
716 <td>delimiter</td>
刘洪青6266f992017-05-15 21:21:03 +0800717 <td>Split result with delimiter (java.util.StringTokenizer)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800718 and use resultproperty as prefix to store tokens.
719 </td>
720 <td></td>
721 </tr>
722
723 <tr>
724 <td>separatearrayresults</td>
刘洪青6266f992017-05-15 21:21:03 +0800725 <td>When return value is an array, save result as property list
726 (<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800727 </td>
728 <td><code>true</code></td>
729 </tr>
730
731</table>
732</p>
733<p>
734Get all Manager ObjectNames from all services and Hosts <br>
刘洪青6266f992017-05-15 21:21:03 +0800735<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800736 &lt;jmx:query
737 name="Catalina:type=Manager,*
738 resultproperty="manager" /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800739</code></pre></div>
740Now you can find the Session Manager at <em>${manager.[0..N].name}</em>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800741properties and access the result object counter with ${manager.length} property.
刘洪青6266f992017-05-15 21:21:03 +0800742</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800743<p>
744Example to get the Manager from <em>servlet-examples</em> application an bind all MBean properties<br>
刘洪青6266f992017-05-15 21:21:03 +0800745<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800746 &lt;jmx:query
刘洪青6266f992017-05-15 21:21:03 +0800747 name="Catalina:type=Manager,context=/servlet-examples,host=localhost*"
Hongqing Liufd5ee812014-05-10 16:32:51 +0800748 attributebinding="true"
749 resultproperty="manager.servletExamples" /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800750</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800751Now you can find the manager at <em>${manager.servletExamples.0.name}</em> property
752and can access all properties from this manager with <em>${manager.servletExamples.0.[manager attribute names]</em>}.
753The result object counter from MBeans is stored ad ${manager.length} property.
刘洪青6266f992017-05-15 21:21:03 +0800754</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800755
756<p>
757Example to get all MBeans from a server and store inside an external XML property file<br>
刘洪青6266f992017-05-15 21:21:03 +0800758<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800759&lt;project name="jmx.query"
760 xmlns:jmx="antlib:org.apache.catalina.ant.jmx"
761 default="query-all" basedir="."&gt;
762&lt;property name="jmx.host" value="localhost"/&gt;
763&lt;property name="jmx.port" value="8050"/&gt;
764&lt;property name="jmx.username" value="controlRole"/&gt;
765&lt;property name="jmx.password" value="tomcat"/&gt;
766
767&lt;target name="query-all" description="Query all MBeans of a server"&gt;
768 &lt;!-- Configure connection --&gt;
769 &lt;jmx:open
770 host="${jmx.host}"
771 port="${jmx.port}"
772 ref="jmx.server"
773 username="${jmx.username}"
774 password="${jmx.password}"/&gt;
刘洪青6266f992017-05-15 21:21:03 +0800775
Hongqing Liufd5ee812014-05-10 16:32:51 +0800776 &lt;!-- Query MBean list --&gt;
777 &lt;jmx:query
778 name="*:*"
779 resultproperty="mbeans"
780 attributebinding="false"/&gt;
781
782 &lt;echoproperties
783 destfile="mbeans.properties"
784 prefix="mbeans."
785 format="xml"/&gt;
786
787 &lt;!-- Print results --&gt;
788 &lt;echo message=
789 "Number of MBeans in server ${jmx.host}:${jmx.port} is ${mbeans.length}"/&gt;
790&lt;/target&gt;
791&lt;/project&gt;
刘洪青6266f992017-05-15 21:21:03 +0800792</code></pre></div>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800793Now you can find all MBeans inside the file <em>mbeans.properties</em>.
刘洪青6266f992017-05-15 21:21:03 +0800794</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800795
796</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorCreateTask: remote create MBean Ant task"><!--()--></a><a name="JMXAccessorCreateTask:__remote_create_MBean_Ant_task"><strong>JMXAccessorCreateTask: remote create MBean Ant task</strong></a></font></td></tr><tr><td><blockquote>
797<p>
798List of Attributes<br>
799<table border="1" cellpadding="5">
800
801 <tr>
802 <th align="center" bgcolor="aqua">Attribute</th>
803 <th align="center" bgcolor="aqua">Description</th>
804 <th align="center" bgcolor="aqua">Default value</th>
805 </tr>
806
807 <tr>
808 <td>name</td>
809 <td>Full qualified JMX ObjectName -- <em>Catalina:type=MBeanFactory</em>
810 </td>
811 <td></td>
812 </tr>
813
814 <tr>
815 <td>className</td>
816 <td>Existing MBean full qualified class name (see Tomcat MBean description above)
817 </td>
818 <td></td>
819 </tr>
820
821 <tr>
822 <td>classLoader</td>
823 <td>ObjectName of server or web application classloader <br>
824 ( <em>Catalina:type=ServerClassLoader,name=[server,common,shared]</em> or<br>
刘洪青6266f992017-05-15 21:21:03 +0800825 <em>Catalina:type=WebappClassLoader,context=/myapps,host=localhost</em>)
Hongqing Liufd5ee812014-05-10 16:32:51 +0800826 </td>
827 <td></td>
828 </tr>
829
830 <tr>
831 <td>ref</td>
832 <td>JMX Connection reference
833 </td>
834 <td><code>jmx.server</code></td>
835 </tr>
836
837 <tr>
838 <td>echo</td>
839 <td>Echo command usage (access and result)
840 </td>
841 <td><code>false</code></td>
842 </tr>
843
844</table>
845</p>
846<p>
847Example to create remote MBean<br>
刘洪青6266f992017-05-15 21:21:03 +0800848<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800849 &lt;jmx:create
850 ref="${jmx.reference}"
851 name="Catalina:type=MBeanFactory"
852 className="org.apache.commons.modeler.BaseModelMBean"
853 classLoader="Catalina:type=ServerClassLoader,name=server"&gt;
854 &lt;arg value="org.apache.catalina.mbeans.MBeanFactory" /&gt;
855 &lt;/jmx:create&gt;
刘洪青6266f992017-05-15 21:21:03 +0800856</code></pre></div>
857</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800858<p>
859 <b>Warning</b>: Many Tomcat MBeans can't be linked to their parent once<br>
860 created. The Valve, Cluster and Realm MBeans are not automatically<br>
刘洪青6266f992017-05-15 21:21:03 +0800861 connected with their parent. Use the <em>MBeanFactory</em> create<br>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800862 operation instead.
863</p>
864
865</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorUnregisterTask: remote unregister MBean Ant task"><!--()--></a><a name="JMXAccessorUnregisterTask:__remote_unregister_MBean_Ant_task"><strong>JMXAccessorUnregisterTask: remote unregister MBean Ant task</strong></a></font></td></tr><tr><td><blockquote>
866<p>
867List of Attributes<br>
868<table border="1" cellpadding="5">
869
870 <tr>
871 <th align="center" bgcolor="aqua">Attribute</th>
872 <th align="center" bgcolor="aqua">Description</th>
873 <th align="center" bgcolor="aqua">Default value</th>
874 </tr>
875
876 <tr>
877 <td>name</td>
878 <td>Full qualified JMX ObjectName -- <em>Catalina:type=MBeanFactory</em>
879 </td>
880 <td></td>
881 </tr>
882
883 <tr>
884 <td>ref</td>
885 <td>JMX Connection reference
886 </td>
887 <td><code>jmx.server</code></td>
888 </tr>
889
890 <tr>
891 <td>echo</td>
892 <td>Echo command usage (access and result)
893 </td>
894 <td><code>false</code></td>
895 </tr>
896
897</table>
898</p>
899<p>
900Example to unregister remote MBean<br>
刘洪青6266f992017-05-15 21:21:03 +0800901<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800902 &lt;jmx:unregister
903 name="Catalina:type=MBeanFactory"
904 /&gt;
刘洪青6266f992017-05-15 21:21:03 +0800905</code></pre></div>
906</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800907<p>
908 <b>Warning</b>: A lot of Tomcat MBeans can't be unregister.<br>
刘洪青6266f992017-05-15 21:21:03 +0800909 The MBeans are not unlinked from their parent. Use <em>MBeanFactory</em><br>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800910 remove operation instead.
911</p>
912
913</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorCondition: express condition"><!--()--></a><a name="JMXAccessorCondition:__express_condition"><strong>JMXAccessorCondition: express condition</strong></a></font></td></tr><tr><td><blockquote>
914<p>
915List of Attributes<br>
916<table border="1" cellpadding="5">
917
918 <tr>
919 <th align="center" bgcolor="aqua">Attribute</th>
920 <th align="center" bgcolor="aqua">Description</th>
921 <th align="center" bgcolor="aqua">Default value</th>
922 </tr>
923
924 <tr>
925 <td>url</td>
926 <td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
927 </td>
928 <td></td>
929 </tr>
930
931 <tr>
932 <td>host</td>
933 <td>Set the host, shortcut the very long URL syntax.
934 </td>
935 <td><code>localhost</code></td>
936 </tr>
937
938 <tr>
939 <td>port</td>
刘洪青6266f992017-05-15 21:21:03 +0800940 <td>Set the remote connection port
Hongqing Liufd5ee812014-05-10 16:32:51 +0800941 </td>
942 <td><code>8050</code></td>
943 </tr>
944
945 <tr>
946 <td>username</td>
947 <td>remote JMX connection user name.
948 </td>
949 <td></td>
950 </tr>
951
952 <tr>
953 <td>password</td>
954 <td>remote JMX connection password.
955 </td>
956 <td></td>
957 </tr>
958
959 <tr>
960 <td>ref</td>
961 <td>Name of the internal connection reference. With this attribute you can
962 configure more the one connection inside the same Ant project.
963 </td>
964 <td><code>jmx.server</code></td>
965 </tr>
966
967 <tr>
968 <td>name</td>
969 <td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
970 </td>
971 <td></td>
972 </tr>
973
974 <tr>
975 <td>echo</td>
976 <td>Echo condition usage (access and result)
977 </td>
978 <td><code>false</code></td>
979 </tr>
980
981 <tr>
982 <td>if</td>
983 <td>Only execute if a property of the given name <b>exists</b> in the current project.
984 </td>
985 <td></td>
986 </tr>
987
988 <tr>
989 <td>unless</td>
990 <td>Only execute if a property of the given name <b>not exists</b> in the current project.
991 </td>
992 <td></td>
993 </tr>
994
995 <tr>
刘洪青6266f992017-05-15 21:21:03 +0800996 <td>value (required)</td>
Hongqing Liufd5ee812014-05-10 16:32:51 +0800997 <td>Second arg for operation
998 </td>
999 <td></td>
1000 </tr>
1001
1002 <tr>
1003 <td>type</td>
1004 <td>Value type to express operation (support <em>long</em> and <em>double</em>)
1005 </td>
1006 <td><code>long</code></td>
1007 </tr>
1008
1009 <tr>
1010 <td>operation</td>
刘洪青6266f992017-05-15 21:21:03 +08001011 <td> express one
Hongqing Liufd5ee812014-05-10 16:32:51 +08001012 <ul>
1013 <li>== equals</li>
1014 <li>!= not equals</li>
1015 <li>&gt; greater than (&amp;gt;)</li>
1016 <li>&gt;= greater than or equals (&amp;gt;=)</li>
1017 <li>&lt; lesser than (&amp;lt;)</li>
1018 <li>&lt;= lesser than or equals (&amp;lt;=)</li>
刘洪青6266f992017-05-15 21:21:03 +08001019 </ul>
Hongqing Liufd5ee812014-05-10 16:32:51 +08001020 </td>
1021 <td><code>==</code></td>
1022 </tr>
1023
1024</table>
1025</p>
1026<p>
1027Wait for server connection and that cluster backup node is accessable<br>
刘洪青6266f992017-05-15 21:21:03 +08001028<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +08001029&lt;target name="wait"&gt;
刘洪青6266f992017-05-15 21:21:03 +08001030 &lt;waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" &gt;
1031 &lt;and&gt;
1032 &lt;socket server="${server.name}" port="${server.port}"/&gt;
1033 &lt;http url="${url}"/&gt;
1034 &lt;jmx:condition
1035 operation="=="
1036 host="localhost"
1037 port="9014"
1038 username="controlRole"
1039 password="tomcat"
1040 name=
Hongqing Liufd5ee812014-05-10 16:32:51 +08001041"Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
刘洪青6266f992017-05-15 21:21:03 +08001042 attribute="connected"
1043 value="true"
1044 /&gt;
Hongqing Liufd5ee812014-05-10 16:32:51 +08001045 &lt;/and&gt;
1046 &lt;/waitfor&gt;
1047 &lt;fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" /&gt;
1048 &lt;echo message="Server ${url} alive" /&gt;
1049&lt;/target&gt;
刘洪青6266f992017-05-15 21:21:03 +08001050</code></pre></div>
1051</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +08001052
1053</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="JMXAccessorEqualsCondition: equals MBean Ant condition"><!--()--></a><a name="JMXAccessorEqualsCondition:__equals_MBean_Ant_condition"><strong>JMXAccessorEqualsCondition: equals MBean Ant condition</strong></a></font></td></tr><tr><td><blockquote>
1054<p>
1055List of Attributes<br>
1056<table border="1" cellpadding="5">
1057
1058 <tr>
1059 <th align="center" bgcolor="aqua">Attribute</th>
1060 <th align="center" bgcolor="aqua">Description</th>
1061 <th align="center" bgcolor="aqua">Default value</th>
1062 </tr>
1063
1064 <tr>
1065 <td>url</td>
1066 <td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
1067 </td>
1068 <td></td>
1069 </tr>
1070
1071 <tr>
1072 <td>host</td>
1073 <td>Set the host, shortcut the very long URL syntax.
1074 </td>
1075 <td><code>localhost</code></td>
1076 </tr>
1077
1078 <tr>
1079 <td>port</td>
刘洪青6266f992017-05-15 21:21:03 +08001080 <td>Set the remote connection port
Hongqing Liufd5ee812014-05-10 16:32:51 +08001081 </td>
1082 <td><code>8050</code></td>
1083 </tr>
1084
1085 <tr>
1086 <td>username</td>
1087 <td>remote JMX connection user name.
1088 </td>
1089 <td></td>
1090 </tr>
1091
1092 <tr>
1093 <td>password</td>
1094 <td>remote JMX connection password.
1095 </td>
1096 <td></td>
1097 </tr>
1098
1099 <tr>
1100 <td>ref</td>
1101 <td>Name of the internal connection reference. With this attribute you can
1102 configure more the one connection inside the same Ant project.
1103 </td>
1104 <td><code>jmx.server</code></td>
1105 </tr>
1106
1107 <tr>
1108 <td>name</td>
1109 <td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
1110 </td>
1111 <td></td>
1112 </tr>
1113
1114
1115 <tr>
1116 <td>echo</td>
1117 <td>Echo condition usage (access and result)
1118 </td>
1119 <td><code>false</code></td>
1120 </tr>
1121
1122</table>
1123</p>
1124<p>
1125Wait for server connection and that cluster backup node is accessible<br>
刘洪青6266f992017-05-15 21:21:03 +08001126<div class="codeBox"><pre><code>
Hongqing Liufd5ee812014-05-10 16:32:51 +08001127&lt;target name="wait"&gt;
1128 &lt;waitfor maxwait="${maxwait}" maxwaitunit="second" timeoutproperty="server.timeout" &gt;
1129 &lt;and&gt;
1130 &lt;socket server="${server.name}" port="${server.port}"/&gt;
1131 &lt;http url="${url}"/&gt;
1132 &lt;jmx:equals
1133 host="localhost"
1134 port="9014"
1135 username="controlRole"
1136 password="tomcat"
1137 name=
1138"Catalina:type=IDataSender,host=localhost,senderAddress=192.168.111.1,senderPort=9025"
1139 attribute="connected"
1140 value="true"
1141 /&gt;
1142 &lt;/and&gt;
1143 &lt;/waitfor&gt;
1144 &lt;fail if="server.timeout" message="Server ${url} don't answer inside ${maxwait} sec" /&gt;
1145 &lt;echo message="Server ${url} alive" /&gt;
1146&lt;/target&gt;
刘洪青6266f992017-05-15 21:21:03 +08001147</code></pre></div>
1148</p>
Hongqing Liufd5ee812014-05-10 16:32:51 +08001149
刘洪青6266f992017-05-15 21:21:03 +08001150</blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Using the JMXProxyServlet"><!--()--></a><a name="Using_the_JMXProxyServlet"><strong>Using the JMXProxyServlet</strong></a></font></td></tr><tr><td><blockquote>
1151
1152 <p>
1153 Tomcat offers an alternative to using remote (or even local) JMX
1154 connections while still giving you access to everything JMX has to offer:
1155 Tomcat's
1156 <a href="api/org/apache/catalina/manager/JMXProxyServlet.html">JMXProxyServlet</a>.
1157 </p>
1158
1159 <p>
1160 The JMXProxyServlet allows a client to issue JMX queries via an HTTP
1161 interface. This technique offers the following advantages over using
1162 JMX directly from a client program:
1163 </p>
1164
1165 <ul>
1166 <li>You don't have to launch a full JVM and make a remote JMX connection
1167 just to ask for one small piece of data from a running server</li>
1168 <li>You don't have to know how to work with JMX connections</li>
1169 <li>You don't need any of the complex configuration covered in the rest
1170 of this page</li>
1171 <li>Your client program does not have to be written in Java</li>
1172 </ul>
1173
1174 <p>
1175 A perfect example of JMX overkill can be seen in the case of popular
1176 server-monitoring software such as Nagios or Icinga: if you want to
1177 monitor 10 items via JMX, you will have to launch 10 JVMs, make 10 JMX
1178 connections, and then shut them all down every few minutes. With the
1179 JMXProxyServlet, you can make 10 HTTP connections and be done with it.
1180 </p>
1181
1182 <p>
1183 You can find out more information about the JMXProxyServlet in the
1184 documentation for the
1185 <a href="manager-howto.html#Using_the_JMX_Proxy_Servlet">Tomcat
1186 manager</a>.
1187 </p>
1188 </blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
1189 on improving documentation for Apache Tomcat.<br><br>
1190 If you have trouble and need help, read
1191 <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
1192 and ask your question on the tomcat-users
1193 <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
1194 Do not ask such questions here. This is not a Q&amp;A section.<br><br>
1195 The Apache Comments System is explained <a href="./comments.html">here</a>.
1196 Comments may be removed by our moderators if they are either
1197 implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
1198 var comments_shortname = 'tomcat';
1199 var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/monitoring.html';
1200 (function(w, d) {
1201 if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
1202 d.write('<div id="comments_thread"><\/div>');
1203 var s = d.createElement('script');
1204 s.type = 'text/javascript';
1205 s.async = true;
1206 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
1207 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
1208 }
1209 else {
1210 d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
1211 }
1212 })(window, document);
1213 //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
1214 Copyright &copy; 1999-2017, Apache Software Foundation
Hongqing Liufd5ee812014-05-10 16:32:51 +08001215 </em></font></div></td></tr></table></body></html>