httping監控網路丟包率/延時/狀態
阿新 • • 發佈:2018-12-19
web介面新增監控專案
型別: Zabbix客戶端
鍵值:如下
httping.status[failed,www.baidu.com,443,https]
httping.status[max,www.baidu.com,443,https]
httping.status[status,www.baidu.com,443,https]
資訊型別:浮點數
在zabbix的agentd端的zabbix_agentd.conf新增如下配置
######httping########### UserParameter=httping.status[*],/etc/zabbix/scripts/httping.sh $1 $2 $3 $4
使用httping指令碼httping.sh
#!/bin/bash metric=$1 host=$2 port=$3 proto=$4 tmp_file=/tmp/httping/${host}_${metric}_httping_status.txt if [ $proto == "https" ];then /bin/httping -c3 -t5 -l $proto://$host:$port > $tmp_file case $metric in status) output=$(cat $tmp_file |grep connected |wc -l ) if [ $output -eq 3 ];then output=1 echo $output else output=0 echo $output fi ;; failed) output=$(cat $tmp_file |grep failed|awk '{print $5}'|awk -F'%' '{print $1}' ) if [ "$output" == "" ];then echo 100 else echo $output fi ;; min) output=$( cat $tmp_file|grep min|awk '{print $4}'|awk -F/ '{print $1}' ) if [ "$output" == "" ];then echo 0 else echo $output fi ;; avg) output=$(cat $tmp_file|grep avg|awk '{print $4}'|awk -F/ '{print $2}') if [ "$output" == "" ];then echo 0 else echo $output fi ;; max) output=$(cat $tmp_file|grep max|awk '{print $4}'|awk -F/ '{print $3}') if [ "$output" == "" ];then echo 0 else echo $output fi ;; *) echo -e "\e[033mUsage: sh $0 [status|failed|min|avg|max]\e[0m" esac elif [ $proto == "http" ];then /bin/httping -c3 -t5 $proto://$host:$port > $tmp_file case $metric in status) output=$(cat $tmp_file |grep connected |wc -l ) if [ $output -eq 3 ];then output=1 echo $output else output=0 echo $output fi ;; failed) output=$(cat $tmp_file |grep failed|awk '{print $5}'|awk -F'%' '{print $1}' ) if [ "$output" == "" ];then echo 100 else echo $output fi ;; min) output=$( cat $tmp_file|grep min|awk '{print $4}'|awk -F/ '{print $1}' ) if [ "$output" == "" ];then echo 0 else echo $output fi ;; avg) output=$(cat $tmp_file|grep avg|awk '{print $4}'|awk -F/ '{print $2}') if [ "$output" == "" ];then echo 0 else echo $output fi ;; max) output=$(cat $tmp_file|grep max|awk '{print $4}'|awk -F/ '{print $3}') if [ "$output" == "" ];then echo 0 else echo $output fi ;; *) echo -e "\e[033mUsage: sh $0 [status|failed|min|avg|max]\e[0m" esac else echo "error parm " $proto >/tmp/httping/error.log fi