Thought I’d post a new thread for this, since the System Monitoring one is getting long. One more metric I was interested in monitoring was the amount of traffic specifically going to FlightAware. I noticed that as my site started receiving a lot more traffic based on the antenna/amp/location changes I made, total transmit bandwidth was adding up to about 8+ GB per day - of course the vast majority of that is internal to my network, to my VRS server, etc. However, I wanted the data, so I created some iptables firewall rules, then used collectd’s iptables plugin to monitor traffic hitting those rules. I thought I’d post this, in case anyone is interested.
http://i.imgur.com/wnf1Q8D.png
The first thing you need to do is create the iptables rules. All the connections I’ve seen my Pi make are to the 70.42.0.0/16 subnet, but perhaps FA staff can comment if there are others, or you can check it on your own Pi by doing a ‘sudo netstat -n |grep 1200’ then modifying the rules below. These should catch both the regular ADS-B traffic and the fa-mlat-client traffic.
sudo iptables -N flightaware
sudo iptables -A OUTPUT -d 70.42.0.0/16 -j flightaware -m comment --comment "fa-ip-range-out"
sudo iptables -A INPUT -s 70.42.0.0/16 -j flightaware -m comment --comment "fa-ip-range-in"
Then save them using iptables-save:
sudo iptables-save > /etc/firewall.conf
Create the file /etc/network/if-pre-up.d/iptables containing the following:
#!/bin/sh
/sbin/iptables-restore < /etc/firewall.conf
Make it executable with sudo chmod +x /etc/network/if-pre-up.d/iptables. These last few steps will ensure the rules survive a reboot.
Configure collectd.conf to read these rules:
LoadPlugin "iptables"
<Plugin "iptables">
Chain "filter" "OUTPUT" "fa-ip-range-out"
Chain "filter" "INPUT" "fa-ip-range-in"
</Plugin>
Restart collectd, and you should have two new folders of rrd files in /usr/lib/collectd/rrd/…
Finally, here is the graphing function:
net_fa_graph() {
rrdtool graph \
"$1" \
--start end-$4 \
--width 480 \
--height 200 \
--step "$5" \
--title "FlightAware Bandwidth Usage" \
--vertical-label "bytes/sec" \
"TEXTALIGN:center" \
"DEF:rx=$2/iptables-filter-INPUT/ipt_bytes-fa-ip-range-in.rrd:value:AVERAGE" \
"DEF:tx=$2/iptables-filter-OUTPUT/ipt_bytes-fa-ip-range-out.rrd:value:AVERAGE" \
"CDEF:tx_neg=tx,-1,*" \
"AREA:rx#32CD32:Incoming" \
"LINE1:rx#336600" \
"GPRINT:rx:MAX:Max\: %4.1lf %sB/sec" \
"GPRINT:rx:AVERAGE:Avg\: %4.1lf %SB/sec" \
"GPRINT:rx:LAST:Current\: %4.1lf %SB/sec\c" \
"AREA:tx_neg#4169E1:Outgoing" \
"LINE1:tx_neg#0033CC" \
"GPRINT:tx:MAX:Max\: %4.1lf %sB/sec" \
"GPRINT:tx:AVERAGE:Avg\: %4.1lf %SB/sec" \
"GPRINT:tx:LAST:Current\: %4.1lf %SB/sec\c" \
"HRULE:0#000000" \
--watermark "Drawn: $nowlit";
}
# This goes in the common_graphs() function - adjust the paths accordingly:
net_fa_graph /srv/www/htdocs/collectd/$2-netfa-$4.png /var/lib/collectd/rrd/$1 "$3" "$4" "$5"