zabbix自动发现监控tomcat健康页面

发布时间:2025-11-26 点击:3
系统运维
zabbix自动发现监控tomcat健康页面
一、背景
公司系统平台有10几个tomcat服务,由于需要服务保持全年无间断服务,特在tomcat中嵌入专门的监控页面,在curl 专用页面返回值为200时,则认定服务正常运行,否则报警发送专门的监控运维的邮箱。
二、原理
正常的tomcat健康状态监控页面如下图
我们利用如下命令判断返回值是否为200
shell>/usr/bin/curl -o /dev/null -s –connect-timeout 5 -w \\\’%{http_code}\\\’ http://10.0.0.107:9100/sms-app/health
倘若返回值不为200,则断定服务异常,报警
三、具体自动发现操作部署如下
1、首先定义需要监控自动发现的tomcat的url
如下内容
1、cat>/etc/zabbix/web.txt<<eof10.0.0.107:9000/sms-admin/health10.0.0.107:9100/sms-app/health10.0.0.107:9090/auditserver/health10.0.0.107:7711/pushcontrol/health10.0.0.107:7700/sendservice/health10.0.0.107:6003/pa/health10.0.0.107:8513/sms/health10.0.0.107:7712/pushcontrol/health10.0.0.107:7725/reply-server/health10.0.0.107:2222/mdnserver/healtheof2、监控脚本如下图所示
1、cat>/etc/zabbix/scripts/web_site_code_status.sh<<eof#!/bin/bash#function:monitortcpconnectstatusfromzabbixsource/etc/bashrc>/dev/null2>&1source/etc/profile>/dev/null2>&1#/usr/bin/curl-o/dev/null-s-w%{http_code}http://$1/web_site_discovery(){web_site=($(cat/etc/zabbix/web.txt|grep-v^#))printf\\\'{\\\\n\\\'printf\\\'\\\\tdata:[\\\\n\\\'for((i=0;i<${#web_site[@]}; i)){num=$(echo$((${#web_site[@]}-1)))if[$i!=${num}];thenprintf\\\\t\\\\t{\\\\nprintf\\\\t\\\\t\\\\t\\\\{#sitename}\\\\:\\\\${web_site[$i]}\\\\},\\\\nelseprintf\\\\t\\\\t{\\\\nprintf\\\\t\\\\t\\\\t\\\\{#sitename}\\\\:\\\\${web_site[$num]}\\\\}]}\\\\nfi}}web_site_code(){/usr/bin/curl-o/dev/null-s--connect-timeout5-w\\\'%{http_code}\\\'$1}case$1inweb_site_discovery)web_site_discovery;;web_site_code)web_site_code$2;;*)echousage:$0{web_site_discovery|web_site_code[url]};;esaceof3、增加zabbix配置文件监控项目
1、root@dl-test2:zabbix#grep\\\'^[a-z]\\\'zabbix_agentd.confpidfile=/var/run/zabbix/zabbix_agentd.pidlogfile=/var/log/zabbix/zabbix_agentd.loglogfilesize=0server=10.0.0.113serveractive=10.0.0.113hostname=dl-test2include=/etc/zabbix/zabbix_agentd.d/*.conf#此项打开1、cat>/etc/zabbix/zabbix_agentd.d/web_site_discovery.conf<<eofuserparameter=web.site.discovery,/bin/bash/etc/zabbix/scripts/web_site_code_status.shweb_site_discoveryuserparameter=web.site.code[*],/bin/bash/etc/zabbix/scripts/web_site_code_status.shweb_site_code$1eof#/bin/bash此项必须要加上,不然有可能找不到命令,导致脚本命令无法被zabbix-agent调用4、增加自动发现模板
模板详见附件
直接在模板里导入附件模板
启动zabbix-agent
会在被监控主机的触发器中发现我们需要监控的tomcat
停止6003端口的服务,我们会发现如下图所示报警
然后启动6003服务后,服务监控正常
至此自动发现tomcat服务状态,部署完毕
附件:http://down.51cto.com/data/2367009

阿里云买服务器有优惠吗多少钱
如何创造一个吸引人的图标
阿里云服务器8g的一年多少钱
阿里云海外云服务器
山东联通服务器托管云服务器价格表
阿里云服务器可以装几个网站
阿里云ecs服务器停机
“双11”助力扶贫,电商正成为精准扶贫的中坚力量