Bandwidth Pie -- a bandwidth-usage pie chart system for Linux. Adam Sampson This software is under the MIT license. -- What is it? -- The purposes of Bandwidth Pie is to draw pie charts showing the usage per machine of a network link. Here at fivegeeks.net, we use it to show who's using our ADSL bandwidth -- for an example, have a look at the pie charts on . It requires iptables (which implies Linux 2.4 or later), Perl and the Perl GD module ("install GD" in CPAN, or the "libgd-perl" package in Debian). GD must be built with TTF support. I'm aware that it's not exactly superb -- it was an evening's hack, and I've written this README because other people seemed to be interested. Before proceeding any further, note that installation will require some knowledge of Perl and sh; I wouldn't suggest installing this if you're not familiar with these. -- How it works -- A set of iptables rules are created which filter all traffic incoming and outgoing for each machine through appropriately-named chains. The bandwidthpie.pl script is run periodically to create a couple of image files showing the traffic going in and out; it uses a stats file on disk somewhere to keep track of the counts between runs. -- Installation -- You're assumed to be installing this on the machine that's the gateway for the link you're interested in. 1. Copy bandwidthpie.pl and pie-firewall.sh somewhere convenient, like root's home directory. 2. Edit bandwidthpie.pl to set the location of the stats file and the generated graphs, and to point at an appropriate TrueType font. (I use the Luxi Sans font that comes with XFree86.) The stats file needs to be somewhere writable by root that isn't blown away at boot time (so /var/state is generally a good choice); the graphs should be put wherever you want them (for instance, in a directory served by your webserver). 3. Create the stats file to ensure that it exists (if you don't do this, bandwidthpie.pl will complain when you run it): "echo 0 >/var/state/net_stats". 4. Edit pie-firewall.sh to list the machines you're interested in at the bottom. If a machine has more than one IP address, make sure you list all of them in the same line (assuming you want them accounted as the same machine). Note: we run an HTTP proxy server on port 80 of our gateway machine, and we want to account for that as well. If you run a proxy on a different port, adjust the two marked lines in pie-firewall.sh. 5. Arrange things so that pie-firewall.sh gets run at the appropriate stage during your firewall initialisation: it should be run before any other firewall rules are added, but make certain not to clear the chains after it's been run! (Effectively, look for lines that do something like "iptables -F INPUT" in your existing firewall script, and add a line to run pie-firewall.sh after that.) 6. Run your firewall setup and bandwidthpie.pl by hand to check that they work. Neither should complain, and bandwidthpie.pl should create the graph files. (If something breaks, check that the firewall rules were added correctly with "iptables -vnxL".) 7. Arrange things so that bandwidthpie.pl gets run every minute (or however often you want the graphs updated). One way to do this is to add a line to /etc/crontab: * * * * * root perl /root/bandwidthpie.pl 2>/dev/null >/dev/null 8. It should Just Work (tm). -- But it doesn't! -- "Tough." As I said, this wasn't designed to be particularly reliable software; ask me if you've got questions about it, but don't necessary expect a quick answer. ;) If you've got ideas for improvements, though, let me know. I'm aware that pie charts probably aren't the best way of representing this information, but they're quite pretty. - Adam Sampson, 5th April 2003 -- History -- 1.0 - Initial release. 1.1 - Avoid undefined errors when new machines appear. - Use TTF font rendering.