监控PHP
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 [root@web01 ~]# vim /etc/php-fpm.d/www.conf pm.status_path = /php_status [root@web01 conf.d]# vim webapp.conf server{ listen 80; server_name _; location / { root /code/webapp; index index.html; } location /status { stub_status on; } location ~ ^/(php_status)$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ; } } [root@web01 conf.d]# systemctl restart nginx php-fpm
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 pool: www process manager: dynamic start time: 02/Aug/2024:10:44:26 +0800 start since: 44 accepted conn: 1 listen queue: 0 max listen queue: 0 listen queue len: 128 idle processes: 4 active processes: 1 total processes: 5 max active processes: 1 max children reached: 0 slow requests: 0 pool process manager start time start since accepted conn listen queue max listen queue listen queue len idle processes active processes total processes max active processes max children reached [root@web01 scripts]# cat php_status.sh PHPFPM_COMMAND=$1 PHPFPM_URL="http://172.16.1.7/php_status" start_since (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^start since:/ {print $NF}' } accepted_conn (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^accepted conn:/ {print $NF}' } listen_queue (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^listen queue:/ {print $NF}' } max_listen_queue (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^max listen queue:/ {print $NF}' } listen_queue_len (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^listen queue len:/ {print $NF}' } idle_processes (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^idle processes:/ {print $NF}' } active_processes (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^active processes:/ {print $NF}' } total_processes (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^total processes:/ {print $NF}' } max_active_processes (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^max active processes:/ {print $NF}' } max_children_reached (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^max children reached:/ {print $NF}' } slow_requests (){ /usr/bin/curl -s "${PHPFPM_URL} " |awk '/^slow requests:/ {print $NF}' } case $PHPFPM_COMMAND in start_since) start_since; ;; accepted_conn) accepted_conn; ;; listen_queue) listen_queue; ;; max_listen_queue) max_listen_queue; ;; listen_queue_len) listen_queue_len; ;; idle_processes) idle_processes; ;; active_processes) active_processes; ;; total_processes) total_processes; ;; max_active_processes) max_active_processes; ;; max_children_reached) max_children_reached; ;; slow_requests) slow_requests; ;; *) echo $"USAGE:$0 {start_since|accepted_conn|listen_queue|max_listen_queue|listen_queue_len|idle_p rocesses|active_processes|total_processes|max_active_processes|max_children_reac hed}" esac [root@web01 scripts]# chmod +x php_status.sh [root@web01 zabbix_agentd.d]# vim php_status.conf UserParameter=php.status[*],/etc/zabbix/zabbix_agentd.d/scripts/php_status.sh $1 [root@web01 zabbix_agentd.d]# systemctl restart zabbix-agent
监控JAVA进程JVM
在Zabbix中,JMX监控数据的获取由专门的代理程序来实现,即Zabbix-Java-Gateway来负责数据的采 集,Zabbix-Java-Gateway和JMX的Java程序之间通信获取数据
JMX在Zabbix中的运行流程
1 2 3 4 5 1.Zabbix-Server找Zabbix-Java-Gateway获取Java数据 2.Zabbix-Java-Gateway找Java程序(zabbix-agent)获取数据 3.Java程序返回数据给Zabbix-Java-Gateway 4.Zabbix-Java-Gateway返回数据给Zabbix-Server 5.Zabbix-Server进行数据展示
安装JAVA-gateway
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/ [root@web02 ~]# rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-java-gateway-5.0.42-1.el7.x86_64.rpm [root@web02 ~]# systemctl start zabbix-java-gateway [root@zabbix5-server ~]# vim /etc/zabbix/zabbix_server.conf JavaGateway=172.16.1.8 JavaGatewayPort=10052 StartJavaPollers=5 [root@zabbix5-server ~]# systemctl restart zabbix-server
tomcat开启JMX
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 [root@web02 ~]# vim /usr/libexec/tomcat/server CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=172.16.1.8" [root@web02 ~]# cat /usr/libexec/tomcat/server . /usr/libexec/tomcat/preamble MAIN_CLASS=org.apache.catalina.startup.Bootstrap FLAGS="$JAVA_OPTS " OPTIONS="-Dcatalina.base=$CATALINA_BASE \ -Dcatalina.home=$CATALINA_HOME \ -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \ -Djava.io.tmpdir=$CATALINA_TMPDIR \ -Djava.util.logging.config.file=${LOGGING_PROPERTIES} \ -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=172.16.1.8" if [ "$1 " = "start" ] ; then FLAGS="${FLAGS} $CATALINA_OPTS " if [ "${SECURITY_MANAGER} " = "true" ] ; then OPTIONS="${OPTIONS} \ -Djava.security.manager \ -Djava.security.policy==${CATALINA_BASE} /conf/catalina.policy" fi run start elif [ "$1 " = "stop" ] ; then run stop fi systemctl daemon-reload systemctl restart tomcat
web界面设置-新建主机
链接模板