背景:
购物车相关的站点某些页面经常出现502,如果超过一些阈值则需要报警给管理员知道 .自动发现脚本的编写
# vim /usr/local/zabbix_agents_3.2.0/scripts/store_nginx_code.sh #!/bin/bash
# function:monitor store nginx access error code store_domain_discovery () {
WEB_DOMAIN=($(cat /usr/local/zabbix_agents_3.2.0/scripts/store_site.txt|grep -v "^#"))
printf '{\n'
printf '\t"data":[\n'
for((i=;i<${#WEB_DOMAIN[@]};++i))
{
num=$(echo $((${#WEB_DOMAIN[@]}-)))
if [ "$i" != ${num} ];
then
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_DOMAIN[$i]}\"},\n"
else
printf "\t\t{ \n"
printf "\t\t\t\"{#SITENAME}\":\"${WEB_DOMAIN[$num]}\"}]}\n"
fi
}
} # 统计nginx access log中的50x代码个数
error_code_count () {
web_site=$
if [ ${web_site} == 'store.wondershare.jp' ];then
/usr/bin/cat /data/www/logs/nginx_log/access/${web_site}.access.log |awk '{print $1" "$10" "$11}'|grep 'HTTP/1.1" 50'|uniq |wc -l
exit
fi
/usr/bin/cat /data/www/logs/nginx_log/access/${web_site}_access.log |awk '{print $1" "$10" "$11}'|grep 'HTTP/1.1" 50'|uniq |wc -l
} case "$1" in
store_domain_discovery)
store_domain_discovery
;;
error_code_count)
error_code_count $
;;
*) echo "Usage:$0 {store_web_discovery|error_code_count [URL]}"
;;
esac # chmod +x /usr/local/zabbix_agents_3.2.0/scripts/store_nginx_code.sh # 需要监控的日志(按照站点分类) vim /usr/local/zabbix_agents_3.2.0/scripts、store_site.txt store.aa.com
store.bb.net # 核心代码
[root@ws_store_web01:/usr/local/zabbix_agents_3.2.0/scripts]# cat error_status_count.sh
#!/bin/bash # Functions to return nginx stats function main {
web_site=$
if [ ${web_site} == 'store.cc.jp' ];then
/usr/bin/cat /data/www/logs/nginx_log/access/${web_site}.access.log |awk '{print $1" "$10" "$11}'|grep 'HTTP/1.1" 50'|uniq |wc -l
exit
fi
/usr/bin/cat /data/www/logs/nginx_log/access/${web_site}_access.log |awk '{print $1" "$10" "$11}'|grep 'HTTP/1.1" 50'|uniq |wc -l
} # Run the requested function
main $ .配置编写
vim /usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd/store_domain_discovery.conf UserParameter=store.domain.discovery,/usr/local/zabbix_agents_3.2.0/scripts/store_nginx_code.sh store_domain_discovery
UserParameter=store.domain.code[*],/usr/local/zabbix_agents_3.2.0/scripts/store_nginx_code.sh error_code_count $ 模板关键配置:



zabbix模板: <?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>3.2</version>
<date>--26T08::38Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>store nginx access error_code count</template>
<name>store nginx access error_code count</name>
<description/>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications/>
<items/>
<discovery_rules>
<discovery_rule>
<name>store.domain.discovery</name>
<type></type>
<snmp_community/>
<snmp_oid/>
<key>store.domain.discovery</key>
<delay></delay>
<status></status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>
<evaltype></evaltype>
<formula/>
<conditions/>
</filter>
<lifetime></lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>store.domain.code ON $</name>
<type></type>
<snmp_community/>
<multiplier></multiplier>
<snmp_oid/>
<key>store.domain.code[{#SITENAME},]</key>
<delay></delay>
<history></history>
<trends></trends>
<status></status>
<value_type></value_type>
<allowed_hosts/>
<units/>
<delta></delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel></snmpv3_securitylevel>
<snmpv3_authprotocol></snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol></snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula></formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type></data_type>
<authtype></authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link></inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<application_prototypes/>
</item_prototype>
</item_prototypes>
<trigger_prototypes>
<trigger_prototype>
<expression>{store nginx access error_code count:store.domain.code[{#SITENAME},].max(#)}&gt;</expression>
<recovery_mode></recovery_mode>
<recovery_expression/>
<name>{#SITENAME} nginx error code is great than </name>
<correlation_mode></correlation_mode>
<correlation_tag/>
<url/>
<status></status>
<priority></priority>
<description/>
<type></type>
<manual_close></manual_close>
<dependencies/>
<tags/>
</trigger_prototype>
</trigger_prototypes>
<graph_prototypes/>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>

zabbix批量监控域名下nginx的访问50x状态码数量的更多相关文章

  1. Nginx的 HTTP 499 状态码处理

    1.前言 今天在处理一个客户问题,遇到Nginx access log中出现大量的499状态码.实际场景是:客户的域名通过cname解析到我们的Nginx反向代理集群上来,客户的Web服务是由一个负载 ...

  2. HTTP 403 ,tomcat配置HTTPS,无法访问 返回状态码HTTP 403

    为了将本机(windows系统)启动的应用以HTTPS的形式访问, 利用Keytool 生成证书之后.在tomcat的server.xml中将配置修改为如下: <Connector port=& ...

  3. java下使用chromedriver获取访问页面状态码

    ##在使用chromedriver的时候 并没有提供api来获取访问页面的状态码,但是可以打开日志来获取到 LoggingPreferences logPrefs = new LoggingPrefe ...

  4. zabbix 自定义监控项 获取nginx监控状态

    本篇是基于zabbix 源码安装的 [root@localhost conf]# curl "http://192.168.0.73:8080/nginx_status" Acti ...

  5. zabbix批量监控urls的状态码

    .添加url监控脚本 [root@node1 usr]# vim /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh #!/b ...

  6. 检测Nginx访问成功(状态码200)的IP及次数

    cat  access.log |awk '{print $1,$9}'|grep '200'|sort | uniq -c|awk '{print $2" "$1}'

  7. nginx 定义的一些状态码

    ngx_string(ngx_http_error_494_page), /* 494, request header too large */    ngx_string(ngx_http_erro ...

  8. Nginx code 常用状态码学习小结

    最近了解下Nginx的Code状态码,在此简单总结下.一个http请求处理流程: 一个普通的http请求处理流程,如上图所示:A -> client端发起请求给nginxB -> ngin ...

  9. Nginx code 状态码说明

    最近了解下Nginx的Code状态码,在此简单总结下. 先来再回顾一下一个http请求处理流程: 一个普通的http请求处理流程,如上图所示: A -> client端发起请求给nginx B ...

随机推荐

  1. Vue-移动端项目真机测试

    一.查看ip地址 在控制台输入 ifconfig 查看ip地址 二.修改webpack-dev-server配置项 webpack-dev-server 默认不支持ip地址访问,需要修改配置项 三.测 ...

  2. MaxCompute教程

    MaxCompute全套攻略:https://blog.csdn.net/qq_35394891/article/details/82943894 [2019年大数据福利推荐]MaxCompute教程 ...

  3. JAVA项目启动正常,无法访问

    若是一般项目web.xml问题  springboot是静态资源问题

  4. XSS原理及防范

    Xss(cross-site scripting)攻击指的是攻击者往Web页面里插入恶意html标签或者javascript代码.比如:攻击者在论坛中放一个看似安全的链接,骗取用户点击后,窃取cook ...

  5. css高級技巧

    1.鼠標顯示 a:小手cursor:pointer b:默認cursor:default c:勾選文本cursor:text d:拖動cursor:move 2.css三種佈局模型 a.流動模型(默認 ...

  6. ubuntu only enable left click

    xmodmap -e "pointer = 1 0 0 0 0 0 0 0 0 0"

  7. P1313 计算系数 HMR大佬讲解

    今天,HMR大佬给我们讲解了这一道难题. 这道题明显的二项式定理,自然想到了要用到杨辉三角了.基本思路就是先用for循环求出杨辉三角,这样就求出了x的n次方的系数和y的m次方的系数. 这是大佬的AC代 ...

  8. Mdoelsim10.4怎么脚本单独仿真ISE14.7 IP核

    软件版本: Modelsim10.4SE ISE14.7 仿真IP:时钟管理IP(clock wizard)   流程: 1.对于Modelsim10.4SE,并不自带Xilinx家的仿真库,因此首先 ...

  9. HDOJ5543 Pick The Sticks

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题目大意:有n个金条,每个金条有长度和价值,给一个长度为L的容器,当金条在容器两端的时候,只要重 ...

  10. Java项目模板设置

    /** * * @ClassName ${PACKAGE_NAME}.${NAME} * @description ${DESCRIPTION} * @author lisongyu * @creat ...