On Fri, 31 May 2002 13:43:18 +1200 Greg Ford wrote:
> Hi Cam
>
> >My ISP will soon be imposing transfer limits of 5GB/month.
> >Can Dachstein give me a report of how much I have used?
>
> I've done a lot of work on a similar problem - as
> traffic costs in NZ appear to be at least an
> order of magnitude more than in the US.
>
> >I have not seen it in the weblet.
> The "network setup" option shows total packets and bytes on each interface.
> (this may get reset if you have a PPP connection that is restarted
> frequently??? I don't use PPP so I have no idea.)
[description of very good ipchains solution snipped]
If you want pull just the number of bytes transmitted and received
by a particular interface, the following kludge of a script should
work. It uses /proc/net/dev [1] just like weblet's "Network Setup"
-> "Statistics" section, but parses the data to make it more
readable.
#!/bin/sh
IFACE=eth0
RX_BYTES=`sed -n -e "/$IFACE/ s/[ :]\+/\|/gp" /proc/net/dev \
| cut -d "|" -f 4`
TX_BYTES=`sed -n -e "/$IFACE/ s/[ :]\+/\|/gp" /proc/net/dev \
| cut -d "|" -f 12`
echo "Bytes received: $RX_BYTES"
echo "Bytes transmitted: $TX_BYTES"
(Improvement suggestions welcomed. It's probably obvious that I
am *far* from a sed guru.)
You could integrate it into weblet by adding a section to
/var/sh-www/cgi-bin/viewnet like this:
IFACE=eth0
t_head "$IFACE Byte Counts"
cat <<- /BYTECOUNTCONTENT
<tr>
<td><div><PRE>
Bytes Received: $(sed -n -e "/$IFACE/ s/[ :]\+/\|/gp" /proc/net/dev \
| cut -d "|" -f 4)
Bytes Transmitted: $(sed -n -e "/$IFACE/ s/[ :]\+/\|/gp" /proc/net/dev \
| cut -d "|" -f 12)
</PRE></div>
</td>
</tr>
/BYTECOUNTCONTENT
t_foot
Not perfect, but it should give you a sense for the possibilities.
If you wanted to get really fancy, you could run netsnmpd[2] on
your firewall and use MRTG[3] or one of the RRDtool frontends[4]
(I like cacti[5]) on an internal host to collect and graph all
sorts of traffic statistics.
--Brad
[1] http://linux.oreillynet.com/pub/a/linux/2000/11/16/LinuxAdmin.html .
[2] http://leaf.sourceforge.net/devel/helices/net-snmp/
[3] http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
[4] http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/rrdworld/
[5] http://www.raxnet.net/products/cacti/
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
------------------------------------------------------------------------
leaf-user mailing list: [EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-user
SR FAQ: http://leaf-project.org/pub/doc/docmanager/docid_1891.html