• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

etc/H11-Jan-2005-543

htdocs/H03-May-2022-

phphtdocs/H03-May-2022-868682

CHANGELOGH A D11-Jan-20056.3 KiB143128

INSTALL.UnixH A D11-Jan-2005612 2114

INSTALL.WindowsH A D11-Jan-2005772 2215

Makefile.inH A D03-May-20221.6 KiB5131

READMEH A D11-Jan-200513.1 KiB282222

TODOH A D07-Jan-2005658 1713

bandwidthd.cH A D11-Jan-200537.2 KiB1,2881,028

bandwidthd.hH A D11-Jan-20055.2 KiB220156

conf.lH A D02-Jan-20051 KiB3229

conf.l.cH A D11-Jan-200542.6 KiB1,7131,184

conf.tab.cH A D11-Jan-200536.4 KiB1,424949

conf.tab.hH A D11-Jan-20052.5 KiB9355

conf.yH A D09-Jan-20053.1 KiB214186

config.guessH A D09-Jan-200538.1 KiB1,3611,184

config.h.inH A D11-Jan-20054.6 KiB177119

config.subH A D09-Jan-200527.2 KiB1,3761,236

configureH A D03-May-2022175.1 KiB6,2345,461

configure.inH A D11-Jan-20053.7 KiB12192

graph.cH A D11-Jan-200532.8 KiB927732

install-shH A D09-Jan-20055.5 KiB252153

schema.postgresqlH A D07-Jan-20051.4 KiB6560

README

1Programmed by David Hinkle, Commissioned by DerbyTech of Illinois.
2Special thanks goes to Brice Beaman at brice@beamans.org for releasing
3the software, testing and debugging, Blaze at ts@spective.net for his
4excellent logo, Andreas Henriksson for polishing, testing, fixing, and
5all the guys at havok for distributing clue.
6
7#### LISCENCE #
8You may use this software under any version of the GPL that is current
9as of your download.  For exact terms and conditions please see www.gnu.org.
10
11#### WHAT IT IS #
12Bandwidthd is a UNIX daemon/Windows service for graphing the traffic
13generated by each machine on several configurable subnets.  It is much
14easier to configure than MRTG, and provides significantly more useful
15information.  MRTG only tells you how much bandwidth you are using,
16Bandwidthd tells you that, and who is using it.
17
18Each IP address that has moved any significant volume of traffic has its
19own graph.  The graphs are color coded to help you figure out at a glance
20if your user is surfing the web, or surfing Kazaa.
21
22Bandwidthd is targeted to run on my routing platforms.  It is very low
23overhead.  Easily graphing small business traffic on a 133Mhz Elan 486
24every 2.5 minutes. My entire ISP (2000-3000 IP addresses across 4 states)
25is graphed on a Celeron 450 every 10 minutes.
26
27#### PORTABILITY #
28Bandwidthd compiles clean on:
29
30ix86	Solaris 9
31		Debian 2.2
32		Fedora Core 2
33		OpenBSD 3.4
34		FreeBSD 4.8
35		NetBSD 1.6.1
36AMD64	Fedora Core 3
37PPC G4 	MacOSX 10.2
38
39Thanks goes to SourceForge for providing the test platforms.
40
41#### CONFIGURATION INSTRUCTIONS #
42There are now two ways to install Bandwidthd.  The fast easy way, which uses
43the built in Bandwidthd graphing system to generate static HTML pages and graphs,
44and the much more complicated way that supports multiple sensors, stores it's
45data in a back end database, and generates reports and graphs with easily
46customized php scripts.
47
48If you are new to Bandwidthd I would recommend just installing it the following the
49instructions in the bandwidthd.conf file.  If you are interested in customizing
50your output or you need a more scalable solution, you can always come back and
51jump through the database hoops later.
52
53See "DATABASE SUPPORT" for information on Bandwidthd's advanced configuration.
54
55#### GRAPHING INTERVAL #
56Bandwidthd defaults to graph up to 4000 local IPs every 200 seconds.  If you need
57to track more IPs, change IP_NUM in bandwidthd.h.
58
59The weekly graph updates every 10 minutes, monthly every hour, and yearly every
6012 hours.
61
62A graphing run will automatically be "skipped" if that last one isn't finished
63before the new one would begin.
64
65#### CDF LOGGING #
66Bandwidthd can be made to log to CDF by setting "output_cdf" to true. This will
67now log out each interval's traffic, so you can import them into a database and
68use a tool like access to create your own graphs, or implement 95 percentile
69billing, for example.  Sending Bandwidthd a HUP will cause it to rotate it's logs.
70It will rotate out 5 times before deleting the oldest log file.
71
72These logs are log.1.0.cdf-log.1.5.cdf for daily, log.2.0.cdf-log.2.5.cdf for
73weekly, etc, etc.
74
75If you are upgrading from an older version of Bandwidthd from before all 4 logs
76rotated you must rename your log files for the new Bandwidthd to find them:
77
78mv log.cdf log.1.0.cdf
79mv log.1.cdf log.1.1.cdf
80mv log.2.cdf log.1.2.cdf
81mv log.3.cdf log.1.3.cdf
82mv log.4.cdf log.1.4.cdf
83mv log.5.cdf log.1.5.cdf
84mv log2.cdf log.2.1.cdf
85mv log3.cdf log.3.1.cdf
86mv log4.cdf log.4.1.cdf
87
88The log format is best documented in the "StoreIPDataInCDF" function in
89bandwidthd.c.  As of this writing, it consists of one line for each  IP address
90for each interval.  The line contains only data for the previous interval.
91
92Fields:
93IP Address,Timestamp,Total Sent,Icmp Sent,Udp Sent,Tcp Sent,Ftp Sent,Http Sent, P2P Sent,Total Received,Icmp Received,Udp Received,Tcp Received,Ftp Received,Http Received, P2P Received
94
95#### HOW TO KEEP YOUR GRAPHS BETWEEN REBOOTS #
96Following is the easy way to keep your graphs between reboots.  You can also opt
97to build and use bandwidthd with database support, as described in "DATABASE SUPPORT"
98below.
99
100In the bandwidthd.conf file set:
101output_cdf true
102recover_cdf true
103
104output_cdf will cause Bandwidthd to log all of it's data to the log.cdf file
105in it's directory.  recover_cdf will cause Bandwidthd to load that file when
106it starts.   You will also want to make a crontab entry like so:
107
1080 0 * * * * /bin/kill -HUP `cat /var/run/bandwidthd.pid`
109
110This will send Bandwidthd a HUP every night at midnight.  When Bandwidthd
111receives a HUP it schedules a rotation of it's log files during the next
112graphing run.  Daily log files rotate each HUP.  Weekly/Monthly/Yearly log
113files rotate every so many HUPs.  Log files get rotated out 5 times before
114deletion.
115
116Fyi, if you use killall instead of kill, each of the children will receive
117the HUP command twice, causing them to rotate their log files twice as
118often as they should.
119
120#### GRAPHING
121Also note that Bandwidthd does not bother to graph an IP that has transmitted
122less than 1Mbit of data.  It does however, include that IP in the table of IPs
123at the top of the page, so it's traffic can still be viewed.  This cutoff can be
124changed by modifying graph_cutoff in bandwidthd.conf.  "graph_cutoff" is in
125kilobytes.
126
127Graphing can be disabled by setting "graph" to false.  This will still log, but
128will use almost no ram or CPU cycles.
129
130#### COLOR CODES #
131RED 	ICMP
132BROWN	UDP
133YELLOW	IP ENCAPSULATED (IP over IP, IPSEC, most VPN's)
134BLUE 	HTTP (Port 80 TCP, actually)
135PURPLE	Peer2Peer (Lots of TCP ports generally used by P2P software)
136GREEN	TCP
137
138#### SPECIFYING THE LIBPCAP FILTER #
139if you'd like more control over what traffic is counted, you can specify a Manuel
140filter to be passed to libpcap.  You can use this to remove certain IPs or only
141graph certain IPs, or limit the graphs to certain kinds of traffic.  You should
142always specify "ip" in the filter.  For example:
143
144filter "ip and host 64.215.40.1"
145
146#### HOW TO IMPROVE PERFORANCE #
147Bandwidthd's primary bottleneck in static HTML mode is the drawing of graphs for
148IP addresses.  To improve bandwidthd's performance, therefore, the only thing you
149can really do is reduce the number of graphs it has to draw in any given run.
150Adjust graph_cutoff in the bandwidthd.conf file in order to tune out the IP addresses
151that don't use so much bandwidth.  These IP addresses will still have their data
152displayed in the table at the top of the page, so you can still see what's going
153on with them.
154
155Alternatively, you can choose to graph less often.  Bandwidthd automatically skips
156a graphing run if the last one is still going when the new one is scheduled to start.
157If you'd like to graph less often than your server is capeable of, you can edit
158skip_intervals in bandwidthd.conf.  A value of 1means to skip every other interval,
1593 would mean to skip three intervals between each run.  This doesn't disable
160Bandwidthd's automatic skipping.
161
162Also, you can choose to deploy Bandwidthd with database support, which provides
163significant performance gains.
164
165#### DATABASE SUPPORT #
166
167Since version 2.0, Bandwidthd now has support for external databases.  This system
168consists of 3 major parts:
169
1701. The Bandwidthd binary which acts as a sensor, recording traffic information and
171storing it in a database across the network or on the local host.  In this mode
172Bandwidthd uses very little ram and CPU. In addition, multiple sensors can record
173to the same database.
174
1752. The database system.  Currently Bandwidthd only supports Postgresql.
176
1773. The webserver and php application.  Bundled with Bandwidthd in the "phphtdocs"
178directory is a php application that reports on and graphs the contents of the database.
179This has been designed to be easy to customize.  Everything is passed around on the urls,
180just tinker with it a little and you'll see how to generate custom graphs pretty easy.
181
182Using Bandwidthd with a database has many advantages, such as much lower overhead, because
183graphs are only graphed on demand.  And much more flexibility, SQL makes building new
184reports easy, and php+sql greatly improves the interactivity of the reports.
185
186My ISP has now switched over to the database driven version of bandwidthd entirely, we
187have half a dozen sensors sprinkled around the country, writing millions of data points a
188day on our customers into the system.
189
190INSTRUCTIONS
191
192As a prerequisite for these instructions, you must have Postgresql installed and working,
193as well as a web server that supports php.
194
195Database Setup:
1961. Create a database for Bandwidthd.  You will need to create users that can access the
197database remotely if you want remote sensors.
198
1992. Bandwidthd's schema is in "schema.postgresql".  "psql mydb username < schema.postgresql"
200should load it and create the 2 tables and 4 indexes.
201
202Bandwidthd Setup:
2031. Add the following lines to your bandwidthd.conf file:
204
205# Standard postgres connect string, just like php, see postgres docs for
206# details
207pgsql_connect_string "user = someuser dbname = mydb host = databaseserver.com"
208# Arbitrary sensor name, I recommend the sensors fully qualified domain
209# name
210sensor_id "sensor1.mycompany.com"
211# Tells Bandwidthd to keep no data and preform no graphing locally
212graph false
213# If this is set to true Bandwidthd will try to recover the daily log
214# into the database.  If you set this true on purpose only do it once.
215# Bandwidthd does not track the fact that it has already transferred
216# certain records into the database.
217recover_cdf false
218
2194. Simply start bandwidthd, and after a few minutes data should start appearing in
220your database.  If not, check syslog for error messages.
221
222Web Server Setup:
2231. Copy the contents of phphtdocs into your web tree some where.
2242. Edit config.conf to set your db connect string
225
226You should now be able to access the web application and see you graphs.  All graphing
227is done by graph.php,  all parameters are passed to it in it's url.  You can create
228custom urls to pull custom graphs from your own index pages, or use the canned
229reporting system.
230
231In addition, you should schedule bd_pgsql_purge.sh to run every so often.  I recomend
232running it weekly.  This script outputs sql statements that aggregate the older
233data points in your database in order to reduce the amount of data that needs to
234be slogged through in order to generate yearly, monthly, and weekly graphs.
235
236Example:
237bd_pgsql_purge.sh | psql bandwidthd postgres
238
239Will connect to the bandwidthd database on local host as the user postgres and summarize
240the data.
241
242# KNOWN BUGS AND TROUBLESHOOTING #
243
244If Bandwidthd shows you nothing but a message saying "Bandwidthd has nothing to graph",
245that means it currently has recorded no data.  The cause is most likely one of these:
2461. It's first interval hasn't expired yet (2.5 minutes).
2472. It is still chewing through large CDF logs.
2483. Bandwidthd's host machine is on a switch and therefor isn't seeing any traffic not
249   destined to or from or going through it.
2504. You don't have a subnet line.
2515. You have a subnet line but it doesn't match any of the packets Bandwidthd is seeing.
2526. You have a filter line that is filtering out all the traffic Bandwidthd could be seeing.
253
254Bandwidthd doesn't do a very good job of tracking ftp.  This is because only some ftp
255server software follows the rfc standard of sourceing all ftp transfers from port 20.
256Surprisingly, Microsofts ftp daemon is compliant in this regard, whereas most open source
257daemons are not.
258
259Bandwidthd forks to perform it's graphing functions.  After this fork finishes it remains
260as a zombie until the next interval, at which time it is reaped by the main process.
261This zombie is nothing to worry about, it's just an entry in the process table waiting
262to be deleted.  With the new weekly, monthly, yearly graphs you'll have up to 4 zombies now.
263
264By default, Bandwidthd now runs in promiscuous mode.  This means it can be used to monitor
265traffic not routing through it's host.  Just make sure that the host and the actual router
266are on the same hub (Not switch) and everything will be ok. Under some circumstances, traffic
267may get counted twice.  If traffic routes to the other router, then routes back out along
268the same wire, it may get counted twice by Bandwidthd.  This is much less of a problem than
269you might think, due to a little known packet called an "icmp redirect" that causes all packets
270after the first to go directly to it's target.  If you find that traffic looks like it's
271getting counted twice, make sure you're not firewalling off the icmp redirects. If you find that
272you actually see none of this traffic, it may be because the icmp redirects cause it to ultimately
273end up going from one port on a switch to another, never touching your hub. If you want
274Bandwidthd to only see traffic actually going into and out of the host set "promiscuous" to
275false in bandwidthd.conf.
276
277Bandwidthd supports ethernet, Linux cooked sockets, raw, and token ring, and most ppp packet
278encapsulation.  If you get an "Unknown Datalink Type" error, Bandwidthd has not been programed
279to handle the physical encapsulation of the ip packets on that interface.  If you send me a
280sample capture and a copy paste of the error message I'll see if I can make bandwidthd work for you.
281
282