04: Nginx and TCP state monitoring templates to create

The following describes the TCP and Nginx status monitoring - made template form:

A, TCP state templates to create:

1, add custom items to monitor any machine:

[root @ tvm_web1 zabbix_agentd.d] # CAT # /etc/zabbix/zabbix_agentd.d/monitor_tcp_status.conf path and file name (and contents) 
UserParameter = TCP_Status [*], SS -ant | grep -c $ 1 # Of course, you also You can use netstat (if not afraid timeout)                                      
[root @ tvm_web1 zabbix_agentd.d] # 

2, the following operations on the management interface zabbix:

Two, Nginx status monitoring templates to create:

1, add a custom script monitoring items and create scripts (remember to use the papers here - do not always go tune nginx):

[root@tvm_web1 zabbix_agentd.d]# cat /etc/zabbix/zabbix_agentd.d/monitor_nginx_status.conf 
UserParameter=nginx_status[*],/etc/zabbix/zabbix_agentd.d/monitor_nginx_status.sh $1
[root@tvm_web1 zabbix_agentd.d]# cat /etc/zabbix/zabbix_agentd.d/monitor_nginx_status.sh 
#!/bin/bash
NGINX_COMMAND=$1
CACHEFILE="/tmp/nginx_status.txt"
CMD="/usr/bin/curl http://127.0.0.1:8000/nginx_status"

if [ ! -f $CACHEFILE ];then
    $CMD > $CACHEFILE 2>/dev/null
fi

TIMEFLM=`stat -c %Y $CACHEFILE`
TIMENOW=`date +%s`

if [ `expr $TIMENOW - $TIMEFLM` -gt 60 ];then
    rm -f $CACHEFILE
fi

if [ ! -f $CACHEFILE ];then
    $CMD > $CACHEFILE 2>/dev/null
fi

nginx_active(){
    grep 'Active' $CACHEFILE | awk '{print $NF}'
    exit 0;
}

nginx_reading(){
    grep 'Reading' $CACHEFILE | awk '{print $2}'
    exit 0;
}

nginx_writing(){
    grep 'Writing' $CACHEFILE | awk '{print $4}'
    exit 0;
}

nginx_waiting(){
    grep 'Waiting' $CACHEFILE | awk '{print $6}'
    exit 0;
}

nginx_accepts(){
    awk NR==3 $CACHEFILE | awk '{print $1}'
    exit 0;
}

nginx_handled(){
    awk NR==3 $CACHEFILE | awk '{print $2}'
    exit 0;
}

nginx_requests(){
    awk NR==3 $CACHEFILE | awk '{print $3}'
    exit 0;
}

case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
*)
echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
esac
[root@tvm_web1 zabbix_agentd.d]#

2、创建模板(自定义监控项):

好了,今天先这样吧

 

Guess you like

Origin www.cnblogs.com/zheng-weimin/p/11343703.html