[Zabbix 4.2 Learning Notes] 8. Data Collection - JMX Agent

Keywords: Zabbix Java Tomcat Apache

JMX Agent is used to monitor the application of java class

JMX Agent can realize the standardization and application management of various operating systems, system architecture, network protocols.

Server side configuration:

JAVA Gateway needs to be started when zabbix server is installed
zabbix server configuration starts JAVA Gateway
zabbix server configures JAVA Gateway/JAVA Gateway Port parameters
zabbix server configures Start Java Pollers parameters
Ensuring IP+Port Communication between zabbix server and JMX Applications

Configuration of monitored end:

Open and configure JMX correctly

Data collection process

Zabbix Server initiates data acquisition requests to Zabbix Java Gateway components. Java Gateway receives requests and initiates data requests to monitored Java applications.
The monitored end receives the request and responds to the corresponding monitoring data. When Zabbix Java Gateway receives data, it returns it to Zabbix Server.

Check to see if JavaGateway is installed on the Server side
[root@localhost ~]# rpm -qa|grep zabbix

If it is not installed, install command:
yum -y install zabbix-java-gateway-4.2.6-1.el7.x86_64
You can also use yum to find installation packages
yum search zabbix
Change the configuration file of ZABBIX JavaGateway
[root@localhost zabbix]# grep ^[a-Z] /etc/zabbix/zabbix_java_gateway.conf 
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java.pid"
START_POLLERS=5
TIMEOUT=3
JAVA_OPTIONS="$JAVA_OPTIONS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345
start-up zabbix JavaGateway
[root@localhost ~]# systemctl start zabbix-java-gateway.service
[root@localhost ~]# systemctl status zabbix-java-gateway.service
● zabbix-java-gateway.service - Zabbix Java Gateway
   Loaded: loaded (/usr/lib/systemd/system/zabbix-java-gateway.service; disabled; vendor preset: disabled)
   Active: active (running) since Two 2019-09-17 21:00:41 CST; 10s ago
  Process: 24955 ExecStart=/usr/sbin/zabbix_java_gateway (code=exited, status=0/SUCCESS)
 Main PID: 24959 (java)
   CGroup: /system.slice/zabbix-java-gateway.service
           └─24959 java -server -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremot...

9 Month 1721:00:39 localhost.localdomain systemd[1]: Starting Zabbix Java Gateway...
9 Month 1721:00:41 localhost.localdomain systemd[1]: Started Zabbix Java Gateway.
Change the Zabbix Server configuration file
[root@localhost zabbix]# grep ^[a-Z] /etc/zabbix/zabbix_server.conf 
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
StartTrappers=10
JavaGateway=192.168.146.133
JavaGatewayPort=10052
StartJavaPollers=5
SNMPTrapperFile=/tmp/zabbix_traps.tmp
StartSNMPTrapper=1
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
SSHKeyLocation=/home/zabbix/.ssh
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
Check if the Java pollers process is enabled
[root@localhost ~]# ps -aux|grep java
zabbix    24959  0.7  1.7 3369484 51500 ?       Sl   21:00   0:02 java -server -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -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.2.6.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java.pid -Dzabbix.startPollers=5 -Dsun.rmi.transport.tcp.responseTimeout=3000 com.zabbix.gateway.JavaGateway
zabbix    25593  0.0  0.1 164224  3660 ?        S    21:05   0:00 /usr/sbin/zabbix_server: java poller #1 [got 0 values in 0.000071 sec, idle 5 sec]
zabbix    25594  0.0  0.1 164224  3660 ?        S    21:05   0:00 /usr/sbin/zabbix_server: java poller #2 [got 0 values in 0.000015 sec, idle 5 sec]
zabbix    25595  0.0  0.1 164224  3660 ?        S    21:05   0:00 /usr/sbin/zabbix_server: java poller #3 [got 0 values in 0.000015 sec, idle 5 sec]
zabbix    25596  0.0  0.1 164224  3660 ?        S    21:05   0:00 /usr/sbin/zabbix_server: java poller #4 [got 0 values in 0.000030 sec, idle 5 sec]
zabbix    25597  0.0  0.1 164224  3660 ?        S    21:05   0:00 /usr/sbin/zabbix_server: java poller #5 [got 0 values in 0.000047 sec, idle 5 sec]
root      25707  0.0  0.0 112724   984 pts/1    S+   21:06   0:00 grep --color=auto java
Install jdk1.8.0 on the agent side
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@localhost ~]# which java
/usr/bin/java
Add jdk environment variables
[root@localhost ~]# vim /etc/profile
//Add the last line
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

[root@localhost ~]# source /etc/profile
[root@localhost ~]# echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64
Download and install Tomcat
[root@localhost data]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.45/bin/apache-tomcat-8.5.45.tar.gz
--2019-09-17 20:25:01--  http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.45/bin/apache-tomcat-8.5.45.tar.gz
//The host mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1:
//Connecting mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:80... Connected.
//HTTP request has been issued, waiting for response... 200 OK
//Length: 9722154 (9.3M) [application/octet-stream]
//Save to "apache-tomcat-8.5.45.tar.gz"

100%[======================================================================>] 9,722,154   2.14MB/s Use time 4.3s   

2019-09-17 20:25:05 (2.14 MB/s) - Preserved“ apache-tomcat-8.5.45.tar.gz" [9722154/9722154])
Unzip and start Tomcat
[root@localhost]# mkdir /data
[root@localhost]# cd /data
[root@localhost data]# tar xvf apache-tomcat-8.5.45.tar.gz
[root@localhost data]# cd bin/
[root@localhost bin]# ./startup.sh 
View Tomcat logs, processes
[root@localhost data]# vim ../logs/catalina.out
[root@localhost data]# ps aux|grep tomcat
Configure Tomcat to enable JMX
[root@localhost data]# vim /data/apache-tomcat-8.5.45/bin/catalina.sh
CATALINA_OPTS="$CATALINA_OPTS
-Djavax.management.builder.initial=
-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=192.168.146.134"
Restart Tomcat
[root@localhost bin]# ./shutdown.sh 
[root@localhost bin]# ./startup.sh

Create monitoring items on the front end of ZABBIX Web Management

Firstly, the monitoring interface corresponding to JMX is added to the host.


In the latest data, you can see that monitoring data has been obtained.


Welcome to pay attention to the public number. Communicate and learn together

Posted by accu on Mon, 30 Sep 2019 05:59:55 -0700