nagios监控流量脚本
监控 脚本 流量 Nagios
2023-09-27 14:29:20 时间
需求是我们需要对服务器上的流量进行监控,网络上有个流传的check_traffic.sh,它需要被监控机开启snmp。但是感觉都使用上了nagios还要开snmp。。。有点斧子剪刀一起用的感觉,所以就动手写了个监控流量的shell:
#!/bin/sh usage() { echo "Usage: $0 [-n <eth0>] [-w <tx rx>] [-c <tx rx>]" 1>&2; exit 1; } foundw=0; foundc=0; foundn=0; for item in $@ ; do if [[ $foundn == 1 ]]; then n=$item; foundn=2; continue; fi if [[ $foundw == 1 ]]; then w1=$item; foundw=2; continue; fi if [[ $foundw == 2 ]]; then w2=$item; foundw=3; continue; fi if [[ $foundc == 1 ]]; then c1=$item; foundc=2; continue; fi if [[ $foundc == 2 ]]; then c2=$item; foundc=2; continue; fi if [[ "$item" == "-w" ]]; then foundw=1; continue; fi if [[ "$item" == "-c" ]]; then foundc=1; continue; fi if [[ "$item" == "-n" ]]; then foundn=1; continue; fi done if [ -z "${w1}" ] || [ -z "${w2}" ] || [ -z "${c1}" ] || [ -z "${c2}" ] || [ -z "${n}" ]; then usage fi R1=`cat /sys/class/net/$n/statistics/rx_bytes` T1=`cat /sys/class/net/$n/statistics/tx_bytes` sleep 1 R2=`cat /sys/class/net/$n/statistics/rx_bytes` T2=`cat /sys/class/net/$n/statistics/tx_bytes` TBPS=`expr $T2 - $T1` RBPS=`expr $R2 - $R1` TMBPS=`expr $TBPS / 1024 / 128` RMBPS=`expr $RBPS / 1024 / 128` if [[ $TMBPS -ge $c1 ]] || [[ $RMBPS -ge $c2 ]] ; then echo "Critical - current is ${TMBPS}, ${RMBPS}"; exit 2; fi if [[ $TMBPS -ge $w1 ]] || [[ $RMBPS -ge $w2 ]] ; then echo "WARNING - current is ${TMBPS}, ${RMBPS}"; exit 1; fi echo "OK - current is ${TMBPS}, ${RMBPS}"; exit 0;
其中的w和c的数值单位都是Mb。
相关文章
- 【miscellaneous】海康威视监控摄像头实现web端无插件监控实拍效果
- iotop实时监控磁盘io
- linux shell 脚本通过log和pid监控程序执行并重启jar
- Prometheus监控学习笔记之360基于Prometheus的在线服务监控实践
- Nagios监控nginx服务具体过程
- 如何在Ubuntu上使用Glances监控系统
- Linux下针对服务器网卡流量和磁盘的监控脚本
- 服务器磁盘监控脚本分享(含报警邮件)
- 分布式监控系统Zabbix-3.0.3-完整安装记录 - 添加shell脚本监控
- vCenter 6.7 使用Grafana监控失败的处理
- 【精】Linux磁盘I/O性能监控之iostat详解
- 最新!Gartner公布持续威胁评估框架CARTA 对应NIST提出的对内持续监控框架ISCM
- Python对系统数据进行采集监控——psutil
- 监控RMAN操作进度的脚本
- 使用脚本命令监控站点日志
- linux监控脚本故障告警
- NetLink通信原理研究、Netlink底层源码分析、以及基于Netlink_Connector套接字监控系统进程行为技术研究
- 自动监控tomcat脚本并且执行重启操作
- Nagios 监控Windows服务器(详细篇)
- 基于SAR对Linux资源的监控shell脚本
- tomcat监控脚本
- hbase监控简单实用脚本