3 .\" Copyright 2001-2010, Emil Mikulic.
5 .\" You may use, modify and redistribute this file under the terms of the
6 .\" GNU General Public License version 2. (see COPYING.GPL)
8 .TH darkstat 8 "September 2008" "darkstat 3"
10 darkstat \- network statistics gatherer
19 .BI \-\-snaplen " bytes"
43 .BI \-l " network/netmask"
47 .BI \-\-user " username"
49 .BI \-\-daylog " filename"
51 .BI \-\-import " filename"
53 .BI \-\-export " filename"
55 .BI \-\-pidfile " filename"
57 .BI \-\-hosts\-max " count"
59 .BI \-\-hosts\-keep " count"
61 .BI \-\-ports\-max " count"
63 .BI \-\-ports\-keep " count"
65 .BI \-\-highest\-port " port"
72 is a packet sniffer that runs as a background process,
73 gathers all sorts of statistics about network usage,
74 and serves them over HTTP.
76 All settings are passed on the commandline.
82 Capture traffic on the specified network interface.
83 This is the only mandatory commandline argument.
87 Instead of capturing live traffic, read it from a
90 This is only useful for development and benchmarking.
95 arguments are mutually exclusive.
98 .BI \-\-snaplen " bytes"
99 How many bytes to capture from the start of each packet.
100 You should not need to specify this;
101 \fIdarkstat\fR will calculate it automatically.
107 Instead, capture on the tunnel interface that your PPPoE software
108 provides, for example \fBtun0\fR on \fIFreeBSD\fR, \fBpppoe0\fR on
109 \fIOpenBSD\fR or \fINetBSD\fR.
111 If you really must, you can capture on an Ethernet interface and pass
112 this argument to have \fIdarkstat\fR decode PPPoE frames and ignore
114 Make sure you also specify your local address with the \fB\-l\fR
119 Errors, warnings, and verbose messages will go to \fBsyslog\fR (facility
120 daemon, priority debug) instead of \fBstderr\fR.
122 On some systems, these messages end up in \fB/var/log/debug\fR
127 Produce more verbose debugging messages.
131 Do not detach from the controlling terminal;
132 stay in the foreground.
136 Do not use promiscuous mode to capture.
137 Note that an interface may already be in promiscuous mode, or may later
138 enter promiscuous mode, due to circumstances beyond \fIdarkstat\fR's control.
139 If this is a problem, use \fB\-f\fR to specify an appropriate
145 Do not resolve IPs to host names.
146 This can significantly reduce memory footprint on small systems
147 as an extra process is created for DNS resolution.
151 Do not display MAC addresses in the hosts table.
155 Do not display the last seen time in the hosts table.
159 Bind the web interface to the specified port.
164 Bind the web interface to the specified address.
165 The default is to listen on all interfaces.
169 Use the specified filter expression when capturing traffic.
170 The filter syntax is beyond the scope of this manual page;
176 .BI \-l " network/netmask"
177 Define a "local network" according to the network and netmask addresses.
178 All traffic entering or leaving this network will be graphed, as opposed
179 to the default behaviour of only graphing traffic to and from the local
183 The rule is that if \fBip_addr & netmask == network\fR,
184 then that address is considered local.
185 See the usage example below.
189 .BI \-\-chroot " dir"
190 Force \fIdarkstat\fR to \fBchroot()\fR into the specified directory.
191 Without this argument, a default directory will be used, which is
192 determined at build time.
193 Usually \fI/var/empty\fR or \fI/var/lib/empty\fR.
196 For security reasons, this directory should be empty, and the user that
197 \fIdarkstat\fR is running as should not have write access to it.
199 However, if you wish to use \fB\-\-daylog\fR or \fB\-\-export\fR,
200 \fIdarkstat\fR will need write access to the chroot.
201 If you are uncomfortable with the security implications, don't
202 use any functionality that requires write access.
206 .BI \-\-user " username"
207 Force \fIdarkstat\fR to drop privileges to the \fBuid\fR and \fBgid\fR of
209 Without this argument, a default value will be used, which is set at
211 Usually \fBnobody\fR.
214 For security reasons, this should not be \fBroot\fR.
218 .BI \-\-daylog " filename"
220 Log daily traffic statistics into the named file, relative to the
222 If you wish to use \fB\-\-daylog\fR, you must first specify a
223 \fB\-\-chroot\fR directory, and it must be writeable by the
225 A writeable chroot has security implications; if you are uncomfortable
226 with this, do not use the \fB\-\-daylog\fR functionality.
228 If the daylog argument is not specified, no logging is performed.
230 The daylog format is:
232 localtime|time_t|bytes_in|bytes_out|pkts_in|pkts_outs
234 Lines starting with a # are comments stating when logging started and
239 .BI \-\-import " filename"
240 Upon starting, import a \fIdarkstat\fR database from the named file,
241 relative to the chroot directory.
242 If you wish to use \fB\-\-import\fR, you must first specify a
243 \fB\-\-chroot\fR directory.
244 If the import is unsuccessful, \fIdarkstat\fR will start with an empty
248 .BI \-\-export " filename"
249 On shutdown, and upon receiving SIGUSR1, export the in-memory database
250 to the named file, relative to the chroot directory.
251 If you wish to use \fB\-\-export\fR, you must first specify a
252 \fB\-\-chroot\fR directory, and it must be writeable by the
254 A writeable chroot has security implications - if you are uncomfortable
255 with this, do not use the \fB\-\-export\fR functionality.
258 .BI \-\-pidfile " filename"
260 Creates a file containing the process ID of \fIdarkstat\fR.
261 This file will be unlinked upon clean shutdown.
262 As with all pidfiles, if \fIdarkstat\fR dies uncleanly, a stale pidfile
265 For example, start \fIdarkstat\fR with:
267 darkstat \-i fxp0 \-\-chroot /var/run/darkstat \-\-pidfile darkstat.pid
271 kill `cat /var/run/darkstat/darkstat.pid`
275 will send SIGTERM, which will cause \fIdarkstat\fR to shut down cleanly.
279 .BI \-\-hosts\-max " count"
280 The maximum number of hosts that will be kept in the hosts table.
281 This is used to limit how much accounting data will be kept in memory.
288 .BI \-\-hosts\-keep " count"
289 When the hosts table hits
291 and traffic is seen from a new host, we clean out the hosts table,
294 number of hosts, sorted by total traffic.
297 .BI \-\-ports\-max " count"
298 The maximum number of ports that will be tracked for each host.
299 This is used to limit how much accounting data will be kept in memory.
306 .BI \-\-ports\-keep " count"
307 When a ports table fills up, this many ports are kept and the rest are
311 .BI \-\-highest\-port " port"
312 Ports that are numerically higher than this will not appear in the
313 per-host ports tables, although their traffic will still be accounted
315 This can be used to hide ephemeral ports.
316 By default, all ports are tracked.
320 Show hex dumps of received traffic.
321 This is only for debugging, and implies \fB\-\-verbose\fR and
322 \fB\-\-no\-daemon\fR.
324 .\" --------------------------------------------------------------------
326 To gather statistics on the
333 We want to account for traffic on the Internet-facing interface,
334 but only serve web pages to our private local network where we have the
335 IP address 192.168.0.1:
337 darkstat \-i fxp0 \-b 192.168.0.1
340 We want to serve web pages on the standard HTTP port:
342 darkstat \-i fxp0 \-p 80
345 We are on Optus (cable) and don't want to account for the constant ARP
346 traffic we are receiving:
348 darkstat \-i fxp0 \-f "not arp"
351 We only want to account for SSH traffic:
353 darkstat \-i fxp0 \-f "port 22"
356 We don't want to account for traffic between internal IPs:
358 darkstat \-i fxp0 \-f "not (src net 192.168.0 and dst net 192.168.0)"
361 (For a full reference on filter syntax, refer to the
366 We have a network consisting of a gateway server (192.168.1.1) and a few
367 workstations (192.168.1.2, 192.168.1.3, etc.) and we want to graph all
368 traffic entering and leaving the local network, not just the gateway
369 server (which is running \fIdarkstat\fR):
371 darkstat \-i fxp0 \-l 192.168.1.0/255.255.255.0
374 On some systems, we can't capture on a "decoded" interface but
375 only on \fInas0\fR which returns PPPoE encapsulated packets.
376 Do PPPoE decoding, and override the local IP manually since it
377 cannot be automatically detected.
378 Note the /32 netmask:
380 darkstat \-i nas0 \-\-pppoe \-l 192.168.1.1/255.255.255.255
385 down cleanly, send a SIGTERM or SIGINT signal to the
389 Sending the SIGUSR1 signal will cause \fIdarkstat\fR to empty out its
391 If an \fB\-\-export\fR file was set, it will first save the database to
395 .SH FREQUENTLY ASKED QUESTIONS
396 .SS How many bytes does each bar on the graph represent?
397 Hover your mouse cursor over a bar and you should get a tooltip
398 saying exactly how many bytes in and out the bar represents.
400 .SS Why aren't there labels / tics / a scale on the graphs?
401 Because implementing them is hard.
402 And doing so \fIcorrectly\fR, and in a way that works across all
403 browsers, looks pretty much impossible.
405 I might attempt it some day.
406 In the meantime, patches would be gladly accepted.
408 .SS Why are the graphs blank? All the bars are zero.
409 The graphs only show traffic in/out of the local host, which is
410 determined by getting the IP address of the interface you're sniffing
413 You can use the \fB\-l\fR argument to override the local address for
415 You can also use it to do accounting for a whole subnet by specifying
416 an appropriate netmask.
423 was written in 2001, largely as a result of a certain Australian
424 cable Internet provider introducing a 3GB monthly traffic limit.
427 Emil Mikulic and others. (see the AUTHORS file)
430 http://dmr.ath.cx/net/darkstat/