tomcatのJVM監視方法について

tomcatのJVMのメモリ監視を行いたいと考えております。
zabbix-java-gatewayを監視対象サーバにインストールし、監視を行おうとしているのですが、
ホストのコネクションが上手くいかず、ご相談させていただきたいです。

◆エラー内容
non-JRMP server at remote endpoint: service:jmx:rmi:///jndi/rmi://172.17.3.6:10052/jmxrm

◆環境について
zabbixサーバのIP:172.17.4.5
監視対象サーバのIP:172.17.3.6

◆ zabbix サーバの設定
diff /etc/zabbix/zabbix_server.conf{,.back}
290d289
< JavaGateway=172.17.3.6
299d297
< JavaGatewayPort=10052
308d305
< StartJavaPollers=5
systemctl restart zabbix-server

◆ zabbix GUIでのホスト設定
添付ファイルの画像「zabbix-settings.jpg」

◆ JVM監視対象サーバの設定
# diff /etc/zabbix/zabbix_java_gateway.conf{,.back}
10d9
< LISTEN_IP="172.17.3.6"
19d17
< LISTEN_PORT=10052
38d35
< START_POLLERS=5
51,52d47
< JAVA_OPTIONS="$JAVA_OPTIONS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10053 -Djava.rmi.server.hostname=172.17.4.5

お手数ですが、ご確認よろしくお願い致します。

コメント表示オプション

お好みのコメント表示方法を選び「設定の保存」をクリックすると変更が反映されます。
ユーザー TNK の写真

Zabbix Java gatewayはホストとして登録するものではありません。
以下のような構成で機能します。

 Zabbixサーバー <-> Zabbix Java gateway <-> Tomcatを稼働しているサーバー

Zabbix Java gatewayへ接続するための情報は、Zabbixサーバーの
設定ファイルに記載するだけです。

あとは、Tomcatを稼働しているサーバーを通常のホストを登録し、
そのホストのJMXインターフェースには、Tomcat起動時にJMXでのア
クセスができるように設定した時のIPとポート番号を登録します。

使用されているZabbixのバージョンがわからないので、4.0のマニ
ュアルですが、以下のURLの内容もご確認ください。

https://www.zabbix.com/documentation/4.0/manual/config/items/itemtypes/j...
https://www.zabbix.com/documentation/4.0/manual/concepts/java

ご参考までに、ポート番号がぶつからず、負荷的にも問題が無いな
らば、Zabbixサーバーを稼働しているサーバー上にZabbix Java
gatewayを稼働させることもできます。
本番環境で本格的に監視するのであれば、サーバーを分けておいた
方が良いと思いますが、ご参考まで。

ユーザー mokokko の写真

TKNさん

ご確認ありがとうございます。また参考リンクのご教示も誠にありがとうございます。
#利用しているzabbixのバージョンは4の最新で合っております

zabbixサーバにzabbix-java-gatewayを稼働させる方針とし、
以下設定を実施致しました。

◆zabbixサーバー側の設定
# diff /etc/zabbix/zabbix_server.conf{,.back}
< JavaGateway=127.0.0.1
< JavaGatewayPort=10052
< StartJavaPollers=5

# diff /etc/zabbix/zabbix_java_gateway.conf{,.back}
< LISTEN_IP="127.0.0.1"
< LISTEN_PORT=10052

◆監視対象側の設定
javaアプリケーション起動コマンドに、以下オプションを追加
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=172.17.4.5 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

zabbix GUI上で、監視対象アプリケーションが動いているホストを登録し、
JMXインターフェースの設定も追記致しました
IPアドレス:172.17.3.6
ポート: 12345

しかし、ホスト一覧に表示されるエージェントの状態 が、灰色のまま、変更されません(1hほど。。)
こちら原因わかりますでしょうか?

初歩的なご質問ばかりで大変恐縮ですが、
ご確認よろしくお願い致します。

ユーザー yk_taiko の写真

アイテムも設定されましたか?

今、手元にjvm監視を試せる環境が無いので確かめられていないですが、
Zabbixエージェント監視では実際にエージェントを使ったアイテムが動かないと色が変わらないです。

ユーザー mokokko の写真

yk_taikoさん

ご確認ありがとうございます。
アイテム設定致しました!結果、赤色が表示されました。。

cannot connect to [[172.17.3.6]:10052]: [111] Connection refused

エラーから、zabbix_server ⇔ zabbix java gateway間を10052で通信しており、
そこが上手くいっていないということだと理解したのですが、
(zabbix java gateway ⇔ 監視対象java 間の問題ではなく)
設定ミスがわからず、、、

お手数ですが、原因わかりますでしょうか?

# zabbix_java_gatewayがZabbixサーバー上で起動されてはいます。
$ ps auxf | grep zabbix_java_gateway
adminus+ 121802 0.0 0.0 112704 956 pts/0 S+ 18:22 0:00 \_ grep --color=auto zabbix_java_gateway
zabbix 117217 0.0 0.6 4056904 47860 ? Sl 16:42 0:04 java -server -Dlogback.configurationFile=/etc/zabbix/zabbix_java_gateway_logback.xml -classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-0.9.27.jar:lib/logback-core-0.9.27.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-4.0.1.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java.pid -Dzabbix.listenIP=127.0.0.1 -Dzabbix.listenPort=10052 -Dsun.rmi.transport.tcp.responseTimeout=3000 com.zabbix.gateway.JavaGateway

ユーザー yk_taiko の写真

zabbixサーバとかjavagatewayのログには何か出てないですか。
デフォルトだと、/var/log/zabbix/ 配下にできるようです。

ユーザー yk_taiko の写真

エラー内容のIPは「172.17.3.6」ですね
Zabbixサーバの設定変更後、サービスの再起動はされましたか?

ユーザー mokokko の写真

ご確認ありがとうございます。

zabbix_server -R config_cache_reload
こちらのリロードは行いましたが、サービスの再起動はしていないため、
zabbix_serverとzabbix_java_gatewayを再起動してみました。

ログは、どちらもエラーのようなものは吐かれておりませんでした。。

◆zabbix_java_gateway
2018-11-14 18:59:42.103 [Thread-0] INFO com.zabbix.gateway.JavaGateway - Zabbix Java Gateway 4.0.1 (revision 86073) has stopped
2018-11-14 18:59:42.769 [main] INFO com.zabbix.gateway.JavaGateway - Zabbix Java Gateway 4.0.1 (revision 86073) has started
2018-11-14 18:59:42.776 [main] INFO com.zabbix.gateway.JavaGateway - listening on /127.0.0.1:10052

◆zabbix_server
123424:20181114:185942.210 ******************************
123424:20181114:185942.210 using configuration file: /etc/zabbix/zabbix_server.conf
123424:20181114:185942.321 current database version (mandatory/optional): 04000000/04000000
123424:20181114:185942.321 required mandatory version: 04000000
123424:20181114:185942.416 server #0 started [main process]
123425:20181114:185942.417 server #1 started [configuration syncer #1]
123426:20181114:185942.417 server #2 started [alerter #1]
123427:20181114:185942.418 server #3 started [alerter #2]
123428:20181114:185942.418 server #4 started [alerter #3]
123429:20181114:185942.419 server #5 started [housekeeper #1]
123430:20181114:185942.419 server #6 started [timer #1]
123431:20181114:185942.420 server #7 started [http poller #1]
123432:20181114:185942.420 server #8 started [discoverer #1]
123433:20181114:185942.436 server #9 started [history syncer #1]
123435:20181114:185942.437 server #11 started [history syncer #3]
123434:20181114:185942.437 server #10 started [history syncer #2]
123436:20181114:185942.437 server #12 started [history syncer #4]
123438:20181114:185942.438 server #14 started [java poller #1]
123439:20181114:185942.441 server #15 started [java poller #2]
123458:20181114:185942.441 server #34 started [alert manager #1]
123450:20181114:185942.442 server #26 started [poller #5]
123441:20181114:185942.444 server #17 started [java poller #4]
123443:20181114:185942.446 server #19 started [proxy poller #1]
123445:20181114:185942.449 server #21 started [task manager #1]
123446:20181114:185942.450 server #22 started [poller #1]
123451:20181114:185942.461 server #27 started [unreachable poller #1]
123447:20181114:185942.462 server #23 started [poller #2]
123449:20181114:185942.472 server #25 started [poller #4]
123452:20181114:185942.475 server #28 started [trapper #1]
123453:20181114:185942.477 server #29 started [trapper #2]
123442:20181114:185942.480 server #18 started [java poller #5]
123444:20181114:185942.483 server #20 started [self-monitoring #1]
123437:20181114:185942.483 server #13 started [escalator #1]
123459:20181114:185942.483 server #35 started [preprocessing manager #1]
123454:20181114:185942.484 server #30 started [trapper #3]
123448:20181114:185942.485 server #24 started [poller #3]
123457:20181114:185942.486 server #33 started [icmp pinger #1]
123440:20181114:185942.496 server #16 started [java poller #3]
123455:20181114:185942.499 server #31 started [trapper #4]
123456:20181114:185942.501 server #32 started [trapper #5]
123462:20181114:185943.144 server #38 started [preprocessing worker #3]
123460:20181114:185943.145 server #36 started [preprocessing worker #1]
123461:20181114:185943.185 server #37 started [preprocessing worker #2]

ちなみに、zabbix-java-gatewayが動いているサーバの10052ポートは以下の状態です。
[xxxxx@zabbix-server ~]# netstat -natp | grep 10052
tcp6 0 0 127.0.0.1:10052 :::* LISTEN 123467/java

ユーザー mokokko の写真

連投失礼致します。
zabbix_server.confのJavaGateway設定値が間違っておりました。
修正後の設定は以下です。

◆環境について
・zabbix-serverが稼働しているサーバのIP:172.17.4.5
 ※ zabbix-java-gatewayはzabbiz-serverと同一サーバに起動
・監視対象のJavaアプリケーションが動いているサーバのIP:172.17.3.6

◆zabbixサーバー側の設定
# diff /etc/zabbix/zabbix_server.conf{,.back}
< JavaGateway=127.0.0.1
< JavaGatewayPort=10052
< StartJavaPollers=5

# diff /etc/zabbix/zabbix_java_gateway.conf{,.back}
< LISTEN_IP="127.0.0.1"
< LISTEN_PORT=10052

◆監視対象側の設定
javaアプリケーション起動コマンドに、以下オプションを追加
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

結果、エラー内容以下に変わりました

Connection refused (Connection refused): service:jmx:rmi:///jndi/rmi://172.17.3.6:12345/jmxrmi

こちらのエラーがでる原因の検討つきますでしょうか、、?

なお
・Javaアプリケーションサーバ側で12345ポートはListenしておりました。
# netstat -nap|grep 12345
tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 66347/java

・iptablesの設定も問題では無さそうでした。
[root@dashboard-web-app01 ~]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

・firewallは起動されていません
[root@dashboard-web-app01 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

お手数おかけいたしますが、ご確認よろしくお願い致します。

1.zabbix_server.conf

JavaGateway=127.0.0.1
JavaGatewayPort=10052
StartJavaPollers=3

弄るのはこの辺りだけ<zabbix-serverと同居させてますので、IPはローカル

2.zabbix_java_gateway.conf

ノータッチ。強いて言えば、TIMEOUTくらい必要に応じて

で、両プロセス再起動でOK

上記まで済んでいれば、後は監視対象側のOS(iptable/selinux)か、JMX設定が問題です。

http://komeiy.hatenablog.com/entry/2015/02/04/232659

上記のURLの下部にあるcmdline-clientで値が取れているか確認してみてください
即興でZABBIX4.0のテスト機にjava-gateway入れて、対向監視対象にTomcatを起動してやってみましたが、
普通に取れます<面倒なので、JMXの認証とかは全てfalseですっ飛ばしてます
尚、Tomcatの場合、RIMポート問題があるのでiptables解放には要注意です

 ※http://www.zabbix.jp/node/3922

・・・cmdline-jmxclientですね。タイプミスりました・・・

ユーザー mokokko の写真

wakabe様

ご確認いただき、誠にありがとうございます。
zabbix-java-gatewayがzabbix-serverと同居している場合、
confの設定はデフォルトのままで良かったのですね。。
ありがとうございます。

また、ご教示頂いた「cmdline-jmxclient」を利用してみました。
結果、zabbixサーバからJavaサーバへリクエストを飛ばすと、タイムアウトエラーが発生致しました。

◆ Javaアプリケーションが起動しているサーバで実行
java -jar cmdline-jmxclient-0.10.3.jar - 127.0.0.1:12345
→ データが得られた

◆zabbixサーバ上で実行
java -jar cmdline-jmxclient-0.10.3.jar - 172.17.3.6:12345
→ タイムアウトエラー
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 172.17.3.6; nested exception is:
java.net.ConnectException: Connection timed out (Connection timed out)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy0.newClient(Unknown Source)
at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2430)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:308)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
at org.archive.jmx.Client.execute(Client.java:225)
at org.archive.jmx.Client.main(Client.java:154)
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.(Socket.java:434)
at java.net.Socket.(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)

zabbixサーバからJavaアプリケーション起動サーバへport:12345でtelnetでの接続は出来るため、
JMXのリモート接続が上手くいっていないのでしょうか。。。
# telnet 172.17.3.6 12345
Trying 172.17.3.6...
Connected to 172.17.3.6.
Escape character is '^]'.

Javaアプリケーションの起動コマンド全貌は以下です。(psの結果)
root 66347 4.2 8.4 10692584 2773016 pts/0 Sl Nov14 5:01
/usr/lib/jvm/java-1.8.0-openjdk/bin/java -Djava.util.logging.config.file=/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Dfile.encoding=UTF8
-Djava.net.preferIPv4Stack=true
-Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false
-Duser.timezone=JST
-Xms4096m -Xmx4096m -XX:MaxPermSize=384m
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Djava.rmi.server.hostname=172.17.3.6
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.endorsed.dirs=/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32/endorsed
-classpath /opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32/bin/bootstrap.jar:/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32/bin/tomcat-juli.jar
-Dcatalina.base=/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32
-Dcatalina.home=/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32
-Djava.io.tmpdir=/opt/liferay/liferay-dxp-digital-enterprise-7.0-sp7/tomcat-8.0.32/temp
org.apache.catalina.startup.Bootstrap start

現在、監視対象側のSELinuxは(原因切り分けのため)無効にしております。
# sestatus
SELinux status: disabled

何かお気づきの点ございましたら
お手数おかけいたしますが、ご教示いただけますと助かります。。。

よろしくお願い致します。

Zabbixサーバからcmdline-jmxclientを行いエラーが出るってことは、Tomcat側の設定に不備があるということです
尚、Telnetはこの際関係ありません。ポートが開いてれば接続出来ている様に見えるだけに過ぎません

ちなみに、私の場合はTomcatプロセス(psコマンド)は以下の通りです
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.rmi.port=12345
-Djava.rmi.server.hostname=<IPアドレス>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

若干異なる様に見られます。
あと、もう1点。JMXの場合の盲点として、ホスト名が返すIPが127.0.0.1の場合も正常に働きません。
「hostname -i」で127.0.0.1を返すようなら、/etc/hosts編集して、172.17.3.6を返す様にしてください。

https://docs.oracle.com/javase/jp/6/technotes/guides/management/faq.html...

ユーザー mokokko の写真

wakaba 様

ご確認ありがとうございます。
以下2点の対応で、無事データが取れるようになりました。
・ -Dcom.sun.management.jmxremote → -Dcom.sun.management.jmxremote=true に変更
・ hostname -i が違うIPを返していたため、hostsを編集し172.17.3.6を返すよう設定

後半、もはやzabbixの話ではなくなっていたにもかかわらず、
ご確認ただけましたこと、誠にありがとうございます。