Coder Social home page Coder Social logo

vnstat's Introduction

vnStat

vnStat is a console-based network traffic monitor that 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 regardless of network traffic rate.

By default, traffic statistics are stored on a five minute level for the last 48 hours, on a hourly level for the last 4 days, on a daily level for the last 2 full months and on a yearly level forever. The data retention durations are fully user configurable. Total seen traffic and a top days listing is also provided. Optional image output is available in systems with the GD library installed.

See the official webpage for additional details and output examples.

Getting started

vnStat works best when installed. It's possible to either use the latest stable release, get the current development version from git or use a Docker container containing the pre-compiled latest stable release.

Stable version

  1. wget https://humdi.net/vnstat/vnstat-latest.tar.gz
  2. optional steps for verifying the file signature
    1. wget https://humdi.net/vnstat/vnstat-latest.tar.gz.asc
    2. gpg --keyserver pgp.mit.edu --recv-key 0xDAFE84E63D140114
    3. gpg --verify vnstat-latest.tar.gz.asc vnstat-latest.tar.gz
    4. the signature is correct if the output shows "Good signature from Teemu Toivola"
  3. tar zxvf vnstat-latest.tar.gz
  4. cd vnstat-*

Development version

  1. git clone https://github.com/vergoh/vnstat
  2. cd vnstat

In both above cases, continue with instructions from the INSTALL or INSTALL_BSD file depending on used operating system. Instructions for upgrading from a previous version are included in the UPGRADE file. Release notes can be found from the CHANGES file.

Docker container

docker run -d \
    --restart=unless-stopped \
    --network=host \
    -e HTTP_PORT=8685 \
    -v /etc/localtime:/etc/localtime:ro \
    -v /etc/timezone:/etc/timezone:ro \
    --name vnstat \
    vergoh/vnstat

For more details regarding container usage, available environment variables and a docker-compose.yml example, see the vergoh/vnstat-docker git repository or Docker Hub.

Contacting the author

Bug reports, improvement ideas, feature requests and pull requests should be sent using the matching features on GitHub as those are harder to miss or forget.

vnstat's People

Contributors

anileo avatar cameronnemo avatar cgzones avatar debfx avatar hub2git avatar ith8 avatar jasperla avatar lasers avatar leeps avatar lilydjwg avatar namtsui avatar papierkorb avatar rrebello avatar sbraz avatar sevu avatar sjonhortensius avatar vergoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vnstat's Issues

Text Width Miscalculation

Vnstat has made my day. I configured it just right, started the daemon, and waited patiently for data to amass in each interface's database.

I then noticed graph columns did not align correctly:

Text Width Miscalculation

I've encountered this problem in my own programs. As programmers, we cannot assume that characters of localized strings only occupy a single column. The fix is straightforward and begins with the man page for wcswidth().

Thank you for maintaining such an awesome utility.

How do I get vnstatd to monitor all interfaces?

Hi,

according to the docs, vnstatd will only create database files for interfaces when there aren't any files yet. How do get it to automatically create database files for interfaces that are added later on? Is there an option for that?

Count 8GB on PPP in 1 second

Hi,
I got this problem 4 times on this month during connecting via 3G USB (only occur on 3G USB). The counter increase 8Gb suddenly with Download 4GB and Upload 4GB.
I don't know why and facing it few time in this month. How can I find the cause of this problem?

Ubuntu 15.10 Error

Just fresh installed and -> Failed to restart vnstat.service: Unit vnstat.service is masked.

ps aux|grep vnstat
--nothing there ...

Will upgrading vnstat result in any loss of logs/database/stats?

My router with LEDE (version 17.01.2) has vnstat version 1.12. I could upgrade it to vnstat version 1.17 by following instructions on https://forum.lede-project.org/t/why-vnstat-is-at-version-1-12-1-only/1179/21

My Linux Mint 18.2 Xfce has vnstat version 1.14. I could follow the instructions on https://askubuntu.com/questions/938293/update-vnstat-to-1-17 to upgrade to vnstat 1.17.

Here's my question. If I upgrade the vnstat on my Linux Mint computer or my router, will I lose some vnstat data/logs/stats that are being saved?

Another question: Before I can upgrade to vnstat 1.17, wouldn't I first have to remove my current vnstat? If so, am I right to think that uninstalling would remove all the vnstat logs/stats/database?

bug for: vnstat -d -s

When I run

vnstat -d -s

it returns

                      rx      /      tx      /     total    /   estimated
 eth0:
       Dec '15     19.47 MiB  /  543.02 MiB  /  562.49 MiB  /   11.01 GiB
         today     19.47 MiB  /  543.02 MiB  /  562.49 MiB  /    1.01 GiB

as you can see, it adds an extra 10 to the days estimate.

When the JSON output to top hour one unnecessary comma is inserted.

And insert the JSON output in one unnecessary commas, therefore in jq command cannot parse error occurs.

This is in recognition that the bug right?

# vnstat --json
{"vnstatversion":"1.13","jsonversion":"1","interfaces":[{"id":"eth0","nick":"eth0","created":{"date":{"year":2015,"month":4,"day":6}},"updated":{"date":{"year":2015,"month":4,"day":6},"time":{"hour":16,"minutes":2}},"traffic":{"total":{"rx":33464,"tx":920},"days":[{"id":0,"date":{"year":2015,"month":4,"day":6},"rx":33464,"tx":920}],"months":[{"id":0,"date":{"year":2015,"month":4},"rx":33464,"tx":920}],"tops":[],"hours":[,{"id":15,"date":{"year":2015,"month":4,"day":6},"rx":33367,"tx":894},{"id":16,"date":{"year":2015,"month":4,"day":6},"rx":97,"tx":26}]}}]}
[root@localhost ~]# vnstat --json | jq .
parse error: Expected value before ',' at line 1, column 425

Install docs are now incorrect

Install docs are now incorrect since you changed to autotools because the binaries are no longer in src/ but in the root of the working directory.

Error parsing json output

We get an error when parsing vnstat -i br0 -h --json using python -m json.tool.
Indeed, the output contains some wrongly formatted json on traffic.hours array which contains a leading , (..."hours":[,{"id":15,"...)

{"vnstatversion":"1.13","jsonversion":"1","interfaces":[{"id":"br0","nick":"br0","created":{"date":{"year":2015,"month":2,"day":8}},"updated":{"date":{"year":2015,"month":2,"day":8},"time":{"hour":15,"minutes":21}},"traffic":{"total":{"rx":974,"tx":128},"days":[{"id":0,"date":{"year":2015,"month":2,"day":8},"rx":974,"tx":128}],"months":[{"id":0,"date":{"year":2015,"month":2},"rx":974,"tx":128}],"tops":[],"hours":[,{"id":15,"date":{"year":2015,"month":2,"day":8},"rx":974,"tx":128}]}}]}

API

Hey
Is there any API of sorts which is possible to use to integrate in a different application. Or some way to access its output stats?

Thanks.

Question xml output hour

Im using the command --exportdb --xml, my xml is then converted to json.

The first id in traffic.days.day and traffic.months.month always seem to be current month/day. However if i do the same to traffic.months.month the usage reported will be in the id of the current hours. (So say i download a huge file at 1700 o'clock the reported use will be in id 16)

Output https://gist.github.com/Hellowlol/7808a07c190a911cc208

Is this intended?

Custom dates

In addition with the default monthly monitoring, I would like to monitor a custom date range matching the billing period. How can it be done?

If not, please let me know how to configure monitoring the billing period.

Question: set first day of the month

Is there any way to change the "first day of the month" for vnstat? Example:

$ vnstat -m

 external (enp4s0)  /  monthly

       month        rx      |     tx      |    total    |   avg. rate
    ------------------------+-------------+-------------+---------------
      May '16     45.71 GiB |    1.86 GiB |   47.57 GiB |  148.99 kbit/s
      Jun '16    261.80 GiB |    4.57 GiB |  266.36 GiB |    1.26 Mbit/s
    ------------------------+-------------+-------------+---------------
    estimated    381.14 GiB |    6.64 GiB |  387.79 GiB |

As you can see, vnstat is treating the first day I started the daemon as the first day of the month. I need it to be the actual first day, e.g. for June it should start at June 1.

My /etc/vnstat.conf has MonthRotate 1 set, but that doesn't seem to have any effect.

$ vnstat -v
vnStat 1.15 by Teemu Toivola <tst at iki dot fi>

JSON output for -tr ( calculate traffic )

Using JSON as output makes vnstat one of the best network monitoring tools.
However I've noticed that --json parameter is not working in some cases like:

  1. live traffic monitoring ( vnstat -l --json )
  2. Calculate traffic ( vnstat -tr --json )

Maybe there is some workaround to achieve JSON output in such situations, if not It might turnout to be very handy to add such support.

Per process stats

I was wondering if there is any chance that support for per-process stats would be added, because it would be quite useful to have.

Edit database

I've been doing some weird stuff and it's messed with my vnstat output. I realized this when I had already uploaded three gigabytes abnormally. Can I edit the database to return the value for a specific hour to a sensible size? I don't know what format databases are in, or how to open them.

Change default for MaxBandwidth to 1000

Since Gigabit links are common, what about changing the default MaxBandwidth setting from 100 to 1000? As far as I can see, this limit exists to detect abnormally high deviations and there shouldn't be any other negative effects from doing so?

question: how to reset to zero again?

I just installed vnstat and enable the service. I wan't to reset it to zero like I never used it.

vnstat -r >> doesn't reset.

vnstat --delete ; vnstat --create -i mydevice ; reboot >> doesn't reset either.
After --create. the profile that was created was the profile that was deleted before.

rm /var/lib/vnstat/mydevice ; vnstat --create -i mydevice ; reboot also doesn't reset.
same thing happened after --create.
just like this guy: http://www.linuxquestions.org/questions/linux-networking-3/vnstat-doesn%27t-reset-494165/

What could be the problem? Am I doing it wrong?
Thank you :'D

Duplicated Entries

I noticed that vnstat has duplicated entries for some days and months. Look at the pictures I attached.
I run Ubuntu 14.04 with the 3.13.0-61 kernel. The vnstat version is 1.14.

screenshot1
screenshot2

PollInterval Range Incorrect

... either that, or the documentation is incorrect.

I am just getting into vnstat and think I am going to love it. In setting up the initial configuration, I noticed that PollInterval was capped at 60 instead of 300 as listed in the documentation.

Thank you!

keep logs for more than a year

Excuse me if this is possible but it's not obvious in any manual pages or docs that I've come across. Would it be possible to be able to log and report on periods longer than 12 months, like say over a 10 year period?

Use human readable unit when show in hours?

Hi @vergoh,

Thanks for this useful tool, I was wondering if -h can show data as -d, -m to use a human readable unit? Currently, it shows the data in KiB, hope it can auto transfer to use MiB and GiB.

Thanks!

grsecurity: no data - no errors

When using a grsecurity enhanced kernel and running vnstatd with the user vnstat, no data is collected.
Due to proc restrictions by grsec, the vnstat user must be a member of the grsec-proc group.

When this is not the case, vnstatd collects no data and produces no error or warning log messages.
Please add one for this case.

Maybe at

if ((fp=fopen(PROCNETDEV, "r"))!=NULL) {
and
if (readproc(inface)!=1) {
?

output in mb

i have a question.
i use a shell script to get the output from one month from different servers.
one server has more b/w usage then the other.
one server gives me 700 mb usage per month
another server gives me 4 gb usage per month.

in my output i get 700 from one server and 4 from the other.
is it possible to get the output in mb ? so i get 700 from one server and 4096 from the other server ?

here is a part of the line i use.
vnstat -m | grep "date +"%b '%y"" | awk '{print $3}' > monitor/download.txt

maybe you have another solution that i can get the output in bytes so i can calculate in the script to get back to mb or gb.

statistics is not correct

hello,i use vnstat to monitor my server , but something that confuse me .

and this happen in 2017.06.24 12:00 am , ,so much traffic appear in an hour , but traffic appear normal on my server provider.

qq 20170625123003

server infomation :
centos 6.8

--json and -tr

Greetings,

I have a feature request -
It would be very helpful to my platform and usage needs if it were possible to get the -tr argument output in JSON format.

Thank you for work on this great product.

buffer overflow in readproc

In the function readproc there is a buffer overflow:
char temp[4][64], procline[512], *proclineptr, ifaceid[33];
[...]
while (fgets(procline, 512, fp)!=NULL) {
sscanf(procline, "%511s", temp[0]);

The variable temp is only 4*64 (=256) bytes, yet the code tries to fill it with 512 byte and thus overflows. (To see the overflow at runtime you can compile vnstat with address sanitizer: 'make CFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address"' and then run 'src/vnstat -tr')

I think a patch like this should fix it (but not 100% sure, cause I don't know what exactly the code is meant to do):

--- ./vnstat-1.14/src/ifinfo.c  2015-03-29 20:56:55.000000000 +0200
+++ ./vnstat-1.14-1/src/ifinfo.c    2015-12-07 18:35:50.981122234 +0100
@@ -182,8 +182,8 @@
    strcat(ifaceid, ":");

    check = 0;
-   while (fgets(procline, 512, fp)!=NULL) {
-       sscanf(procline, "%511s", temp[0]);
+   while (fgets(procline, 256, fp)!=NULL) {
+       sscanf(procline, "%255s", temp[0]);
        if (strncmp(ifaceid, temp[0], strlen(ifaceid))==0) {
            /* if (debug)
                printf("\n%s\n", procline); */

Over 10 GiB/h causes overflow in hourly output in some locales

I couldn't find a mention of this in the changelog; and the config-file didn't seem to have an option for this either. This change makes the output pretty useless as it's just a bunch of numbers now (which are also being truncated). Can I change this; or is this a bug?

wrong prefix (SI / binary)

When vnstat shows me stats it gives wrong information about the avg. rate.

Example:

         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      01/17/16      1.77 GiB |    1.09 GiB |    2.86 GiB |  277.92 kbit/s

That is wrong information because 2.86 GiB (Gebibyte) per day equals 284.34 kbit/s.

Either your calculation is wrong or you're just using the wrong prefix. I suspect the latter, because 277.92 kibibyte/s would be right.

I attached a screenshot of my calculations, just to show what I did.
bildschirmfoto_2016-04-11_14-20-41

Invalid database timestamp.

I updated from 1.12 to 1.16 and I got this error.
Error: wlan0: Invalid database timestamp.
Error: validation of imported database failed.

How do I fix this? I can't even import my backup databases.

Remote control / access

Would be nice to have remote controll of vnstat so you can collect data from diffrent hosts!

Such as in FreeNAS jails or other simular setups.

Sorry bad english!

vnStat JSON

I am using the --json parameter to output results for my website's dashboard. Using a script that converts the output into a readable format, it returns MB, rather than GB. The readable numbers are the exact same.

My question is, is the rx and tx numbers bytes?

is it 1.12 now?

If so, could you offer a tag in github for new releases from now on?

I also would like to see tarball available on your homepage.

Thanks.

Traffic from apt-mirror not counted

I noticed traffic from apt-mirror is not (reliably) counted by vnstat, but the traffic shows up in my Zabbix monitoring. apt-mirror downloaded a good 120GB at a speed of roughly 700Mbit/s today, yet only 18GB were registered by vnstat (which includes other traffic by other applications). I haven't noticed any other applications not being counted on my system. I have no idea how this is even possible, vnstat usually even counts routed traffic on the network interface. Any suggestions?

ifinfo.c:131: possible problem with call to strncpy ?

[ifinfo.c:131]: (error) Dangerous usage of 'ifaceid' (strncpy doesn't always null-terminate it).

Source code is

strncpy(ifaceid, iface, 32);
strcat(ifaceid, ":");

Suggest new code

strncpy(ifaceid, iface, 32);
ifaceid[32] = '\0';
strcat(ifaceid, ":");

FreeBSD 10.1: unknown type u_{int,short,char} errors in misc.c

I see errors like this

In file included from common.h:18:0,
                 from misc.c:2:
/usr/include/sys/file.h:209:2: error: unknown type name 'u_int'
  u_int xf_flag; /* flags (see fcntl.h) */

in gmake all, even with the CPATH and LIBRARY_PATH variables set. I'm not a C programmer, so what other information do you need?

missing February in -s short printout

vnstat -s

                  rx      /      tx      /     total    /   estimated

wan0:
Jan '16 4.00 GiB / 3.40 GiB / 7.40 GiB
Mar '16 0.99 GiB / 1.05 GiB / 2.04 GiB / 2.26 GiB
yesterday 18.52 MiB / 23.78 MiB / 42.30 MiB
today 2.90 MiB / 2.39 MiB / 5.29 MiB / 32 MiB

however in standard printout:

vnstat
Database updated: Tue Mar 1 02:55:01 2016

wan0 since 08/03/15

      rx:  16.17 GiB      tx:  11.53 GiB      total:  27.70 GiB

monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Jan '16 4.00 GiB | 3.40 GiB | 7.40 GiB | 23.18 kbit/s
Feb '16 0.99 GiB | 1.05 GiB | 2.04 GiB | 7.57 kbit/s
------------------------+-------------+-------------+---------------
estimated 1.10 GiB | 1.16 GiB | 2.26 GiB |

daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
yesterday 18.52 MiB | 23.78 MiB | 42.30 MiB | 4.01 kbit/s
today 2.90 MiB | 2.39 MiB | 5.29 MiB | 4.13 kbit/s
------------------------+-------------+-------------+---------------
estimated 16 MiB | 16 MiB | 32 MiB |

looks like February in -s short printout is missing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.