httping监控网络丢包率/延时/状态

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

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值