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
| 1、安装agent
Server=192.168.6.10 Hostname=192.168.6.30 AllowRoot=1 User=root
zabbix_agentd
2、nginx开启状态页
location /nginx_status { stub_status; }
打开状态页信息
Active connections: 2 server accepts handled requests 2 2 3 Reading: 0 Writing: 1 Waiting: 1
提取状态页脚本
host=${2:-'127.0.0.1'} port=${3:-'80'} page=${4:-'nginx_status'} info=$(/usr/bin/curl --connect-timeout 5 -s http://${host}:${port}/${page} 2>/dev/null) code=$(/usr/bin/curl --connect-timeout 5 -o /dev/null -s -w %{http_code} http://${host}:${port}/${page}) proc=$(/usr/bin/pgrep nginx | wc -l)
case "$1" in status) echo "$code $proc" | awk '{code=$1}{proc=$2}END{if(code == "200" && proc != 0){printf("%d\n",1)}else{printf("%d\n",0)}}' ;; active) echo "$info" | awk '/^Active/{var=$NF}END{if(var~/^[0-9]+$/){printf("%d\n",var)}else{printf("%d\n",0)}}' ;; reading) echo "$info" | awk '/Reading/ {print $2}' ;; writing) echo "$info" | awk '/Writing/ {print $4}' ;; waiting) echo "$info" | awk '/Waiting/ {print $6}' ;; accepts) echo "$info" | awk 'NR==3 {print $1}' ;; handled) echo "$info" | awk 'NR==3 {print $2}' ;; requests) echo "$info" | awk 'NR==3 {print $3}' ;; restimes) echo "$info" | awk 'BEGIN{OFMT="%.3f"} NR==3 {print $4/$3}' ;; *) echo "ZBX_NOTSUPPORTED" ;; esac
3、导入脚本 root@zabbix-node2:~ UserParameter=nginx.status[*],/etc/zabbix/zabbix_agentd.conf.d/check_nginx.sh $1 $2 4、使用zabbix_get命令测试
5、创建模板
|