Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Vnstat how-to

    Scheduled Pinned Locked Moved Traffic Monitoring
    29 Posts 13 Posters 13.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bwdutton
      last edited by

      Here are the directions I used to manually install vnstat:

      ssh into router, cd to /root, download these:
      fetch http://pkg.freebsd.org/freebsd:10:x86:64/latest/All/vnstat-1.14.txz
      fetch http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz

      this will ask to install dependencies, say yes

      pkg install vnstat-1.14.txz

      this copies your existing vnstat data to a new home and leaves the existing files untouched

      mkdir -p /var/lib
      cp -rp /cf/conf/vnstat /var/lib
      chown -R vnstat:vnstat /var/lib/vnstat

      install the frontend

      cd /usr/local/www
      tar xvf /root/vnstat_php_frontend-1.5.1.tar.gz
      mv vnstat_php_frontend-1.5.1 vnstat

      configure front end, I use vi, use ed or whatever you prefer

      vi vnstat/config.php
      change $language to en: $language = 'en';
      change $iface list to your interfaces, e.g.:
      $iface_list = array('em0', 'em1', 'em2');
      add/edit the title lines for your interfaces, e.g.:
          $iface_title['em0'] = 'LAN';
          $iface_title['em1'] = 'WAN';
          $iface_title['em2'] = 'JUMBOLAN';
      change $vnstat_bin = '/usr/local/bin/vnstat';

      fix image output:

      vi vnstat/graph_svg.php
      edit line 156:
      svg_text($iw / 2, ($ytm / 2), $text, array( 'stroke' => $cl['text'], 'fill' => $cl['text']['rgb'],'
      stroke-width' => 0, 'font-family' => SVG_FONT, 'font-weight' => 'bold', 'text-anchor' => 'middle' ));
      to:
      svg_text($iw / 2, ($ytm / 2), $text, array( 'stroke' => 'none', 'fill' => $cl['text']['rgb'],'
      stroke-width' => 0, 'font-family' => SVG_FONT, 'font-weight' => 'bold', 'text-anchor' => 'middle' ));

      run this once to make sure there are no errors

      /usr/local/bin/vnstat -u

      add the crontab entry to update the stats

      crontab -e
      */5 * * * * /usr/local/bin/vnstat -u

      And that should be it. Go to http://yourrouter/vnstat/ to view the results.

      1 Reply Last reply Reply Quote 0
      • C
        cmb
        last edited by

        vnstat is available for manual 'pkg install' now. That's a first step towards getting the full package back.

        Just SSH in, and run:

        pkg update 
        pkg install vnstat
        
        

        To install it.

        1 Reply Last reply Reply Quote 0
        • R
          Retrograde
          last edited by

          @cmb:

          vnstat is available for manual 'pkg install' now. That's a first step towards getting the full package back.

          Just SSH in, and run:

          pkg update 
          pkg install vnstat
          
          

          To install it.

          Followed instructions, rebooted PFsense, see no package installed and no VNstat under status, any more instructions available/needed?

          1 Reply Last reply Reply Quote 0
          • jdillardJ
            jdillard
            last edited by

            That just installs the FreeBSD package. It won't show up in the GUI, it's all CLI: http://humdi.net/vnstat/man/vnstat.html

            1 Reply Last reply Reply Quote 0
            • R
              Retrograde
              last edited by

              Profound sadness, thanks for the update though!

              1 Reply Last reply Reply Quote 0
              • jdillardJ
                jdillard
                last edited by

                I am working on a front-end for it. You can scroll through my post history if you want more info/screencasts.

                1 Reply Last reply Reply Quote 0
                • V
                  vizi0n
                  last edited by

                  My vnstatd is working perfectly on my 2.3.1 box. I have also added a rc.d script for startup/shutdown to try to prevent corrupt data files.

                  Location: /usr/local/etc/rc.d/vnstatd.sh

                  
                  #!/bin/sh
                  
                  . /etc/rc.subr
                  
                  name="vnstatd"
                  rcvar=vnstatd_enable
                  
                  load_rc_config $name
                  
                  : ${vnstatd_conf="/usr/local/etc/vnstat.conf"}
                  : ${vnstatd_flags="-d --config ${vnstatd_conf}"}
                  
                  required_files=${vnstatd_conf}
                  command="/usr/local/sbin/vnstatd"
                  
                  run_rc_command "$1"
                  
                  

                  Added this to my /etc/rc.conf.local

                  vnstatd_enable="YES"
                  

                  Now vnstatd starts at boot time and stops at shutdown.

                  I also added a backup script (that definately need tuning in order to only keep maybe a few days of backup in case something goes unnoticed). It was added to the crontab to run every hour

                  0 * * * * /root/vnstat_backup.sh >/dev/null 2>&1
                  

                  Here is the /root/vnstat_backup.sh. I'm not sure if I had to install bash, but I think I did :

                  #!/usr/local/bin/bash
                  
                  #START
                  TIME=`date +%Y-%m-%d_%H%M`		# This Command will add date in Backup File Name.
                  FILENAME=$TIME.tar.gz			# Here i define Backup file name format.
                  SRCDIR=/var/db/vnstat			# Location of Important Data Directory (Source of backup).
                  DESDIR=/root/vnstat_backup		# Destination of backup file.
                  #echo $TIME
                  tar -cpzf $DESDIR/$FILENAME $SRCDIR
                  #END
                  

                  This script creates a ton of files that need to be cleaned manually once in a while, so if someone could tune it to delete files older than X days it would be great! :)

                  1 Reply Last reply Reply Quote 1
                  • R
                    Retrograde
                    last edited by

                    Just curious if there's any update, Comcast is rolling out more data caps and Fios is still working on outfitting our building.

                    1 Reply Last reply Reply Quote 0
                    • johnpozJ
                      johnpoz LAYER 8 Global Moderator
                      last edited by

                      I just got an email from comcast about caps - its 1TB.. are you actually using more than 1TB a month?

                      An intelligent man is sometimes forced to be drunk to spend time with his fools
                      If you get confused: Listen to the Music Play
                      Please don't Chat/PM me for help, unless mod related
                      SG-4860 24.11 | Lab VMs 2.8, 24.11

                      1 Reply Last reply Reply Quote 0
                      • MikeV7896M
                        MikeV7896
                        last edited by

                        The Traffic Monitor package is in testing for pfSense 2.3.2 development builds now… just became available a day or two ago. A few minor bugs to be worked out and things that need to be tweaked so far, but it's there and it's working...

                        The S in IOT stands for Security

                        1 Reply Last reply Reply Quote 0
                        • johnpozJ
                          johnpoz LAYER 8 Global Moderator
                          last edited by

                          This traffic monitor package is based on what?  Vnstat, Bandwidthd, something all new?  Curious - maybe I will jump to the 2.3.2 just to check it out..

                          An intelligent man is sometimes forced to be drunk to spend time with his fools
                          If you get confused: Listen to the Music Play
                          Please don't Chat/PM me for help, unless mod related
                          SG-4860 24.11 | Lab VMs 2.8, 24.11

                          1 Reply Last reply Reply Quote 0
                          • MikeV7896M
                            MikeV7896
                            last edited by

                            @johnpoz:

                            This traffic monitor package is based on what?  Vnstat, Bandwidthd, something all new?  Curious - maybe I will jump to the 2.3.2 just to check it out..

                            It's based on vnstat, just using the same graphing engine as the monitoring graphs to visualize the data, getting it from vnstat's JSON output.

                            The S in IOT stands for Security

                            1 Reply Last reply Reply Quote 0
                            • R
                              Retrograde
                              last edited by

                              Just wondering if this is planned to be implemented into an upcoming version soon, the Comcast data caps just rolled out to a bunch of new states and like hell I trust their meter over my own: https://www.reddit.com/r/cordcutters/comments/5az24d/comcast_rolls_out_new_data_caps_in_28_states/

                              1 Reply Last reply Reply Quote 0
                              • MikeV7896M
                                MikeV7896
                                last edited by

                                The Traffic Totals package is available in 2.3.x. Go to System > Package Manager > Status_Traffic_Totals. Install that package and you'll have a new item added to your Status menu for Traffic Totals. You'll need to enable it under the Advanced settings and after 5 minutes, it'll start showing data.

                                The S in IOT stands for Security

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post
                                Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.