Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175842
  • 博文数量: 47
  • 博客积分: 3053
  • 博客等级: 少校
  • 技术积分: 451
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-01 04:33
个人简介

malware/APT detection, silicon valley, entrepreneur, CTO, start-up operation, team build, Nanjing/Beijing, if you want to do creative things, join the adventure.

文章分类

全部博文(47)

分类: LINUX

2016-11-27 03:38:45



/sys/class/net/eth0/statistics/rx_packets:
number of packets received
/sys/class/net/eth0/statistics/tx_packets:
number of packets transmitted
/sys/class/net/eth0/statistics/rx_bytes:
number of bytes received
/sys/class/net/eth0/statistics/tx_bytes:
number of bytes transmitted
/sys/class/net/eth0/statistics/rx_dropped:
number of packets dropped while received
/sys/class/net/eth0/statistics/tx_dropped:
number of packets dropped while transmitted


Measure Packets per Second on an Interface


  1. #!/bin/bash
  2.  
  3. INTERVAL="1" # update interval in seconds
  4.  
  5. if [ -z "$1" ]; then
  6.         echo
  7.         echo usage: $0 [network-interface]
  8.         echo
  9.         echo e.g. $0 eth0
  10.         echo
  11.         echo shows packets-per-second
  12.         exit
  13. fi
  14.  
  15. IF=$1
  16.  
  17. while true
  18. do
  19.         R1=`cat /sys/class/net/$1/statistics/rx_packets`
  20.         T1=`cat /sys/class/net/$1/statistics/tx_packets`
  21.         sleep $INTERVAL
  22.         R2=`cat /sys/class/net/$1/statistics/rx_packets`
  23.         T2=`cat /sys/class/net/$1/statistics/tx_packets`
  24.         TXPPS=`expr $T2 - $T1`
  25.         RXPPS=`expr $R2 - $R1`
  26.         echo "TX $1: $TXPPS pkts/s RX $1: $RXPPS pkts/s"
  27. done

Measure Network Bandwidth on an Interface


  1. #!/bin/bash
  2.  
  3. INTERVAL="1" # update interval in seconds
  4.  
  5. if [ -z "$1" ]; then
  6.         echo
  7.         echo usage: $0 [network-interface]
  8.         echo
  9.         echo e.g. $0 eth0
  10.         echo
  11.         exit
  12. fi
  13.  
  14. IF=$1
  15.  
  16. while true
  17. do
  18.         R1=`cat /sys/class/net/$1/statistics/rx_bytes`
  19.         T1=`cat /sys/class/net/$1/statistics/tx_bytes`
  20.         sleep $INTERVAL
  21.         R2=`cat /sys/class/net/$1/statistics/rx_bytes`
  22.         T2=`cat /sys/class/net/$1/statistics/tx_bytes`
  23.         TBPS=`expr $T2 - $T1`
  24.         RBPS=`expr $R2 - $R1`
  25.         TKBPS=`expr $TBPS / 1024`
  26.         RKBPS=`expr $RBPS / 1024`
  27.         echo "TX $1: $TKBPS kB/s RX $1: $RKBPS kB/s"
  28. done


阅读(1292) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~