Ad Widget

Collapse

Suggestions on how to extract value from bandwidthd

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hyarion
    Junior Member
    • Mar 2007
    • 22

    #1

    Suggestions on how to extract value from bandwidthd

    I want to monitor the total traffic usage from a linux server that is running bandwidthd monitoring but I can't think of an easy way to do it.

    The bandwidthd program saves an html page every couple of minutes which contains the total traffic value that I'm looking for.

    Using cut and similar commands I can get it down to the number, but it's not the bytes number.

    e.g. it could be 80K / 80M / 80G / etc.

    Extracting the number on it's own then is obviously not useful as getting "80" could mean anything from 80 bytes to 80 terabytes.

    Does anyone have a suggestion on how I can extract the size in bytes in order to use it in zabbix?

    I've thought of perhaps making a script to take the K/M/G/etc and multiply the number appropriately.

    Suggestions?
    Last edited by hyarion; 01-11-2010, 15:57. Reason: edited for clarity
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    Wow, the developers really haven't done this in a very Unix like manner.

    Reading through the docs I find the following:

    Bandwidthd can be made to log to CDF by setting "output_cdf" to true. This will
    now log out each interval's traffic, so you can import them into a database and
    use a tool like access to create your own graphs, or implement 95 percentile
    billing, for example. Sending Bandwidthd a HUP will cause it to rotate it's logs.
    It will rotate out 5 times before deleting the oldest log file.

    These logs are log.1.0.cdf-log.1.5.cdf for daily, log.2.0.cdf-log.2.5.cdf for
    weekly, etc, etc.

    ...

    The log format is best documented in the "StoreIPDataInCDF" function in
    bandwidthd.c. As of this writing, it consists of one line for each IP address
    for each interval. The line contains only data for the previous interval.

    Fields:
    IP Address,Timestamp,Total Sent,Icmp Sent,Udp Sent,Tcp Sent,Ftp Sent,Http Sent, P2P Sent,Total Received,Icmp Received,Udp Received,Tcp Received,Ftp Received,Http Received, P2P Received
    So it looks like you'll have to do some serious script hacking, perhaps with expect involved (ouch).
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • hyarion
      Junior Member
      • Mar 2007
      • 22

      #3
      Ok, I managed to do it, it's not pretty but it works.

      First I created a bash script - First time making a bash script, so please don't judge

      Code:
      #!/bin/bash
      
      var=`cat /home/httpd/html/bandwidth/index.html|grep "#Total-1"|cut -d">" -f8|cut -d"<" -f1`
      
      vlen=${#var}
      
      slen=$vlen-1
      
      size=${var:0:slen}
      
      octal=${var:slen}
      
      #B = bytes
      #K = kilobytes
      #M = megabytes
      #G = gigabytes
      
      if [ "$octal" = "K" ]; then
      #	echo "kb"
      	size=$(echo $size|awk '{printf("%f", $1*1024)}')
      fi
      
      if [ "$octal" = "M" ]; then
      #	echo "Mb"
      	size=$(echo $size|awk '{printf("%f", $1*1024*1024)}')
      fi
      
      if [ "$octal" = "G" ]; then
      #	echo "Gb"
      	size=$(echo $size|awk '{printf("%f", $1*1024*1024*1024)}') 
      fi
      
      echo $size
      exit 0
      I then saved it as bandwidthd.sh in the /etc/zabbix/ folder and gave it execute permissions.

      And added the following to my zabbix_agentd.conf

      Code:
      UserParameter=ipcop.bandwidthd, /etc/zabbix/bandwidthd.sh
      Last edited by hyarion; 15-11-2010, 10:29. Reason: spelling mistakes

      Comment

      Working...