Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use GeekTool to track network data transfer rates Apps
I use GeekTool to display some network information for my MacBook on my desktop. One thing I couldn't find was a way to show the current transfer rate (in Kb/sec) in and out. So I wrote a shell script that calls on netstat, waits one second, calls on netstat again, and then uses the difference in the numbers to display how many kilobytes were sent or received during that second.

If you use ethernet instead of AirPort, you'll have to change en1 to the interface you need (probably en0). This could also be used to monitor your bluetooth speeds as well. To set this up, first create a file (I named mine inout.sh) and save it wherever you like. Insert the following code and save it:
#!/bin/sh
# created by chris helming.
# chris dot helming at gmail

# get the current number of bytes in and bytes out
myvar1=`netstat -ib | grep -e "en1" -m 1 | awk '{print $7}'` #  bytes in
myvar3=`netstat -ib | grep -e "en1" -m 1 | awk '{print $10}'` # bytes out

#wait one second
sleep 1

# get the number of bytes in and out one second later
myvar2=`netstat -ib | grep -e "en1" -m 1 | awk '{print $7}'` # bytes in again
myvar4=`netstat -ib | grep -e "en1" -m 1 | awk '{print $10}'` # bytes out again

# find the difference between bytes in and out during that one second
subin=$(($myvar2 - $myvar1))
subout=$(($myvar4 - $myvar3))

# convert bytes to kilobytes
kbin=`echo "scale=2; $subin/1024;" | bc`
kbout=`echo "scale=2; $subout/1024;" | bc`

# print the results
echo "in: $kbin Kb/sec"
echo "out: $kbout Kb/sec"
After saving your file, switch to GeekTool, click the New Entry button, give it a name (Net Activity), and set the pop-up on the right to Shell. On the Command tab, set the command to something like this: sh /path/to/inout.sh, replacing /path/to/ with the path to the folder containing the inout.sh file. I left the Refresh setting at 10, and so GeekTool updates my Kb/sec transfer rates every 10 seconds. It can be changed to whatever you want, though.

[robg adds: I tested this, and it works as described.]
    •    
  • Currently 3.38 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)
 
[43,343 views]  

Use GeekTool to track network data transfer rates | 14 comments | Create New Account
Click here to return to the 'Use GeekTool to track network data transfer rates' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use GeekTool to track network data transfer rates
Authored by: wordsofwisedumb on Mar 27, '09 08:05:11AM
Bandwidth Monitor NG would also allow you to monitor this information as well as disk IO: http://www.gropp.org/?id=projects&sub=bwm-ng

[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: JaxMyers on Mar 27, '09 08:10:37AM

Why don't you just use Activity Monitor in your Utilities folder? If can monitor and graph data transfer rates.



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: leamanc on Mar 27, '09 09:36:24AM

I'd say because he likes the way GeekTool displays items on the desktop.



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: toupsz on Mar 27, '09 09:43:32AM
I prefer MenuMeters (http://www.ragingmenace.com/software/menumeters/) -- shows me in and out traffic in my menubar!

Best,
-Zach

[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: derelictstatic on Mar 27, '09 10:30:32AM

iStat menus also covers this pretty well. its menu dropdown also offers links to copy your current ip address and open network prefs/utility.



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: rpaege on Mar 27, '09 11:30:52AM

This works great! Many thanks for a useful little tool.



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: ghay on Mar 27, '09 01:03:11PM

I love geektool, but it seems very buggy to me.

Anyone got any alternatives?



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: mael on Aug 22, '09 02:32:23PM
Yes, absolutely. Try this: http://www.macupdate.com/info.php/id/31909

NerdTool is free, very compatible to GeekTool (you can even import its scripts), very stable and there are still developers working on it.

[ Reply to This | # ]
Or use netstat -w 1
Authored by: Pedro Estarque on Mar 27, '09 01:15:37PM

no need to keep calling it every second, simply do netstat -w 1



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: gecko2 on Mar 27, '09 02:04:21PM

An other way is adding the following line to your .profile:

traffic() { netstat -w1 -I"$@"; };

start a new shell and type:

traffic en0 # change en0 to the name of the interface you want to monitor

if you got enough, just cancel with ^C



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: gecko2 on Mar 27, '09 02:07:25PM

... or use "all" as the interfacename to see the traffic on all interfaces



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: CarlRJ on Mar 27, '09 09:30:18PM
I, too, recommend iStat menus for this and similar tasks, but if you want to go shell script/GeekTool, it's fairly easy to change the script to run only about a third as many external commands (also, not everyone has /usr/sbin on their path):

#!/bin/sh

INTF=en1

# get the current number of bytes in and bytes out
sample1=(`/usr/sbin/netstat -ib | awk "/$INTF/"'{print $7" "$10; exit}'`)

# wait one second
sleep 1

# get the number of bytes in and out one second later
sample2=(`/usr/sbin/netstat -ib | awk "/$INTF/"'{print $7" "$10; exit}'`)

# find the difference between bytes in and out during that one second
# and convert bytes to kilobytes
results=(`echo "2k ${sample2[0]} ${sample1[0]} - 1024 / p" \
		  "${sample2[1]} ${sample1[1]} - 1024 / p" | dc`)

# print the results
printf "in: %.2f Kb/sec\nout: %.2f Kb/sec\n" ${results[0]} ${results[1]}


[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: mael on Aug 22, '09 02:06:51PM

Hi,

does anybody else have a problem with the last line?
> printf "in: %.2f Kb/sec\nout: %.2f Kb/sec\n" ${results[0]} ${results[1]}
Unfortunately I'll get the following error: "printf: invalid number".

Could this have something to do with my system settings? Here in Europe we usually expect a comma instead of a decimal point? Could it be that printf expects a comma but finds a decimal point and coughs up?



[ Reply to This | # ]
Use GeekTool to track network data transfer rates
Authored by: post_break on Mar 29, '09 09:46:28PM

How about using bmon instead? Personally that does the job pretty easily.



[ Reply to This | # ]