shell指令碼實現對網絡卡流量監控

2021-07-05 06:53:00 字數 555 閱讀 6610

突然想對linux的網絡卡流量進行監控,又不想使用cacti,覺得配置snmp很麻煩。現成的工具好像也沒啥太好用的。決定自己寫乙個指令碼。

#!/bin/bash

rx1=$(ifconfig $1|grep "rx bytes"|awk ''|awk -f: '')

sleep 1

rxa=$(($rx1 / 1000))

rx2=$(ifconfig eth0|grep "rx bytes"|awk ''|awk -f: '')

rxb=$(($rx2 / 1000))

echo "net traffic is:" $(($rxb - $rxa))k/s

另存為traffic

使用方法如下:

chmod 777 traffic

watch ./traffic eth0

效果如下:

用shell指令碼實時檢視網絡卡流量

用shell指令碼可以實現對網絡卡bytes和packets的雙重監控,每隔一秒輸出一次,最後輸出的是對應ip位址的流量情況。bin bash while true don 1 while n cat proc net dev wc l do 獲取當前時刻網口接收與傳送的流量 rb pre n ca...

Python指令碼實現網絡卡流量監控

usr bin env python coding utf 8 import sys,re,time,os maxdata 50000 單位kb memfilename tmp newnetcardtransdata.txt netcard proc net dev def checkfile fi...

shell監控網絡卡流量

最近出現了由於網路阻塞訪問庫出現問題現象,現紀錄下,怎麼排查由於網路阻塞影響的問題指令碼,方便查閱 bin bash watch n 1 monitor.sh 2 timer 1 echo eth rx tx for i in ifconfig grep encap awk doeth i rxpr...