Linux查看实时网卡流量的几种方式
发布日期:2021-05-10 15:54:09 浏览次数:15 分类:精选文章

本文共 4284 字,大约阅读时间需要 14 分钟。

������������������������������������������������������������������Linux������������������������������������������������������������������

������������������sar������

sar���System Activity Reporter���������������������������������������������������������������������������������Linux������������sar���������������������������������������������������������sar������������������

sar -n DEV 1 2

������������������������������������������������-n������������������������������������������������������DEV���������������������EDEV���������������������NFS���NFS���������������NFSD���NFS������������������������������������������������������������������������������������������������������

���������������������������������������������������

Linux 2.6.32-431.el6.x86_64 (CDVM-213017031) 05/04/2017 08:05:30 PM
IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
lo 0.00 0.00 0.00 0.00 0.00 0.00 0.000
eth0 1788.00 1923.00 930.47 335.60 0.00 0.00 0.000
Average:
lo 0.00 0.00 0.00 0.00 0.00 0.00 0.000
eth0 1587.50 1696.00 791.29 296.29 0.00 0.00 0.00

���������������������

  • rxpck/s���������������������������������
  • txpck/s���������������������������������
  • rxkB/s���txkB/s���������������������������KB������
  • rxcmp/s���txcmp/s������������������������������������������������
  • rxmcst/s���������������������������������������

������������������������������������

���������������������������������������������������������������������������������������������������������������������Bash���������������

#!/bin/bash
ethn=$1
while true
do
RX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
clear
echo -e "\t RX `date +%k:%M:%S` TX"
RX=$((${RX_next}-${RX_pre})
TX=$((${TX_next}-${TX_pre})
if [[ $RX -lt 1024 ]];then
RX="${RX}B/s"
elif [[ $RX -gt 1048576 ]];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi
if [[ $TX -lt 1024 ]];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi
echo -e "$ethn \t $RX $TX "
done

���������������������

  • ������/proc/net/dev������������������������
  • ���������������������������������������
  • ������������������������������������
  • ���������������������������������������������B/s���KB/s���MB/s���
  • ���������������������������������������������������������������
  • ���Ctrl+C���������������

���������������

  • ���������������������������������������net.sh
  • ������chmod +x ./net.sh���������������
  • ���������������������������������������sh net.sh eth0
  • ������������������cat /proc/net/dev

    /proc/net/dev������������������������������������������������������cat /proc/net/dev������������������������������������������������

    ���������

    eth0: 1788.00 1923.00 1366157371 3134679052
    0 0 0.00 0.00
    0 0 0.00 0.00
    0 0 0.00 0.00
    0 0 0.00 0.00

    ���������������������

    • ������������
    • ���������������������
    • ���������������
    • ������������������ -(pg���������������������)

    ������������������watch������������������

    watch���������������������������������������������������������

    watch -n 1 "ifconfig eth0" or watch -n 1 "cat /proc/net/dev | grep eth0"

    watch������������������������������������������������������������������������������������������������������

    ������������

    ���������������������������������������������

    • ������������������������������������������������sar���������
    • ������������������������������������������������������������������������������
    • ���������������������������������������������cat /proc/net/dev������������������������������
    • watch������������������������������������������������������������

    ���������������������/proc/net/dev���������������������������������������������������������������������������������������������

    ������������������������������������������������������������������������������������������

    上一篇:NAT地址转换配置
    下一篇:Oracle闪回查询总结

    发表评论

    最新留言

    留言是一种美德,欢迎回访!
    [***.207.175.100]2025年04月03日 14时29分48秒