nagios监控流量脚本
监控 脚本 流量 Nagios
2023-09-14 08:59:40 时间
需求是我们需要对服务器上的流量进行监控,网络上有个流传的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; if [[ $foundw == 1 ]]; then w1=$item; foundw=2; continue; if [[ $foundw == 2 ]]; then w2=$item; foundw=3; continue; if [[ $foundc == 1 ]]; then c1=$item; foundc=2; continue; if [[ $foundc == 2 ]]; then c2=$item; foundc=2; continue; if [[ "$item" == "-w" ]]; then foundw=1; continue; if [[ "$item" == "-c" ]]; then foundc=1; continue; if [[ "$item" == "-n" ]]; then foundn=1; continue; if [ -z "${w1}" ] || [ -z "${w2}" ] || [ -z "${c1}" ] || [ -z "${c2}" ] || [ -z "${n}" ]; then usage 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; if [[ $TMBPS -ge $w1 ]] || [[ $RMBPS -ge $w2 ]] ; then echo "WARNING - current is ${TMBPS}, ${RMBPS}"; exit 1; echo "OK - current is ${TMBPS}, ${RMBPS}"; exit 0;
其中的w和c的数值单位都是Mb。
相关文章
- Spring Boot + Web Socket 打造实时监控异常,写得太好了!
- shell脚本 监控网络流量
- 视频监控系统智能识别分析
- shell脚本案例-监控内存使用率
- 走马观花云原生技术(13):度量与监控 Prometheus
- Prometheus监控实战系列八:标签重写
- Python程序监控脚本
- 太强了!利用 Python 写了一个监控服务器资源利用率的脚本!
- shell脚本监控网站状态详解程序员
- oracle AWR性能监控报告生成方法
- python写个进程监控的脚本详解编程语言
- 进程监控的python脚本详解编程语言
- Linux网络IO实时监控实践(linux网络io监控)
- Linux系统中自动监控磁盘容量的脚本(linux监控磁盘的脚本)
- 如何监控Linux系统的网络流量(如何查看linux流量)
- 深入Linux系统:监控IO负载(linux查看io负载)
- 在 Linux 上监控 CPU 和 GPU 温度
- 在 Linux 上用 Bash 脚本监控 messages 日志
- Linux 文件监控:实时保护数据安全(监控Linux文件)
- Linux系统下的电源监控:低耗能的选择(linux 电源 监控)
- Linux流量监控:十个实用的查看流量命令(linux查看流量命令)
- 脚本实现监控Redis数据安全(脚本监控redis)