RTFM.WIKI

Ordnung muß sein. Ordnung über alles (18+)

Инструменты пользователя

Инструменты сайта


linux:vnstat

Установка Vnstat + webui

Quick howto для CentOS 6

# yum install vnstat -y

Редактируем файл /etc/sysconfig/vnstat

VNSTAT_OPTIONS="-u -i eth0"

В файле /etc/vnstat.conf указываем интерфейс по-умолчанию

# default interface
Interface "eth0"

Создаём базу данных для eth0 интфейса

# vnstat -u -i eth0

Error: Unable to read database "/var/lib/vnstat/eth0".
Info: -> A new database has been created.

Добавляем в автозагрузку

# chkconfig vnstat on

Запускаем

# /etc/init.d/vnstat start 
Starting vnstatd:                                          [  OK  ]

Как смотреть данные подскажет vnstat –help

# vnstat --help
 vnStat 1.15 by Teemu Toivola <tst at iki dot fi>

         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top 10 days
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth0)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

See also "--longhelp" for complete options list and "man vnstat".

Демон или cron. Информация из файла install

There are two way
 for updating interface data, daemon and cron. It is suggested to use daemon
 based updating because it generated less disk access and is more accurate
 especially when monitoring interfaces that aren't always available. Select
 ONLY ONE of these two:

 1) daemon based updating
 ::::::::::::::::::::::::

   Configure init scripts so that the following command is executed once
   during system start:

       vnstatd -d

   The examples/init.d directory contains suitable init.d scripts for
   some commonly used distributions. An alternative option is to just add
   the command to an already existing script that gets executed during
   startup. In many distributions /etc/rc.local can be used for that.

 2) cron based updating
 ::::::::::::::::::::::

   Copy the example cron file to /etc/cron.d

       cp examples/vnstat.cron /etc/cron.d/vnstat

   and edit the cron file if the default 5 minute update interval is too
   long. See the vnStat man page 'restrictions' section for limitations
   regarding fast interfaces and 32 bit interface traffic counters. Devices
   like ppp0 also require vnStat enable and disable commands to be added
   to suitable script file when cron based updating is used. Example scripts
   can be found in the 'examples' directory.

Красивый PHP frontend

Заметки для CentOS 7 и Debian

As easy as pie. Установка, запуск, автозагрузка, проверка статуса.

# yum install vnstat
# systemctl start vnstat
# systemctl enable vnstat
Created symlink from /etc/systemd/system/multi-user.target.wants/vnstat.service to /usr/lib/systemd/system/vnstat.service.
# systemctl status vnstat

В CentOS 7 и Debian данные перестают автоматически обновляться с ошибкой Error: Unable to create database backup "/var/lib/vnstat/.eth0" из-за проблем с правами доступа.

# ls -la /var/lib/vnstat/ 
total 16
drwxr-xr-x  2 vnstat vnstat 4096 Jul 13 09:09 .
drwxr-xr-x 33 root   root   4096 Jul 13 00:22 ..
-rw-r--r--  1 vnstat vnstat 2792 Jul 13 09:09 .eth0
-rw-r--r--  1 root   root   2792 Jul 13 09:04 eth0

Баги

Исправляем права

# chown -R vnstat:vnstat /var/lib/vnstat

Обсуждение

Ваш комментарий. Вики-синтаксис разрешён:
 
linux/vnstat.txt · Последнее изменение: 2017/08/21 23:47 — 127.0.0.1