个人工具

“UbuntuHelp:HowToMonitorInternetTrafficTotals”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(New page: {{From|https://help.ubuntu.com/community/HowToMonitorInternetTrafficTotals}} {{Languages|php5}} Parent page: Internet and Networking == ipac-ng == A...)
 
第17行: 第17行:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo aptitude install ipac-ng
 
sudo aptitude install ipac-ng
</nowiki></code>
+
</nowiki></pre>
  
 
=== Configuration ===
 
=== Configuration ===
第28行: 第28行:
 
total upload |ipac~i|eth0|all||
 
total upload |ipac~i|eth0|all||
 
total download |ipac~o|eth0|all||
 
total download |ipac~o|eth0|all||
</nowiki></code>
+
</nowiki></pre>
 
Note: replace eth0 with the network adapter you wish to measure.
 
Note: replace eth0 with the network adapter you wish to measure.
  
第36行: 第36行:
  
 
storage = gdbm
 
storage = gdbm
</nowiki></code>
+
</nowiki></pre>
  
 
To ignore LAN traffic, some simple iptables rules are added to the startup scripts.
 
To ignore LAN traffic, some simple iptables rules are added to the startup scripts.
第65行: 第65行:
 
echo "$NAME stopped."
 
echo "$NAME stopped."
 
;;
 
;;
</nowiki></code>
+
</nowiki></pre>
 
Note: replace aaa.bbb.ccc.0 with your local network. For example, if your router is at 192.168.0.1, you would use 192.168.0.0.
 
Note: replace aaa.bbb.ccc.0 with your local network. For example, if your router is at 192.168.0.1, you would use 192.168.0.0.
  
第82行: 第82行:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install vnstat
 
sudo apt-get install vnstat
</nowiki></code>
+
</nowiki></pre>
  
 
=== Setup ===
 
=== Setup ===
第89行: 第89行:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo chmod o+x /usr/bin/vnstat
 
sudo chmod o+x /usr/bin/vnstat
</nowiki></code>
+
</nowiki></pre>
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo chmod o+wx /var/lib/vnstat/
 
sudo chmod o+wx /var/lib/vnstat/
</nowiki></code>
+
</nowiki></pre>
  
 
Now vnstat should be ready to run
 
Now vnstat should be ready to run
第100行: 第100行:
 
<pre><nowiki>
 
<pre><nowiki>
 
vnstat -u -i ath0
 
vnstat -u -i ath0
</nowiki></code>
+
</nowiki></pre>
 
''Replace ath0 with the interface you want to monitor''
 
''Replace ath0 with the interface you want to monitor''
  
第119行: 第119行:
 
         -----------------------+------------+-----------
 
         -----------------------+------------+-----------
 
         estimated        0 MB |      0 MB |      0 MB
 
         estimated        0 MB |      0 MB |      0 MB
</nowiki></code>
+
</nowiki></pre>
  
 
You can read more about options you can use to modify the output in the man page of vnstat.
 
You can read more about options you can use to modify the output in the man page of vnstat.

2007年5月13日 (日) 12:31的版本

Parent page: Internet and Networking


ipac-ng

Aimed at people with a small home network, who want to monitor the amount uploaded / download from the internet but not the local traffic on the LAN. This might be useful if your ISP sets monthly bandwidth limits, and you also transfer files across your local network.

The instructions guide you through setting up IPAC-NG, an iptables/ipchains based IP accounting package.

Installation

You will need access to the Universe repository - see AddingRepositoriesHowto if you need more information.

First install ipac-ng, either with Synaptic (SynapticHowto)or type in a terminal:

sudo aptitude install ipac-ng

Configuration

Edit /etc/ipac-ng/rules.conf to tell it the type of traffic you want to log. To simply measure upload and download totals, it should read:

# /etc/ipac-ng/rules.conf

total upload |ipac~i|eth0|all||
total download |ipac~o|eth0|all||

Note: replace eth0 with the network adapter you wish to measure.

Edit /etc/ipac-ng/ipac.conf and change the storage method to gdbm, otherwise the logs will take up a very large amount of space. (postgre could probably be used too)

# /etc/ipac-ng/ipac.conf

storage = gdbm

To ignore LAN traffic, some simple iptables rules are added to the startup scripts.

Edit /etc/init.d/ipac-ng and add the four lines between the

case "$1" in
  start)
	echo -n "Starting $DESC: "
	check
	$DAEMON -S
	$IPTABLES -I INPUT -s aaa.bbb.ccc.0/24 -j ACCEPT
	$IPTABLES -I OUTPUT -d aaa.bbb.ccc.0/24 -j ACCEPT
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	# fetch accounting before removing the rules
	$DAEMON
	echo -n "flushing IP accounting rules ..."
	$IPTABLES --flush ipac~o
	$IPTABLES --flush ipac~i
	$IPTABLES --flush ipac~fi
	$IPTABLES --flush ipac~fo
	# here should the ipac_* rule be removed from INPUT OUTPUT and FORWARD but --flush is
	# evil because it would remove all rules in these chains.
	$IPTABLES -D INPUT -s aaa.bbb.ccc.0/24 -j ACCEPT
	$IPTABLES -D OUTPUT -d aaa.bbb.ccc.0/24 -j ACCEPT
	echo "$NAME stopped."
	;;

Note: replace aaa.bbb.ccc.0 with your local network. For example, if your router is at 192.168.0.1, you would use 192.168.0.0.


That's it! The traffic totals will be automatically fetched from iptables every 10 minutes when your computer is running. To view the totals, use 'ipacsum'. It can be configured to display a specific time interval, and will even draw graphs of the traffic.

Links

[1]

vnstat

vnstat is another app that can be used to monitor bandwidth usage. It is a little simpler and easier to use then the ipac-ng package. One of the benefits of vnstat is it's not a running daemon so it takes up no memory. The process is created via a cron job which is run every 5 minutes.

Install

The vnstat package is very easy to install from the repositories with no dependencies.

sudo apt-get install vnstat

Setup

vnstat is meant to be used by any user so it needs to be set up that way first by giving correct permission. The following gives any user permission to use this feature. If desired you can set up a group so only users in the group can use this.

sudo chmod o+x /usr/bin/vnstat
sudo chmod o+wx /var/lib/vnstat/

Now vnstat should be ready to run

Usage

To create the cron job simply run this command

vnstat -u -i ath0

Replace ath0 with the interface you want to monitor

This creates a file in /var/lib/vnstat/ that collects the data for that interface. A cron job will run every 5 minutes to update the data. Below is a sample output with no options.

Database updated: Thu Jan 12 22:20:01 2006

        ath0

           received:           0.11 MB (nan%)
        transmitted:           0.01 MB (nan%)
              total:           0.12 MB

                        rx     |     tx     |  total
        -----------------------+------------+-----------
            today      0.11 MB |    0.01 MB |    0.12 MB
        -----------------------+------------+-----------
        estimated         0 MB |       0 MB |       0 MB

You can read more about options you can use to modify the output in the man page of vnstat.



CategoryDocumentation CategoryNetworking