1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
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>
<title>Monitoring and Managing Tomcat</title>
</properties>
<body>
<section name="Table of Contents">
<toc/>
</section>
<section name="Introduction">
<p>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.</p>
</section>
<section name="Enabling JMX Remote">
<p><strong>Note:</strong> 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.</p>
<p>The Oracle website includes the list of options and how to configure
JMX Remote on Java 11:
<a href="https://docs.oracle.com/en/java/javase/11/management/monitoring-and-management-using-jmx-technology.html">
http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html</a>.
</p>
<p>The following is a quick configuration guide for Java 11:</p>
<p>Add the following parameters to <code>setenv.bat</code> script of your
Tomcat (see <a href="RUNNING.txt">RUNNING.txt</a> for details).<br/>
<em>Note:</em> 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 Linux, MacOS, etc, remove <code>"set "</code> from beginning of the
line.
</p>
<source><![CDATA[set CATALINA_OPTS=-Dcom.sun.management.jmxremote.port=%my.jmx.port%
-Dcom.sun.management.jmxremote.rmi.port=%my.rmi.port%
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false]]></source>
<p>If you don't set <code>com.sun.management.jmxremote.rmi.port</code> then the
JSR 160 JMX-Adaptor will select a port at random which will may it difficult to
configure a firewall to allow access.</p>
<p>If you require TLS:</p>
<ol>
<li>change and add this:
<source><![CDATA[ -Dcom.sun.management.jmxremote.ssl=true
-Dcom.sun.management.jmxremote.registry.ssl=true
]]></source></li>
<li>to configure the protocols and/or cipher suites use:
<source><![CDATA[ -Dcom.sun.management.jmxremote.ssl.enabled.protocols=%my.jmx.ssl.protocols%
-Dcom.sun.management.jmxremote.ssl.enabled.cipher.suites=%my.jmx.cipher.suites%
]]></source></li>
<li>to client certificate authentication use:
<source><![CDATA[ -Dcom.sun.management.jmxremote.ssl.need.client.auth=%my.jmx.ssl.clientauth%]]></source></li>
</ol>
<p>If you require authorization (it is strongly recommended that TLS is always
used with authentication):</p>
<ol>
<li>change and add this:
<source><![CDATA[ -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 authorization file <em>$CATALINA_BASE/conf/jmxremote.access</em>:
<source><![CDATA[monitorRole readonly
controlRole readwrite]]></source>
</li>
<li>edit the password file <em>$CATALINA_BASE/conf/jmxremote.password</em>:
<source><![CDATA[monitorRole tomcat
controlRole tomcat]]></source>
<b>Tip</b>: The password file should be read-only and only accessible by the
operating system user Tomcat is running as.
</li>
<li>Alternatively, you can configure a JAAS login module with:
<source><![CDATA[ -Dcom.sun.management.jmxremote.login.config=%login.module.name%]]></source></li>
</ol>
<p>If you need to specify a host name to be used in the RMI stubs sent to the
client (e.g. because the public host name that must be used to connect is not
the same as the local host name) then you can set:</p>
<source><![CDATA[set CATALINA_OPTS=-Djava.rmi.server.hostname]]></source>
<p>If you need to specify a specific interface for the JMX service to bind to
then you can set:</p>
<source><![CDATA[set CATALINA_OPTS=-Dcom.sun.management.jmxremote.host]]></source>
</section>
<section name="Manage Tomcat with JMX remote Ant Tasks">
<p>To simplify JMX usage with Ant, a set of tasks is provided that may
be used with antlib.</p>
<p><b>antlib</b>: Copy your catalina-ant.jar from $CATALINA_HOME/lib to $ANT_HOME/lib.</p>
<p>The following example shows the JMX Accessor usage:<br/>
<em>Note:</em> The <code>name</code> attribute value was wrapped here to be
more readable. It has to be all on the same line, without spaces.</p>
<source><![CDATA[<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.original</em>
-->
<jmx:get
name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
attribute="maxActiveSessions"
resultproperty="clustertest.maxActiveSessions.original"
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>]]></source>
<p><b>import:</b> Import the JMX Accessor Project with
<em><import file="${CATALINA.HOME}/bin/catalina-tasks.xml" /></em> and
reference the tasks with <em>jmxOpen</em>, <em>jmxSet</em>, <em>jmxGet</em>,
<em>jmxQuery</em>, <em>jmxInvoke</em>, <em>jmxEquals</em> and <em>jmxCondition</em>.</p>
</section>
<!-- Open #########################################################################
-->
<section name="JMXAccessorOpenTask - JMX open connection task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>url</td>
<td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
</td>
<td></td>
</tr>
<tr>
<td>host</td>
<td>Set the host, shortcut the very long URL syntax.
</td>
<td><code class="noHighlight">localhost</code></td>
</tr>
<tr>
<td>port</td>
<td>Set the remote connection port
</td>
<td><code class="noHighlight">8050</code></td>
</tr>
<tr>
<td>username</td>
<td>remote JMX connection user name.
</td>
<td></td>
</tr>
<tr>
<td>password</td>
<td>remote JMX connection password.
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>Name of the internal connection reference. With this attribute you can
configure more the one connection inside the same Ant project.
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo the command usage (for access analysis or debugging)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>if</td>
<td>Only execute if a property of the given name <b>exists</b> in the current project.
</td>
<td></td>
</tr>
<tr>
<td>unless</td>
<td>Only execute if a property of the given name <b>not exists</b> in the current project.
</td>
<td></td>
</tr>
</table>
<p>
Example to open a new JMX connection
</p>
<source><![CDATA[ <jmx:open
host="${jmx.server.name}"
port="${jmx.server.port}"
/>]]></source>
<p>
Example to open a JMX connection from URL, with authorization and
store at other reference
</p>
<source><![CDATA[ <jmx:open
url="service:jmx:rmi:///jndi/rmi://localhost:9024/jmxrmi"
ref="jmx.server.9024"
username="controlRole"
password="tomcat"
/>]]></source>
<p>
Example to open a JMX connection from URL, with authorization and
store at other reference, but only when property <em>jmx.if</em> exists and
<em>jmx.unless</em> not exists
</p>
<source><![CDATA[ <jmx:open
url="service:jmx:rmi:///jndi/rmi://localhost:9024/jmxrmi"
ref="jmx.server.9024"
username="controlRole"
password="tomcat"
if="jmx.if"
unless="jmx.unless"
/>]]></source>
<p><b>Note</b>: All properties from <em>jmxOpen</em> task also exists at all
other tasks and conditions.
</p>
</section>
<!-- Get #########################################################################
-->
<section name="JMXAccessorGetTask: get attribute value Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
</td>
<td></td>
</tr>
<tr>
<td>attribute</td>
<td>Existing MBean attribute (see Tomcat MBean description above)
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>resultproperty</td>
<td>Save result at this project property
</td>
<td></td>
</tr>
<tr>
<td>delimiter</td>
<td>Split result with delimiter (java.util.StringTokenizer)
and use resultproperty as prefix to store tokens.
</td>
<td></td>
</tr>
<tr>
<td>separatearrayresults</td>
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
</td>
<td><code class="noHighlight">true</code></td>
</tr>
</table>
<p>
Example to get remote MBean attribute from default JMX connection
</p>
<source><![CDATA[ <jmx:get
name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
attribute="maxActiveSessions"
resultproperty="servlets-examples.maxActiveSessions"
/>]]></source>
<p>
Example to get and result array and split it at separate properties
</p>
<source><![CDATA[ <jmx:get
name="Catalina:type=ClusterSender,host=localhost"
attribute="senderObjectNames"
resultproperty="senderObjectNames"
/>]]></source>
<p>
Access the senderObjectNames properties with:
</p>
<source><![CDATA[ ${senderObjectNames.length} give the number of returned sender list.
${senderObjectNames.[0..N]} found all sender object names]]></source>
<p>
Example to get IDataSender attribute connected only when cluster is configured.<br/>
<em>Note:</em> The <code>name</code> attribute value was wrapped here to be
more readable. It has to be all on the same line, without spaces.
</p>
<source><![CDATA[
<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>
</section>
<!-- Set #########################################################################
-->
<section name="JMXAccessorSetTask: set attribute value Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
</td>
<td></td>
</tr>
<tr>
<td>attribute</td>
<td>Existing MBean attribute (see Tomcat MBean description above)
</td>
<td></td>
</tr>
<tr>
<td>value</td>
<td>value that set to attribute
</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>type of the attribute.
</td>
<td><code class="noHighlight">java.lang.String</code></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
</table>
<p>
Example to set remote MBean attribute value
</p>
<source><![CDATA[ <jmx:set
name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
attribute="maxActiveSessions"
value="500"
type="int"
/>]]></source>
</section>
<!-- Invoke #########################################################################
-->
<section name="JMXAccessorInvokeTask: invoke MBean operation Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
</td>
<td></td>
</tr>
<tr>
<td>operation</td>
<td>Existing MBean operation
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>resultproperty</td>
<td>Save result at this project property
</td>
<td></td>
</tr>
<tr>
<td>delimiter</td>
<td>Split result with delimiter (java.util.StringTokenizer)
and use resultproperty as prefix to store tokens.
</td>
<td></td>
</tr>
<tr>
<td>separatearrayresults</td>
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
</td>
<td><code class="noHighlight">true</code></td>
</tr>
</table>
<p>
stop an application
</p>
<source><![CDATA[ <jmx:invoke
name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
operation="stop"/>]]></source>
<p>
Now you can find the sessionid at <em>${sessions.[0..N}</em> properties and access the count
with ${sessions.length} property.
</p>
<p>
Example to get all sessionids
</p>
<source><![CDATA[ <jmx:invoke
name="Catalina:type=Manager,context=/servlets-examples,host=localhost"
operation="listSessionIds"
resultproperty="sessions"
delimiter=" "
/>]]></source>
<p>
Now you can find the sessionid at <em>${sessions.[0..N}</em> properties and access the count
with ${sessions.length} property.
</p>
<p>
Example to get remote MBean session attribute from session ${sessionid.0}
</p>
<source><![CDATA[ <jmx:invoke
name="Catalina:type=Manager,context=/ClusterTest,host=localhost"
operation="getSessionAttribute"
resultproperty="hello">
<arg value="${sessionid.0}"/>
<arg value="Hello" />
</jmx:invoke>]]></source>
<p>
Example to create a new access logger valve at vhost <em>localhost</em>
</p>
<source><![CDATA[ <jmx:invoke
name="Catalina:type=MBeanFactory"
operation="createAccessLoggerValve"
resultproperty="accessLoggerObjectName"
>
<arg value="Catalina:type=Host,host=localhost"/>
</jmx:invoke>]]></source>
<p>
Now you can find new MBean with name stored at <em>${accessLoggerObjectName}</em>
property.
</p>
</section>
<!-- Query #########################################################################
-->
<section name="JMXAccessorQueryTask: query MBean Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>JMX ObjectName query string -- <em>Catalina:type=Manager,*</em>
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>resultproperty</td>
<td>Prefix project property name to all founded MBeans (<em>mbeans.[0..N].objectname</em>)
</td>
<td></td>
</tr>
<tr>
<td>attributebinding</td>
<td>bind ALL MBean attributes in addition to <em>name</em>
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>delimiter</td>
<td>Split result with delimiter (java.util.StringTokenizer)
and use resultproperty as prefix to store tokens.
</td>
<td></td>
</tr>
<tr>
<td>separatearrayresults</td>
<td>When return value is an array, save result as property list
(<em>$resultproperty.[0..N]</em> and <em>$resultproperty.length</em>)
</td>
<td><code class="noHighlight">true</code></td>
</tr>
</table>
<p>
Get all Manager ObjectNames from all services and Hosts
</p>
<source><![CDATA[ <jmx:query
name="Catalina:type=Manager,*
resultproperty="manager" />]]></source>
<p>
Now you can find the Session Manager at <em>${manager.[0..N].name}</em>
properties and access the result object counter with ${manager.length} property.
</p>
<p>
Example to get the Manager from <em>servlet-examples</em> application an bind all MBean properties
</p>
<source><![CDATA[ <jmx:query
name="Catalina:type=Manager,context=/servlet-examples,host=localhost*"
attributebinding="true"
resultproperty="manager.servletExamples" />]]></source>
<p>
Now you can find the manager at <em>${manager.servletExamples.0.name}</em> property
and can access all properties from this manager with <em>${manager.servletExamples.0.[manager attribute names]</em>}.
The result object counter from MBeans is stored ad ${manager.length} property.
</p>
<p>
Example to get all MBeans from a server and store inside an external XML property file
</p>
<source><![CDATA[<project name="jmx.query"
xmlns:jmx="antlib:org.apache.catalina.ant.jmx"
default="query-all" basedir=".">
<property name="jmx.host" value="localhost"/>
<property name="jmx.port" value="8050"/>
<property name="jmx.username" value="controlRole"/>
<property name="jmx.password" value="tomcat"/>
<target name="query-all" description="Query all MBeans of a server">
<!-- Configure connection -->
<jmx:open
host="${jmx.host}"
port="${jmx.port}"
ref="jmx.server"
username="${jmx.username}"
password="${jmx.password}"/>
<!-- Query MBean list -->
<jmx:query
name="*:*"
resultproperty="mbeans"
attributebinding="false"/>
<echoproperties
destfile="mbeans.properties"
prefix="mbeans."
format="xml"/>
<!-- Print results -->
<echo message=
"Number of MBeans in server ${jmx.host}:${jmx.port} is ${mbeans.length}"/>
</target>
</project>]]></source>
<p>
Now you can find all MBeans inside the file <em>mbeans.properties</em>.
</p>
</section>
<!-- Create #########################################################################
-->
<section name="JMXAccessorCreateTask: remote create MBean Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=MBeanFactory</em>
</td>
<td></td>
</tr>
<tr>
<td>className</td>
<td>Existing MBean full qualified class name (see Tomcat MBean description above)
</td>
<td></td>
</tr>
<tr>
<td>classLoader</td>
<td>ObjectName of server or web application classloader <br/>
( <em>Catalina:type=ServerClassLoader,name=[server,common,shared]</em> or<br/>
<em>Catalina:type=WebappClassLoader,context=/myapps,host=localhost</em>)
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
</table>
<p>
Example to create remote MBean
</p>
<source><![CDATA[ <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>
<b>Warning</b>: Many Tomcat MBeans can't be linked to their parent once<br/>
created. The Valve, Cluster and Realm MBeans are not automatically<br/>
connected with their parent. Use the <em>MBeanFactory</em> create<br/>
operation instead.
</p>
</section>
<!-- Unregister #########################################################################
-->
<section name="JMXAccessorUnregisterTask: remote unregister MBean Ant task">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=MBeanFactory</em>
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>JMX Connection reference
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>echo</td>
<td>Echo command usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
</table>
<p>
Example to unregister remote MBean
</p>
<source><![CDATA[ <jmx:unregister
name="Catalina:type=MBeanFactory"
/>]]></source>
<p>
<b>Warning</b>: A lot of Tomcat MBeans can't be unregister.<br/>
The MBeans are not unlinked from their parent. Use <em>MBeanFactory</em><br/>
remove operation instead.
</p>
</section>
<!-- condition #########################################################################
-->
<section name="JMXAccessorCondition: express condition">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>url</td>
<td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
</td>
<td></td>
</tr>
<tr>
<td>host</td>
<td>Set the host, shortcut the very long URL syntax.
</td>
<td><code class="noHighlight">localhost</code></td>
</tr>
<tr>
<td>port</td>
<td>Set the remote connection port
</td>
<td><code class="noHighlight">8050</code></td>
</tr>
<tr>
<td>username</td>
<td>remote JMX connection user name.
</td>
<td></td>
</tr>
<tr>
<td>password</td>
<td>remote JMX connection password.
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>Name of the internal connection reference. With this attribute you can
configure more the one connection inside the same Ant project.
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>Echo condition usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
<tr>
<td>if</td>
<td>Only execute if a property of the given name <b>exists</b> in the current project.
</td>
<td></td>
</tr>
<tr>
<td>unless</td>
<td>Only execute if a property of the given name <b>not exists</b> in the current project.
</td>
<td></td>
</tr>
<tr>
<td>value (required)</td>
<td>Second arg for operation
</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>Value type to express operation (support <em>long</em> and <em>double</em>)
</td>
<td><code class="noHighlight">long</code></td>
</tr>
<tr>
<td>operation</td>
<td> express one
<ul>
<li>== equals</li>
<li>!= not equals</li>
<li>> greater than (&gt;)</li>
<li>>= greater than or equals (&gt;=)</li>
<li>< lesser than (&lt;)</li>
<li><= lesser than or equals (&lt;=)</li>
</ul>
</td>
<td><code class="noHighlight">==</code></td>
</tr>
</table>
<p>
Wait for server connection and that cluster backup node is accessible
</p>
<source><![CDATA[<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>
</section>
<!-- Equals #########################################################################
-->
<section name="JMXAccessorEqualsCondition: equals MBean Ant condition">
<p>
List of Attributes
</p>
<table class="defaultTable">
<tr>
<th>Attribute</th>
<th>Description</th>
<th>Default value</th>
</tr>
<tr>
<td>url</td>
<td>Set JMX connection URL - <em>service:jmx:rmi:///jndi/rmi://localhost:8050/jmxrmi</em>
</td>
<td></td>
</tr>
<tr>
<td>host</td>
<td>Set the host, shortcut the very long URL syntax.
</td>
<td><code class="noHighlight">localhost</code></td>
</tr>
<tr>
<td>port</td>
<td>Set the remote connection port
</td>
<td><code class="noHighlight">8050</code></td>
</tr>
<tr>
<td>username</td>
<td>remote JMX connection user name.
</td>
<td></td>
</tr>
<tr>
<td>password</td>
<td>remote JMX connection password.
</td>
<td></td>
</tr>
<tr>
<td>ref</td>
<td>Name of the internal connection reference. With this attribute you can
configure more the one connection inside the same Ant project.
</td>
<td><code class="noHighlight">jmx.server</code></td>
</tr>
<tr>
<td>name</td>
<td>Full qualified JMX ObjectName -- <em>Catalina:type=Server</em>
</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>Echo condition usage (access and result)
</td>
<td><code class="noHighlight">false</code></td>
</tr>
</table>
<p>
Wait for server connection and that cluster backup node is accessible
</p>
<source><![CDATA[<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>
</section>
<section name="Using the JMXProxyServlet">
<p>
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
<a href="api/org/apache/catalina/manager/JMXProxyServlet.html">JMXProxyServlet</a>.
</p>
<p>
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:
</p>
<ul>
<li>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 running server</li>
<li>You don't have to know how to work with JMX connections</li>
<li>You don't need any of the complex configuration covered in the rest
of this page</li>
<li>Your client program does not have to be written in Java</li>
</ul>
<p>
A perfect example of JMX overkill can be seen in the case of popular
server-monitoring software such as Nagios or Icinga: 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.
</p>
<p>
You can find out more information about the JMXProxyServlet in the
documentation for the
<a href="manager-howto.html#Using_the_JMX_Proxy_Servlet">Tomcat
manager</a>.
</p>
</section>
</body>
</document>
|