Révision be7d3f82
Fix regexp in case iptables returns huge numbers. It may not have spaces at the begin of the line.
Make use of state file so that the plugin doesn't show an increasing jauge, but a current network usage
| plugins/network/traffic_ipt | ||
|---|---|---|
| 36 | 36 |
|
| 37 | 37 |
=item 2013.02.03: Converted to use iptables/ip6tables by Michiel Holtkamp <michiel@supermind.nl> |
| 38 | 38 |
|
| 39 |
=item 2015.01.25: Fixed regexp and make use of a status file by Pierre Schweitzer <pierre@reactos.org> |
|
| 40 |
|
|
| 39 | 41 |
=back |
| 40 | 42 |
|
| 41 | 43 |
=head1 LICENSE |
| ... | ... | |
| 49 | 51 |
|
| 50 | 52 |
=cut |
| 51 | 53 |
|
| 54 |
STAT_FILE=$MUNIN_PLUGSTATE/plugin-traffic_ipt.state |
|
| 52 | 55 |
|
| 53 | 56 |
if [ "$1" == "config" ] |
| 54 | 57 |
then |
| ... | ... | |
| 100 | 103 |
exit 0 |
| 101 | 104 |
fi |
| 102 | 105 |
|
| 106 |
if [ ! -r $STAT_FILE ]; then |
|
| 107 |
oldv4=0 |
|
| 108 |
oldv6=0 |
|
| 109 |
else |
|
| 110 |
oldv4=$(grep IPv4 $STAT_FILE | cut -f2 -d '=') |
|
| 111 |
oldv6=$(grep IPv6 $STAT_FILE | cut -f2 -d '=') |
|
| 112 |
fi |
|
| 103 | 113 |
|
| 104 | 114 |
ipv4=0 |
| 105 | 115 |
ipv6=0 |
| 116 |
diffv4=0 |
|
| 117 |
diffv6=0 |
|
| 106 | 118 |
|
| 107 |
IPv4_bytes=$(iptables -L -n -v -x | egrep '^\W+[0-9]+\W+[0-9]+\W+all\W+--\W+\*\W+\*\W+0.0.0.0/0\W+0.0.0.0/0\W+$' | while read pkts bytes rest; do echo $bytes; done)
|
|
| 119 |
IPv4_bytes=$(iptables -L -n -v -x | egrep '^\W*[0-9]+\W+[0-9]+\W+all\W+--\W+\*\W+\*\W+0.0.0.0/0\W+0.0.0.0/0\W*$' | while read pkts bytes rest; do echo $bytes; done)
|
|
| 108 | 120 |
if [ -z "$IPv4_bytes" ]; |
| 109 | 121 |
then |
| 110 | 122 |
echo "W: Unable to read rule from iptables, please add rules" >&2 |
| ... | ... | |
| 112 | 124 |
ipv4=$(echo $IPv4_bytes | sed -e 's/ / + /' | bc -l) |
| 113 | 125 |
fi |
| 114 | 126 |
|
| 115 |
IPv6_bytes=$(ip6tables -L -n -v -x | egrep '^\W+[0-9]+\W+[0-9]+\W+all\W+\*\W+\*\W+::/0\W+::/0\W+$' | while read pkts bytes rest; do echo $bytes; done)
|
|
| 127 |
IPv6_bytes=$(ip6tables -L -n -v -x | egrep '^\W*[0-9]+\W+[0-9]+\W+all\W+\*\W+\*\W+::/0\W+::/0\W*$' | while read pkts bytes rest; do echo $bytes; done)
|
|
| 116 | 128 |
if [ -z "$IPv6_bytes" ]; |
| 117 | 129 |
then |
| 118 | 130 |
echo "W: Unable to read rule from ip6tables, please add rules" >&2 |
| ... | ... | |
| 120 | 132 |
ipv6=$(echo $IPv6_bytes | sed -e 's/ / + /' | bc -l) |
| 121 | 133 |
fi |
| 122 | 134 |
|
| 123 |
echo "IPv4.value $ipv4" |
|
| 124 |
echo "IPv6.value $ipv6" |
|
| 125 |
echo "total.value $( echo $ipv4 + $ipv6 | bc )" |
|
| 135 |
if [ $ipv4 -ge $oldv4 ]; |
|
| 136 |
then |
|
| 137 |
diffv4=$(($ipv4 - $oldv4)) |
|
| 138 |
else |
|
| 139 |
diffv4=$ipv4 |
|
| 140 |
fi |
|
| 126 | 141 |
|
| 127 |
exit 0 |
|
| 142 |
if [ $ipv6 -ge $oldv6 ]; |
|
| 143 |
then |
|
| 144 |
diffv4=$(($ipv6 - $oldv6)) |
|
| 145 |
else |
|
| 146 |
diffv4=$ipv6 |
|
| 147 |
fi |
|
| 128 | 148 |
|
| 149 |
echo "IPv4=$ipv4" > $STAT_FILE |
|
| 150 |
echo "IPv6=$ipv6" >> $STAT_FILE |
|
| 151 |
|
|
| 152 |
echo "IPv4.value $diffv4" |
|
| 153 |
echo "IPv6.value $diffv6" |
|
| 154 |
echo "total.value $( echo $diffv4 + $diffv6 | bc )" |
|
| 155 |
|
|
| 156 |
exit 0 |
|
Formats disponibles : Unified diff