Ad Widget

Collapse

MACRO containing a calculated value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frater
    Senior Member
    • Oct 2010
    • 340

    #1

    MACRO containing a calculated value

    I'm monitoring a DSL-router with a Zabbix agent (Freetz) and I've managed to extract the speed of the physical layer of the DSL-line (in bps). This DSL-router also has a network-interface (Ethernet) called 'adsl' where I'm able to fetch the throughput of the traffic going to the DSL-line (in B).
    These are the 2 items

    Code:
    net.if.in[adsl,bytes]
    dsl.downstream
    I now have the ingredients to see if a line is saturated or not.

    I already have this trigger, but I'm still not sure if zabbix is doing something with the units (bps and B). And when the trigger goes off it will show ugly calculations.

    This what I have now, which is
    Code:
    {Template_Freetz:net.if.in[adsl,bytes].avg(300)} > (0.9 * 100 * {Template_Freetz:dsl.downstream.last(0)})
    I also can't just say 8 bits on the physical layer is equal to 1 Byte on Ethernet. There's a significant overhead there. Especially when the Ethernet packages are decapsulated from the ATM-cels.
    A 1 Mbit/s will give you a maximum througput of 110 KBytes/s

    This is a PPPoA (PPP over ATM). A PPPoE (PPP over Ethernet) will probably give less overhead.


    I thought I was able to create a {$MACRO} like this and work with that:

    Code:
    {$SATURATION.RAW} = net.if.in[adsl,bytes] / dsl.downstream
    I thought I would be able to use {$SATURATION.RAW} in a trigger. Well, I can but it just expands to the text "net.if.in[adsl,bytes] / dsl.downstream" when in fact I want that value.

    Have I set my expectations too high as far as user-macros are concerned or is there something wrong with my syntax?

    I can of course create a new item on the agent and let the agent calculate the saturation. Maybe that's better in this case anyhow.

    I would still like an answer to my question or any other ideas of handling this.
    Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    You just gave me an idea for an addition to my Lua patch for Zabbix.
    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

    • frater
      Senior Member
      • Oct 2010
      • 340

      #3
      I solved that specific problem by creating a User-defined item which will calculate the saturation level itself.
      It will give a value from 0 to 100
      This way I will not have any problems showing a nice value in the interface.

      I only need an elegant way to find out if the modem is using ATM or not. If it isn't using ATM I can increase the value $NETTO as it has much less overhead. But I really don't need it myself.... (no PPPoE connections yet)

      On Zabbix:
      Code:
      Saturation Download in %
      Zabbix Agent
      saturation.rx
      Numeric (unsigned)
      Decimal
      %
      Code:
      Saturation Upload in %
      Zabbix Agent
      saturation.tx
      Numeric (unsigned)
      Decimal
      %
      Triggers
      Code:
      >$1% download on {HOSTNAME} ({ITEM.VALUE1}% of {ITEM.VALUE2} kbps)
      {Template_Freetz:saturation.rx.avg(300)} > 95 & {Template_Freetz:dsl.downstream.last(0)} > 100
      On Freetz:

      cat /tmp/flash/zbx_agentd_user_parameters | grep saturation
      Code:
      UserParameter=saturation.tx, adsl.saturation tx
      UserParameter=saturation.rx, adsl.saturation rx
      cat /mod/usr/sbin/adsl.saturation
      Code:
      #!/bin/sh
      
      # the parameter rx or tx has to be given
      echo "$1" | egrep -q '^(tx|rx)$' || exit 1
      
      STATDIR=/sys/devices/virtual/net/adsl/statistics
      STATFILE=$1_bytes
      [ -e ${STATDIR}/${STATFILE} ] || exit 1
      
      # Create a file in /tmp to fetch the previous sample
      SCRATCH=/tmp/${0##*/}.$1
      
      # Fetch the corresponding DSL-speed of physical layer
      # 'US Connection Rate' for tx and 'DS Connection Rate' for rx
      UPDOWN=US
      [ $1 = 'rx' ] && UPDOWN=DS
      DSL_SPEED=`grep -o "${UPDOWN} Connection Rate:.*" /proc/avalanche/avsar_modem_stats | awk '{print $4}' | tr -cd '0-9'`
      
      # Fetch date and Bytes from ADSLL-interface
      NOW_TIME=`date +%s.%N`
      NOW_BYTES=`cat ${STATDIR}/${STATFILE}`
      
      # On first run, these vars do not exist
      LAST_BYTES=${NOW_BYTES}
      LAST_TIME=0
      
      # read previous values
      [ -f ${SCRATCH} ] && . ${SCRATCH}
      
      # Sanity check in case previous value is somehow off
      [ ${NOW_BYTES} -lt ${LAST_BYTES} ] && LAST_BYTES=${NOW_BYTES}
      
      DIFF_BYTES=$(( ${NOW_BYTES} - ${LAST_BYTES} ))
      DIFF_TIME=`echo "${NOW_TIME} ${LAST_TIME}" | awk '{print $1 - $2}'`
      
      BITS_PER_SEC=`echo "${DIFF_BYTES} ${DIFF_TIME}" | awk '{printf"%.0f\n", 8 * $1 / $2}'`
      
      # Write Bytes and Time to ${SCRATCH}
      echo -e "LAST_BYTES=${NOW_BYTES}\nLAST_TIME=${NOW_TIME}" >${SCRATCH}
      
      # There's some overhead going from ATM over DSL to Ethernet
      NETTO=0.885
      
      # echo "${BITS_PER_SEC} ${DSL_SPEED} ${NETTO}"
      echo "${BITS_PER_SEC} ${DSL_SPEED} ${NETTO}" | awk '{printf"%.0f\n", $1 / ($2 * $3 * 10)}'
      Last edited by frater; 12-09-2011, 17:11.
      Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

      Comment

      • frater
        Senior Member
        • Oct 2010
        • 340

        #4
        The script is already in my post.... (the one before you posted)
        You only need a script for the saturation

        Here's my /tmp/flash/zbx_agentd_user_parameters
        Code:
        ####### USER-DEFINED MONITORED PARAMETERS #######
        # Format: UserParameter=<key>,<shell command>
        # Note that shell command must not return empty string or EOL only
        UserParameter=net.ping[*], sudo ping -c1 -W1 $1 2>/dev/null | grep -c 'bytes f'
        
        UserParameter=net.ipv4.cksum,ifconfig | grep -B1 ' inet ' | md5sum | tr -cd 0-9 | cut -b1-10
        UserParameter=net.ipv4,ifconfig | grep -B1 ' inet ' | grep -oE '(^[a-z0-9:]+|addr:[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'
        
        UserParameter=listenport[*], netstat -ln | grep -c ':$1 '
        UserParameter=net.netstat.cksum, netstat -lnt 2>/dev/null | sort | md5sum | tr -cd 0-9 | cut -b1-10
        UserParameter=net.netstat, netstat -lnt 2>/dev/null | sort
        
        UserParameter=net.tcpdump, sudo tcpdump -nc30 2>/dev/null | grep length | awk -F': ' '{print $1}'| grep -v '192\.168\..*192\.168\.'
        
        # Freetz DSL
        UserParameter=dsl.upstream, grep -o 'US Connection Rate:.*' /proc/avalanche/avsar_modem_stats | awk '{print $4}' | tr -cd '0-9'
        UserParameter=dsl.downstream, grep -o 'DS Connection Rate:.*' /proc/avalanche/avsar_modem_stats | awk '{print $4}' | tr -cd '0-9'
        UserParameter=dsl.upsnr, grep -o 'US Margin:.*' /proc/avalanche/avsar_modem_stats | awk '{print $3*10}'
        UserParameter=dsl.downsnr, grep -o 'DS Margin:.*' /proc/avalanche/avsar_modem_stats | awk '{print $3*10}'
        UserParameter=dsl.upcrc, grep -A1 '(TX) Interleave path' /proc/avalanche/avsar_modem_stats | grep CRC: | awk '{print $2}'
        UserParameter=dsl.downcrc, grep -A1 '(RX) Interleave path' /proc/avalanche/avsar_modem_stats | grep CRC: | awk '{print $2}'
        UserParameter=dsl.los, grep -o 'LOS errors:.*' /proc/avalanche/avsar_modem_stats | awk '{print $3}' | tr -cd '0-9'
        UserParameter=saturation.tx, adsl.saturation tx
        UserParameter=saturation.rx, adsl.saturation rx

        If you want to use sudo you need to read this thread:
        Hallo, habe mir heute (Nacht) mal etwas Zeit genommen und Zabbix Agentd 1.4 + GUI für Freetz vorbereitet. Ist mit einem Zabbix Server 1.8.4 getestet. Jetzt auch mit Zabbix Agent 1.8


        Read the whole thing, because the one explaining there assumed I had already a lot of knowledge about Freetz... which I didn't....

        I have added my current template for Freetz...
        It's work in progress...

        enable sudo, zabbix, dropbear, tcpdump and some other stuff....
        in busybox enable SUID (using /etc/busybox.conf) and nanoseconds for date
        also checkout my fwmod_custom which I posted there....
        Attached Files
        Last edited by frater; 23-09-2011, 19:29.
        Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

        Comment

        • nelsonab
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Sep 2006
          • 1233

          #5
          Looks like spammers are getting better at passing Turing tests...
          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

          • frater
            Senior Member
            • Oct 2010
            • 340

            #6
            Originally posted by nelsonab
            Looks like spammers are getting better at passing Turing tests...
            Yes

            Maybe it helped some human too....
            Zabbix agents on Linux, FreeBSD, Windows, AVM-Fritz!box, DD-WRT and QNAP

            Comment

            Working...