Zabbix- (six) JMX monitoring

Zabbix- (six) JMX monitoring

I. Introduction

Zabbix provides JMX monitoring, it gets information through the JVM JMX API, to provide monitoring data. This article describes the use of JMX monitoring of Tomcat JVM information.

ready

  • Zabbix Server 4.4 (ip: 192.168.152.140)
  • Host running Java applications hereinafter referred to as Server-A (has been Zabbix monitoring) (ip: 192.168.152.142)


II. Installation Zabbix-Java-gateway

Zabbix Server Zabbix Java gateway JMX collected by surveillance data, you first need to install the Zabbix-Java-gateway, modify the configurations of Zabbix Server.

  1. Install Zabbix-Java-gateway

    It can be installed on other hosts Zabbix-Java-gateway, only need to modify the Zabbix-server configuration file, specify the Zabbix-Java-gateway address and port, here in Deploying Zabbix-Java-gateway on a host of Zabbix Server.

    # yum install zabbix-java-gateway
  2. Zabbix-Java-gateway configuration

    The configuration file is /etc/zabbix/zabbix_java_gateway.confa file, the text take the default configuration, the configuration item details can refer to the diagram or refer to official Zabbix-java-gateway configuration items .

  3. Start Zabbix-Java-gateway

    # systemctl start zabbix-java-gateway
  4. Modify Zabbix server configuration

    The need to increase zabbix-java-gateway configuration in zabbix server configuration file

    # vim /etc/zabbix/zabbix_server.conf

    Modify the configuration information

    # zabbix-java-gateway地址
    JavaGateway=192.168.152.140
    
    # zabbix-java-gateway端口
    JavaGatewayPort=10052
    
    StartJavaPollers=5

    Zabbix server restart

    # systemctl restart zabbix-server


III. Modify the Java application startup parameters

This article is the use of docker deploy tomcat, so this paper is to modify the tomcat catalina.sh script mainly to add the following parameters to start jvm

-Dcom.sun.management.jmxremote
# java应用ip地址(docker部署 使用宿主机ip)
-Djava.rmi.server.hostname=192.168.152.142
# jmx端口
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.rmi.port=12345
# 不开启认证
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

You can add in front of the script file in tomcat catalina.sh

JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=192.168.152.142"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=12345"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=12345"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"

Restart tomcat container port exposed JMX 12345, and mount data volume (mainly tomcat configuration of the catalina.sh), where a can be started tomcat vessel, the vessel catalina.sh docker cp to modify the host do

# docker rm -f tomcat
# docker run --name tomcat -p 8080:8080 -p 12345:12345 -v /data/zabbix/catalina.sh:/usr/local/tomcat/bin/catalina.sh  -dit tomcat:jdk8-adoptopenjdk-hotspot

After starting jconsole tool can be tested by what can monitor tomcat container


IV. Configuring the Zabbix JMX interface

After the service starts, the need to increase JMX monitoring zabbix Server-A interface on the host.

Click [Configuration] - [host] - [Select Server-A]

Increase JMX configuration

Configuration Item value
IP addresses 192.168.152.142
port 12345


V. custom JMX Monitoring Templates

In fact Zabbix 4.4 comes with two JMX template Template App Apache Tomcat JMX and Template App Generic Java JMX template can monitor a Tomcat application, a Java application can monitor general. Readers can directly increase the link above two templates for the host to be monitored, can quickly monitor.

In this paper, the way to create a custom template JMX monitoring

Note: JMX provides a template Zabbix does not necessarily fit all JDK versions, such as Template App Generic Java JMX template provided Perm Gen-generation permanent monitoring items, and JDK 8 in the Perm Gen has been replaced by a permanent change to Metaspace element space, and There are no entry template element space monitoring of


  1. Create custom templates JMX

    Create a template process is not posted, and do not know how to create a custom template since before the reader is referred to the article on how to create a custom template . Here we created a group of Java Server Group and custom templates Custom JMX Template

  2. Create a monitored item

    JMX monitoring item key format jmx[object_name,attribute_name], where object_name is an MBean the ObjectName, ATTRIBUTE_NAME is the attribute value to be read. How to determine the data that needs to be monitored by reference JMX problem at the end of the text .


    The official description of the key:

    Readers can view the official documents JMX monitoring items


    Within heap memory monitoring items

    Configuration Item value
    * Name Within heap memory monitoring items
    Types of JMX agent agent
    * Key jmx["java.lang:type=Memory","HeapMemoryUsage.used"]
    * JMX endpoint service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    unit B
    Other configuration items Configure the


    The total number of monitored JVM thread

    Configuration Item value
    * Name The total number of monitored JVM thread
    Types of JMX agent agent
    * Key jmx["java.lang:type=Threading","ThreadCount"]
    * JMX endpoint service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    Other configuration items Configure the


    Tomcat total number of requests monitoring

    Configuration Item value
    * Name Tomcat total number of requests monitoring
    Types of JMX agent agent
    * Key jmx["Catalina:type=GlobalRequestProcessor,name="http-nio-8080"",requestCount]
    * JMX endpoint service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    Other configuration items Configure the

    Where \ "http-nio-8080 \ " is the default port 8080 tomcat, if you change the port here also do the corresponding adjustment. This parameter can be configured as a template in the template to configuration custom macros , macro value can be changed in the host.


    Tomcat monitoring requests per minute

    Configuration Item value
    * Name Tomcat monitoring requests per minute
    Types of JMX agent agent
    * Key change("jmx["Catalina:type=GlobalRequestProcessor,name=\"http-nio-8080\"",requestCount]")
    * JMX 端点 service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    其他配置项 根据需要配置


    JVM老年代已使用内存监控

    配置项
    * 名称 JVM老年代已使用内存监控
    类型 JMX agent代理程序
    * 键值 jmx["java.lang:type=MemoryPool,name=Tenured Gen", "Usage.used"]
    * JMX 端点 service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    其他配置项 根据需要配置


    JVM老年代总内存监控

    配置项
    * 名称 JVM老年代已使用内存监控
    类型 JMX agent代理程序
    * 键值 jmx["java.lang:type=MemoryPool,name=Tenured Gen", "Usage.committed"]
    * JMX 端点 service:jmx:rmi:///jndi/rmi://{HOST.CONN}:{HOST.PORT}/jmxrmi
    其他配置项 根据需要配置


    老年代内存使用比例监控

    配置项
    * 名称 JVM老年代已使用内存监控
    类型 可计算的
    * 键值 jmx.old
    * 公式 100 * (last("jmx[\"java.lang:type=MemoryPool,name=Tenured Gen\", \"Usage.used\"]"))
    /
    last("jmx[\"java.lang:type=MemoryPool,name=Tenured Gen\", \"Usage.committed\"]")
    * 信息类型 浮点数
    单位 %
    其他配置项 根据需要配置


六.DashBoard创建图形

创建图形的步骤本文就忽略了,添加图形步骤可以参考Zabbix-(三)监控主机CPU、磁盘、内存并创建监控图形


七.其他

如何确定JMX的object_name和attribute_name

jmx监控项格式: jmx[object_name,attribute_name]

  1. 使用jconsole连接到JVM,选择MBean


  2. 找到需要监控的MBean,查看Bean信息和它的属性信息



    !


  3. 结合上面的步骤,那么zabbix监控项就可以填写为

    jmx["java.lang:type=Memory","HeapMemoryUsage.used"]

Guess you like

Origin www.cnblogs.com/Sherry-XRJ/p/11857632.html
JMX