Pages

2010-02-21

MRTG - Custom monitoring of a linux box using net-snmp (lm-sensors)

Assume you want to monitor the FAN rotation of your CPU and CPU and MB temperature:

Step 1: Set up lm-sensors

rtfmlm-sensors
Step 2: Create check script (e.g. /var/www/mrtg/sensors)

#!/bin/bash
case $1 in
fan)   
    /usr/bin/sensors | grep fan1| awk '{print $2}'
;;
temp)   
    /usr/bin/sensors | grep temp1| awk '{print $2}'| sed "s/[+|°C]//g" | sed "s/\..*$//g"
    /usr/bin/sensors | grep temp3| awk '{print $2}'| sed "s/[+|°C]//g" | sed "s/\..*$//g"
;;
esac


Step 3: Extend snmpd.conf

extend .1.3.6.1.4.1.2021.50 fan /var/www/mrtg/sensors fan
extend .1.3.6.1.4.1.2021.51 cpu_temp /var/www/mrtg/sensors temp


Step 4: Snmpwalk required OID

rtfm snmpwalk

Step 5: Extend mrtg.conf

Target[atom.fan]: .1.3.6.1.4.1.2021.50.4.1.2.3.102.97.110.1&.1.3.6.1.4.1.2021.50.4.1.2.3.102.97.110.1:public@localhost
Title[atom.fan]: CPU Fan speed
PageTop[atom.fan]: <H1>CPU Fan Speed</H1>
MaxBytes[atom.fan]: 5000
ShortLegend[atom.fan]: rpm
YLegend[atom.fan]: RPM
LegendI[atom.fan]: CPU fan speed
Options[atom.fan]: growright,nopercent,unknaszero,gauge,noo
Unscaled[atom.fan]: ymwd

Target[atom.temp]: .1.3.6.1.4.1.2021.51.4.1.2.8.99.112.117.95.116.101.109.112.1&.1.3.6.1.4.1.2021.51.4.1.2.8.99.112.117.95.116.101.109.112.2:public@localhost
Title[atom.temp]: Temperature
PageTop[atom.temp]: <H1>Temperature</H1>
MaxBytes[atom.temp]: 100
ShortLegend[atom.temp]: °C
YLegend[atom.temp]: Temperature
LegendI[atom.temp]: CPU Temperature
LegendO[atom.temp]: MB Temperature
Options[atom.temp]: growright,nopercent,unknaszero,gauge
Unscaled[atom.temp]: ymwd




That's it!

MRTG - Performance monitoring of a linux box using net-snmp


LoadMIBs: /usr/share/mibs/netsnmp/UCD-SNMP-MIB


Target[atom.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
Title[atom.cpu]: Server CPU Load
PageTop[atom.cpu]: <H1>CPU Load - System, User and Nice Processes</H1>
MaxBytes[atom.cpu]: 100
ShortLegend[atom.cpu]: %
YLegend[atom.cpu]: CPU Utilization
Legend1[atom.cpu]: Current CPU percentage load
LegendI[atom.cpu]: Used
LegendO[atom.cpu]:
Options[atom.cpu]: growright,nopercent,unknaszero
Unscaled[atom.cpu]: ymwd

Target[atom.memory]: memAvailReal.0&memTotalReal.0:public@localhost
Title[atom.memory]: Free Memory
PageTop[atom.memory]: <H1>Free Memory</H1>
MaxBytes[atom.memory]: 100000000000
ShortLegend[atom.memory]: B
YLegend[atom.memory]: Bytes
LegendI[atom.memory]: Free
LegendO[atom.memory]: Total
Legend1[atom.memory]: Free memory, not including swap, in bytes
Legend2[atom.memory]: Total memory
Options[atom.memory]: gauge,growright,nopercent,unknaszero
kMG[atom.memory]: k,M,G,T,P,X

Title[atom.mempercent]: Percentage Free Memory
PageTop[atom.mempercent]: <H1>Percentage Free Memory</H1>
Target[atom.mempercent]: ( memAvailReal.0&memAvailReal.0:public@localhost ) * 100 / ( memTotalReal.0&memTotalReal.0:public@localhost )
Options[atom.mempercent]: growright,gauge,transparent,nopercent,unknaszero
Unscaled[atom.mempercent]: ymwd
MaxBytes[atom.mempercent]: 100
YLegend[atom.mempercent]: Memory %
ShortLegend[atom.mempercent]: Percent
LegendI[atom.mempercent]: Free
LegendO[atom.mempercent]: Free
Legend1[atom.mempercent]: Percentage Free Memory
Legend2[atom.mempercent]: Percentage Free Memory
That's it!

Join a string array to a string in Java - like join() in Perl

 An implementation of Perl like join() function in Java:



        public static String join(String[] strings, String separator) {
            StringBuffer sb = new StringBuffer();
            for (int i=0; i < strings.length; i++) {
                if (i != 0) sb.append(separator);
                     sb.append(strings[i]);
                 }
                 return sb.toString();
        }

Enjoy!

How to fix NO_PUBKEY errors in "apt-get update" operations

Just keep stumbmling upon it every time:


W: GPG error: http://ftp.de.debian.org stable/non-US Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F1D53D8C4F368D5D
W: You may want to run apt-get update to correct these problems

You should run the following to fix it (substitute F1D53D8C4F368D5D with the one from your error message):
gpg --keyserver subkeys.pgp.net --recv F1D53D8C4F368D5D
gpg --export --armor F1D53D8C4F368D5D | apt-key add -

Now you can run apt-get update and will not get an error message.
 That's it!

"Fork" in bash w/ timeout


This simple bash script will call “a_very_long_operation” command and wait for LIMIT seconds until it exits with 1.
Otherwise the script will exit with the return code of the command
#!/bin/sh
WAIT=1
LIMIT=10
echo "Forkie"
function fork {
        $1 >/dev/null 2>&1
        echo $? > $3
        rm -f $2
}
FORK_STATUS="/tmp/forkie.fork.$$"
FORK_RETURN="/tmp/forkie.ret.$$"
rm -f $FORK_STATUS $FORK_RETURN
touch $FORK_STATUS
fork "a_very_long_operation"  $FORK_STATUS $FORK_RETURN &
TIMEOUT=0
while [ $TIMEOUT -le $LIMIT ]
do
        if ! [ -f $FORK_STATUS ]
        then
                RC=`cat $FORK_RETURN`
                rm -f $FORK_RETURN
                exit $RC
        fi
        sleep $WAIT
        TIMEOUT=`expr $TIMEOUT + $WAIT`
        if [ $TIMEOUT -eq $LIMIT ]
        then
                exit 1
        fi
done
That’s it!

Tutorial to set up Axis2 + Eclipse Galileo + Tomcat Framework

There's a great tutorial how to set up an Axis 2 webservice development framework using recent versions:

Eclipse Galileo
Tomcat 6
Axis 2

Check it out here: http://www.vogella.de/articles/Webservice/article.html