zabbix监控JVM

01

使用zabbix-java-gateway监控tomcat

        从图里可以看出,java gateway相当于一个代理,java gateway本身并不存什么数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
##centos7 默认最小化安装以后并不会进行自动补全需要安装如下的套件。
yum -y install bash-completion
##java-gateway 本身就是一个 java 程序,所以要安装一个 jdk
yum -y install zabbix-java-gateway java-1.8.0
vim /etc/zabbiix/zabbix_java_gateway.conf
探测进程(默认 5 个):
START_POLLERS=10
超时时间(1-30)
TIMEOUT:网络环境差就要改长一点。
启动服务:
[root@zabbix-server ~]# systemctl start zabbix-java-gateway.service
查看端口
[root@zabbix-server ~]# netstat -ntupl | grep java
tcp6 0 0 :::10052 :::* LISTEN 39419/java
可以发现 java-gateway 监控的是 10052 端口。这个 java-gateway 相当于一个代理,具体装在哪一台机器上其实是无关紧要的。

        需要告诉zabbix-server,java-gateway在哪

1
vim /etc/zabbix/zabbix_server.conf
1
2
3
JavaGateway=192.168.56.11
#要启动多少个进程去轮询
StartJavaPollers=5

        重启zabbix-server,然后准备一个tomcat,这里把tomcat安装在 192.168.56.12

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
[root@Zabbix-agent tools]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.13/bin/apache-tomcat-8.5.13.tar.gz
[root@Zabbix-agent tools]# tar xf apache-tomcat-8.5.13.tar.gz
[root@Zabbix-agent tools]# mv apache-tomcat-8.5.13 /usr/local/
[root@Zabbix-agent tools]# cd /usr/local/
[root@Zabbix-agent local]# ln -s ./apache-tomcat-8.5.13/ /usr/local/tomcat
[root@Zabbix-agent local]# yum -y install java-1.8.0
[root@Zabbix-agent local]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@Zabbix-agent logs]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1879/zabbix_agentd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1584/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1675/master
tcp 0 0 :::10050 :::* LISTEN 1879/zabbix_agentd
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 1814/java
tcp 0 0 :::8009 :::* LISTEN 1814/java
tcp 0 0 :::8080 :::* LISTEN 1814/java
tcp 0 0 :::22 :::* LISTEN 1584/sshd
tcp 0 0 ::1:25 :::* LISTEN 1675/master
[root@Zabbix-agent logs]# lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 1814 root 48u IPv6 12681 0t0 TCP *:webcache (LISTEN)

02

tomcat监控管理

03

        搜索JMX

04

        JMX监控有三种类型

  1. 无密码认证
  2. 用户名密码认证
  3. SSL认证

        开启JMX远程监控

1
[root@Zabbix-agent logs]# vim /usr/local/tomcat/bin/catalina.sh

        在 catalina.sh 文件中添加如下内容:

1
2
3
4
5
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=192.168.56.12"

        保存后进行重启,发现没起来,于是查看错误日志,有这么一条错误

1
Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: Zabbix-agent: Zabbix-agent: No address associated with hostname

        很可能是本地hosts文件没把现在设置的临时hostname加进去,因此修改/etc/hosts文件,添加主机名后重启

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@Zabbix-agent logs]# /usr/local/tomcat/bin/shutdown.sh
[root@Zabbix-agent logs]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@Zabbix-agent logs]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 1879/zabbix_agentd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1584/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1675/master
tcp 0 0 :::10050 :::* LISTEN 1879/zabbix_agentd
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 5100/java
tcp 0 0 :::8009 :::* LISTEN 5100/java
tcp 0 0 :::8080 :::* LISTEN 5100/java
tcp 0 0 :::54357 :::* LISTEN 5100/java
tcp 0 0 :::22 :::* LISTEN 1584/sshd
tcp 0 0 :::8888 :::* LISTEN 5100/java
tcp 0 0 ::1:25 :::* LISTEN 1675/master
tcp 0 0 :::35578 :::* LISTEN 5100/java

        启动成功。

        然后用windows平台的java套件中的jconsole软件来进行测试。记得安装jdk。目标程序在C:/ProgramFiles(x86)/java/jdk1.8.x.x/bin下,打开jconsole.exe,输入远程连接地址:端口号,点击连接

05

06

        出现如下内容就证明JMX没有问题。那么接下来就可以进行jvm的监控了。

添加JVM监控

        因为当前tomcat是在agent节点部署的,因此按照如下步骤进行部署:

        Configuration–>Host–>Zabix-agent主机–>在JMX部分添加如下配置

07

        模版选择如下

08

09

        查看图形

10