scalpels/scripts/device-input-traffic.sh
Kun Huang 9c188cc61a parse device traffic like rpc
Change-Id: Ifc2aa017b45f41052fecc80c49fd239b621e6aee
2015-10-29 16:21:39 +08:00

20 lines
573 B
Bash
Executable File

#!/bin/bash
# Author: Kun Huang <academicgareth@gmail.com>
dev=${1:-eth0}
packages=`cat /sys/class/net/$dev/statistics/rx_packets `
bytes=`cat /sys/class/net/$dev/statistics/rx_bytes `
interval=3
trap 'break' INT
while [ 1 -eq 1 ] ; do
sleep $interval
n_packages=`cat /sys/class/net/$dev/statistics/rx_packets `
n_bytes=`cat /sys/class/net/$dev/statistics/rx_bytes `
python -c "print '%0.2f pkt/s %0.2f byte/s' % ((float($n_packages-$packages)/int($interval), (float($n_bytes-$bytes)/int($interval))))"
packages=$n_packages
bytes=$n_bytes
done