dinsdag 14 juli 2015

mpower ubiquiti to Carbon/Grapite

mpower ubiquiti to Carbon/Grapite

Since the graphite interface seems to be a standard in statistics gathering (also supported by opentsdb and influxdb) Its a much nicer setup if we cut out the collectd middleman:


This script will poll the the mpower twice per minute if you put it in cron, it will send the data to to your carbon host using the plaintext protocol (http://graphite.wikidot.com/getting-your-data-into-graphite)

mpower2carbon.sh                                                                                     
#!/bin/bash                                                                     
MPOWERNAME=MPBureau
MPOWERHOST=192.168.1.100                                                       GRAPHITESERVER=192.168.1.125
GRAPHITEPORT=2003
curl -X POST -d "username=admin&password=yourpassword" -b "AIROS_SESSIONID=01234567890123456789012345678901" $MPOWERHOST/login.cgi
for i in 1 2
do
  for MP in 1 2 3
        do
        SENSOR=$(curl -b "AIROS_SESSIONID=01234567890123456789012345678901" $MPOWERHOST/sensors$MP)
          MPPOWER=$(echo $SENSOR | cut -d "," -f3 | cut -d ":" -f2)
            echo "mpower.$MPOWERNAME.power $MPPOWER `date +%s`" | nc -q0 ${GRAPHITESERVER} ${GRAPHITEPORT}

          MPCURRENT=$(echo $SENSOR | cut -d "," -f5 | cut -d ":" -f2)
   echo "mpower.$MPOWERNAME.current $MPCURRENT `date +%s`" | nc -q0 ${GRAPHITESERVER} ${GRAPHITEPORT}

          MPVOLTAGE=$(echo $SENSOR | cut -d "," -f6 | cut -d ":" -f2)
            echo "mpower.$MPOWERNAME.voltage $MPCURRENT `date +%s`" | nc -q0 ${GRAPHITESERVER} ${GRAPHITEPORT}

          MPPOFA=$(echo "scale=2 ; ($(echo $SENSOR | cut -d "," -f7 | cut -d ":" -f2 )*100)" | bc)
            echo "mpower.$MPOWERNAME.powerfactor $MPPOFA `date +%s`" | nc -q0 ${GRAPHITESERVER} ${GRAPHITEPORT}
        done 
  sleep 20
done

Geen opmerkingen:

Een reactie posten