zoukankan      html  css  js  c++  java
  • zabbix监控TCP连接状态

    https://www.cnblogs.com/cloudos/p/8308946.html

    zabbix的客户端

    1、进入所有mysql本地服务器上的zabbix客户端创建脚本目录和文件
    [root@i-ynodsrbz ~]# cd /usr/local/zabbix-2.4.2/
    [root@i-ynodsrbz zabbix-2.4.2]# mkdir scripts
    [root@i-ynodsrbz zabbix-2.4.2]# cd scripts/
    [root@i-ynodsrbz scripts]# touch tcp_conn_status.sh
    脚本内容如下:
    #!/bin/bash
    #this script is used to get tcp and udp connetion status
    #tcp status
    metric=$1
    tmp_file=/tmp/tcp_status.txt
    /bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' > $tmp_file

    case $metric in
    closed)
    output=$(awk '/CLOSED/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    listen)
    output=$(awk '/LISTEN/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    synrecv)
    output=$(awk '/SYN_RECV/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    synsent)
    output=$(awk '/SYN_SENT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    established)
    output=$(awk '/ESTABLISHED/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    timewait)
    output=$(awk '/TIME_WAIT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    closing)
    output=$(awk '/CLOSING/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    closewait)
    output=$(awk '/CLOSE_WAIT/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    lastack)
    output=$(awk '/LAST_ACK/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    finwait1)
    output=$(awk '/FIN_WAIT1/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    finwait2)
    output=$(awk '/FIN_WAIT2/{print $2}' $tmp_file)
    if [ "$output" == "" ];then
    echo 0
    else
    echo $output
    fi
    ;;
    *)
    echo -e "e[033mUsage: sh $0 [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack|timewait]e[0m"

    esac
    2、赋予脚本执行权限
    [root@i-ynodsrbz scripts]# chmod +x tcp_conn_status.sh
    3、在zabbix配置文件中添加脚本及其路径
    [root@i-ynodsrbz scripts]# cd /usr/local/zabbix-2.4.2/etc/
    [root@i-ynodsrbz etc]# vim zabbix_agentd.conf
    在配置文件最后一行添加以下内容即可
    UserParameter=tcp.status[*],/usr/local/zabbix-2.4.2/scripts/tcp_conn_status.sh $1
    UnsafeUserParameters=1
    4、重启zabbix客户端
    [root@i-ynodsrbz ~]# pkill zabbix
    [root@i-ynodsrbz ~]# /usr/local/zabbix-2.4.2/sbin/zabbix_agentd
    5、zabbix服务端检测
    [root@Zabbix-server ~]# /usr/local/zabbix-2.2.2/bin/zabbix_get -s 106.2.12.125 -p 10050 -k "tcp.status[listen]"
    4
    [root@Zabbix-server ~]#
    5、web界面添加配置

  • 相关阅读:
    正则表达式 1
    14 同步 1
    14 线程属性
    14 线程状态
    14 线程
    window.location.hostname与 window.location.host 区别
    泛型 的通配符类型 extends super
    svn拷贝一个项目作为新项目
    List Collections sort
    && 和 || 逻辑运算符
  • 原文地址:https://www.cnblogs.com/bazingafraser/p/8950126.html
Copyright © 2011-2022 走看看