Skip to main content
added 242 characters in body
Source Link
akira
  • 1.1k
  • 6
  • 13

something to get you started (just in case you want to write it yourself):

#!/bin/bash # # usage: bwmon PID IN=0 OUT=0 IN=0; OUT=0; TIME=0 get_traffic() { t=`awk '/eth0:/ { printf("%s,%d,%d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev` IN=${t#*,}; IN=${IN%,*} OUT=${t##*,}; TIME=${t%%,*}; } get_traffic $1 while true do  _IN=$IN  _OUT=$OUT  _IN=$IN; _OUT=$OUT; _TIME=$TIME get_traffic $1 echo "$TIME,$(( $TIME - $_TIME )),$IN,$(( $IN - $_IN )),$OUT,$(( $OUT - $_OUT))" sleep 1 done 

comments:

  • checks only eth0
  • checks every 1 second
  • works only under linux, but other unixes work similar (procfs or whatever)
  • output could be stored into a sqlite.db with stat --printf="%N\n" /proc/PID/exe | cut -d ' ' -f 3

something to get you started (just in case you want to write it yourself):

#!/bin/bash # # usage: bwmon PID IN=0 OUT=0 TIME=0 get_traffic() { t=`awk '/eth0:/ { printf("%s,%d,%d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev` IN=${t#*,}; IN=${IN%,*} OUT=${t##*,}; TIME=${t%%,*}; } get_traffic $1 while true do  _IN=$IN  _OUT=$OUT  _TIME=$TIME get_traffic $1 echo "$TIME,$IN,$(( $IN - $_IN )),$(( $OUT - $_OUT))" sleep 1 done 

something to get you started (just in case you want to write it yourself):

#!/bin/bash # # usage: bwmon PID IN=0; OUT=0; TIME=0 get_traffic() { t=`awk '/eth0:/ { printf("%s,%d,%d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev` IN=${t#*,}; IN=${IN%,*} OUT=${t##*,}; TIME=${t%%,*}; } get_traffic $1 while true do _IN=$IN; _OUT=$OUT; _TIME=$TIME get_traffic $1 echo "$TIME,$(( $TIME - $_TIME )),$IN,$(( $IN - $_IN )),$OUT,$(( $OUT - $_OUT))" sleep 1 done 

comments:

  • checks only eth0
  • checks every 1 second
  • works only under linux, but other unixes work similar (procfs or whatever)
  • output could be stored into a sqlite.db with stat --printf="%N\n" /proc/PID/exe | cut -d ' ' -f 3
added 334 characters in body
Source Link
akira
  • 1.1k
  • 6
  • 13

something to get you started (just in case you want to write it yourself):

 #!/bin/shbash # # whileusage: true;bwmon doPID   IN=0 OUT=0 TIME=0 get_traffic() {  awkt=`awk '/eth0:/ { printf("%s,%d, %d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/devdev` IN=${t#*,}; IN=${IN%,*} OUT=${t##*,};  sleep TIME=${t%%,*}; } get_traffic $1 while true do   _IN=$IN _OUT=$OUT _TIME=$TIME get_traffic $1 echo "$TIME,$IN,$(( $IN - $_IN )),$(( $OUT - $_OUT))" sleep 1 done 

usage: sh bwmon.sh PID

something to get you started (just in case you want to write it yourself):

 #!/bin/sh while true; do   awk '/eth0:/ { printf("%s,%d, %d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev sleep done 

usage: sh bwmon.sh PID

something to get you started (just in case you want to write it yourself):

#!/bin/bash # # usage: bwmon PID  IN=0 OUT=0 TIME=0 get_traffic() {  t=`awk '/eth0:/ { printf("%s,%d,%d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev` IN=${t#*,}; IN=${IN%,*} OUT=${t##*,};   TIME=${t%%,*}; } get_traffic $1 while true do   _IN=$IN _OUT=$OUT _TIME=$TIME get_traffic $1 echo "$TIME,$IN,$(( $IN - $_IN )),$(( $OUT - $_OUT))" sleep 1 done 
Source Link
akira
  • 1.1k
  • 6
  • 13

something to get you started (just in case you want to write it yourself):

 #!/bin/sh while true; do awk '/eth0:/ { printf("%s,%d, %d\n",strftime("%s"),$2,$10); }' < /proc/$1/net/dev sleep done 

usage: sh bwmon.sh PID