Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:user-guide:services:vnstat [2018/02/18 16:56] – link to usb storage page updated after wiki merge tmomas | docs:guide-user:services:network_monitoring:vnstat [2021/04/08 01:02] (current) – unify code vgaetera | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== vnStat ====== | + | ====== |
| vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won't actually be sniffing any traffic and also ensures light use of system resources. [[http:// | vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won't actually be sniffing any traffic and also ensures light use of system resources. [[http:// | ||
| - | ===== Installing ===== | ||
| + | ===== Installing ===== | ||
| ==== Base ==== | ==== Base ==== | ||
| - | < | + | < |
| - | opkg install vnstat</ | + | opkg update |
| + | opkg install vnstat | ||
| + | </ | ||
| ==== LuCI Webgui Integration (optional) ==== | ==== LuCI Webgui Integration (optional) ==== | ||
| - | < | + | < |
| - | opkg install vnstati luci-app-vnstat</ | + | opkg update |
| + | opkg install vnstati luci-app-vnstat | ||
| + | </ | ||
| If you want language translation for the LuCI Webgui Integration then install the following: | If you want language translation for the LuCI Webgui Integration then install the following: | ||
| - | < | + | |
| - | opkg install luci-i18n-vnstat-(YOUR_COUNTRY_CODE)</ | + | < |
| + | opkg update | ||
| + | opkg install luci-i18n-vnstat-(YOUR_COUNTRY_CODE) | ||
| + | </ | ||
| If you dont know which language codes are available you can search it with the following command: | If you dont know which language codes are available you can search it with the following command: | ||
| - | < | + | < |
| + | opkg list | grep luci-i18n-vnstat-* | ||
| + | </ | ||
| An example to Install German Translation for LuCI Webgui: | An example to Install German Translation for LuCI Webgui: | ||
| - | < | + | |
| - | opkg install luci-i18n-vnstat-de</ | + | < |
| + | opkg update | ||
| + | opkg install luci-i18n-vnstat-de | ||
| + | </ | ||
| ===== Configuring ===== | ===== Configuring ===== | ||
| The only configuring it really needs is to tell it what interface(s) to monitor, and some method of updating the database such as a cronjob. You might want to backup your database file. The vnstati package comes with a ' | The only configuring it really needs is to tell it what interface(s) to monitor, and some method of updating the database such as a cronjob. You might want to backup your database file. The vnstati package comes with a ' | ||
| Line 32: | Line 44: | ||
| First, you have to find out which is your WAN Interface: | First, you have to find out which is your WAN Interface: | ||
| + | |||
| <code bash> | <code bash> | ||
| . / | . / | ||
| Line 38: | Line 51: | ||
| :!: The interface must be active for the above command to work. See ticket [[https:// | :!: The interface must be active for the above command to work. See ticket [[https:// | ||
| - | \\ | + | |
| - | \\ | + | |
| - | \\ | + | |
| If you have an already activated WAN connection, you will get the following output, for example: | If you have an already activated WAN connection, you will get the following output, for example: | ||
| - | < | ||
| - | \\ | ||
| - | Now edit __/ | ||
| - | < | + | Your WAN Interface is: pppoe-wan. |
| - | MaxBandwidth 1000</ | + | Now edit __/ |
| + | |||
| + | < | ||
| + | Interface " | ||
| + | MaxBandwidth 1000 | ||
| + | </ | ||
| " | " | ||
| Line 53: | Line 67: | ||
| :!: MaxBandwidth means: How fast is your WAN Interface at most. __MaxBandwidth 1000 = 1000 Mbit__ and __MaxBandwidth 100 = 100 Mbit__ ! It has nothing to do with your Internet speed ! | :!: MaxBandwidth means: How fast is your WAN Interface at most. __MaxBandwidth 1000 = 1000 Mbit__ and __MaxBandwidth 100 = 100 Mbit__ ! It has nothing to do with your Internet speed ! | ||
| - | \\ | + | |
| - | \\ | + | |
| - | \\ | + | |
| Then edit or create __/ | Then edit or create __/ | ||
| - | < | + | |
| - | list interface ' | + | < |
| + | config vnstat | ||
| + | list interface ' | ||
| + | </ | ||
| | | ||
| **Please Note:** " | **Please Note:** " | ||
| - | \\ | + | |
| - | \\ | + | |
| - | \\ | + | |
| Now you have to create the Database with this command: | Now you have to create the Database with this command: | ||
| - | < | + | < |
| + | vnstat -u -i pppoe-wan | ||
| + | </ | ||
| - | **Hint:** vnStat normally uses "IEC prefixes" | + | **Hint:** vnStat normally uses "IEC prefixes" |
| - | < | ||
| ==== Database Updating ==== | ==== Database Updating ==== | ||
| | {{: | | {{: | ||
| - | === Using included daemon: === | ||
| - | Edit __/ | + | === Using included daemon: === |
| - | < | + | Edit __/ |
| UpdateInterval tells the daemon to update the Database every 300 seconds (5 minutes). If you want another Interval you can change it for your needs. | UpdateInterval tells the daemon to update the Database every 300 seconds (5 minutes). If you want another Interval you can change it for your needs. | ||
| Run these commands to enable the daemon. This will also auto start the daemon if you reboot your device: | Run these commands to enable the daemon. This will also auto start the daemon if you reboot your device: | ||
| - | < | + | < |
| / | / | ||
| | {{: | | {{: | ||
| This same init.d script will automatically download a database backup if you configured ''/ | This same init.d script will automatically download a database backup if you configured ''/ | ||
| - | === Using a cronjob: === | + | |
| - | Add to crontab: | + | === Using a cronjob === |
| - | < | + | Update the crontab: |
| - | Restart cron with: | + | |
| - | < | + | < |
| + | cat << | ||
| + | */5 * * * * vnstat -u | ||
| + | EOF | ||
| + | / | ||
| + | </ | ||
| | {{: | | {{: | ||
| + | |||
| ==== Image Generation | ==== Image Generation | ||
| You can install webif and it will generate images. But thats not lightweight so RealOpty developed scripts based off webif code that will generate the images without webif. | You can install webif and it will generate images. But thats not lightweight so RealOpty developed scripts based off webif code that will generate the images without webif. | ||
| Line 100: | Line 119: | ||
| I always output the images to the tmpfs so it dont always write to flash. | I always output the images to the tmpfs so it dont always write to flash. | ||
| - | | <code bash> | + | <code bash> |
| #!/bin/sh | #!/bin/sh | ||
| # vnstati image generation script. | # vnstati image generation script. | ||
| Line 134: | Line 153: | ||
| exit 1 | exit 1 | ||
| - | </ | + | </ |
| ==== Sample HTML ==== | ==== Sample HTML ==== | ||
| - | | <code html> | + | <code html> |
| <META HTTP-EQUIV=" | <META HTTP-EQUIV=" | ||
| < | < | ||
| Line 170: | Line 189: | ||
| </ | </ | ||
| </ | </ | ||
| - | + | </ | |
| - | </ | + | |
| ==== Persistent stats ==== | ==== Persistent stats ==== | ||
| vnStat stores stats to / | vnStat stores stats to / | ||
| - | By default, vnStat is configured to write to the directory in volatile memory every 30 minutes. Both the directory and the interval can be adjusted in vnStat' | + | By default, vnStat is configured to write to the directory in volatile memory every 30 minutes. Both the directory and the interval can be adjusted in vnStat' |
| Additionally, | Additionally, | ||
| === Method 1 === | === Method 1 === | ||
| - | To store the database on the thumb drive, ensure that [[docs:user-guide: | + | To store the database on the thumb drive, ensure that [[docs: |
| === Method 2 === | === Method 2 === | ||
| This method automatically backs up the vnStat database to flash memory as **/ | This method automatically backs up the vnStat database to flash memory as **/ | ||
| + | |||
| == Script == | == Script == | ||
| - | The script goes into / | + | <code bash> |
| - | | <code bash> | + | cat << " |
| #!/bin/sh / | #!/bin/sh / | ||
| EXTRA_COMMANDS=" | EXTRA_COMMANDS=" | ||
| - | EXTRA_HELP=<< | + | EXTRA_HELP=<< |
| backup | backup | ||
| restore Restore vnstat database | restore Restore vnstat database | ||
| - | EOF | + | EOI |
| START=98 | START=98 | ||
| Line 241: | Line 260: | ||
| restore_database | restore_database | ||
| } | } | ||
| - | </ | + | EOF |
| - | + | chmod +x / | |
| - | Then do: | + | / |
| - | + | </ | |
| - | < | + | |
| - | / | + | |
| And for good measure, create an initial backup: | And for good measure, create an initial backup: | ||
| - | < | + | < |
| + | / | ||
| + | </ | ||
| == Add for cron and for init == | == Add for cron and for init == | ||
| The below commands will add a cronjob entry that triggers a backup every 6 hours every day, if necessary adjust to an interval you feel comfortable with: | The below commands will add a cronjob entry that triggers a backup every 6 hours every day, if necessary adjust to an interval you feel comfortable with: | ||
| - | < | + | |
| - | / | + | < |
| + | cat << | ||
| + | 0 */6 * * * / | ||
| + | EOF | ||
| + | / | ||
| + | </ | ||