Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


CentOS/Debian - Total Monthly Traffic tool?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

CentOS/Debian - Total Monthly Traffic tool?

geodirkgeodirk Member

I have a bunch of CentOS 5/6 boxes plus a couple of Debian servers. I'm looking for some sort of tool that runs in the background that will give me total traffic that is passed through the network adapter each month. Nothing fancy needed like graphs or anything like that...just the raw MB/GB numbers. I realize that I could get these same numbers from the OpenVZ control panels that are hosting my VMs, but that requires a whole lot more work than just SSH'ing into my VM and dumping the number from the console.

Anyone know of such a tool? Thanks!

Comments

  • NickkNickk Member

    vnstat should do the trick.

    Thanked by 1geodirk
  • ClouviderClouvider Member, Patron Provider

    Cacti for example.
    Or observium.
    Or any other server monitoring tool. ;)

  • Here's a simple bash script since you have a lot of boxes. This will read the SSH credentials per box and output the bandwidth usage according to "ifconfig eth0". You may use any other command there of course to execute a specific command for other purposes - modify the "file" variable to the file where you keep the credentials:

    #!/bin/bash
    file="/root/boxes"
    #File syntax should be: SSH_PORT HOSTNAME_OR_IP USERNAME PASSWORD
    while read p; do
    creds=($p)
    echo ${creds[1]}
    sshpass -p ${creds[3]} ssh -p ${creds[0]} ${creds[2]}@${creds[1]} 'ifconfig eth0 | grep "RX by"'
    echo ''
    done < $file
    

    P.S You must have "sshpass". To install it, execute "yum install sshpass" on CentOS; there should also be an entry for that host inside ~/.ssh/known_hosts for this to work. If there isn't, connect the first time normally through "ssh" and then press "y" when prompted to add the host to the known hosts.

    Example boxes file:

    22 127.0.0.1 root password
    
    Thanked by 2geodirk 4n0nx
  • vnstat is quick and easy to use and install for openvz and kvm.

    vnstat -d for daily usage
    vnstat -m for monthly usage

    Thanked by 1geodirk
  • I'm giving vnstat a go... However, with vnstat, how do you do create a database on the venet0:0 adapter? I get this error on that adapter but it seems to work on the tun0 adapter:

    # vnstat -u -i venet0:0
    Error:
    Unable to read database "/var/lib/vnstat/venet0:0".
    Error:
    Unable to get interface statistics.
    
    # vnstat -u -i tun0
    Error:
    Unable to read database "/var/lib/vnstat/tun0".
    -> A new database has been created.
    

    Thanks for the help.

  • ClouviderClouvider Member, Patron Provider

    Venet0:0 is not an interface. It's an alias.

    Venet0 is the interface.

    Thanked by 1geodirk
  • @Clouvider said:
    Venet0:0 is not an interface. It's an alias.

    Venet0 is the interface.

    Sure enough, if I target that, it works. Thanks!

  • ClouviderClouvider Member, Patron Provider

    You're most welcome ;).

    Have a lovely weekend. Don't work too much! :)

  • @Verelox said:
    Here's a simple bash script since you have a lot of boxes.

    Nifty script. I'll have to implement something like this later on. I had no idea that running the ifconfig command with a specific adapter dumped out all that extra info. Thanks!

Sign In or Register to comment.