Donnerstag, 1. September 2011

Read MessPC temperature sensor and populate values in PRTG Network Monitor in Linux


today I wan't to show a little tutorial howto read temperature sensors from the german company "MessPC" and populate the values in PRTG Network Monitor from Paessler.

Installing and configuring the sensors and the software

First you need the sensors. In my example I have the com port interface twin adapter (30203) with two attached sensors (30101) . 
Then you need the software for Linux which can be bought directly at the MessPC Online Shop. (

Attach the two sensors to the adapter and plug it into your com port interface. If you have more than one com port interface in your server or pc, remember which on you've plugged the adapter in. In most cases the interfaces are labeled.

You will get the software as a tarball. Untar it (tar -xvzf) in your favorite directory. You will find a file called "pcmeasure" which is the executable of the program and a file called "pcmeasure4linux.cfg". This is your config file.

In my example the ready configured file looks like




The interesting part is "ports" label which describes your com port (in my case com port 1) and the sensor index. In my case two sensors with index 1 and 2 at com port 1. The twin adapter should have little labels an the cables to identify the sensors. The figures behind the equals sign describes the type of the sensor. "01" means temperature. The types are described in the installation textfile which should be also a content of the tarball.

If finished the config file start the program with

The program starts a deamon which stays in background and read the sensors every x seconds (interval). So there is no need to attach 
> /dev/null 2>&1 &

Now you should have a file called "pcmeasure.dat" in the same directory as your main programm. The file looks like



Here we are. The sensors are working. The labels 
with the figure behind the equal sign is our current temperature. The file will be rewritten every x seconds (intervall) as long the pcmeasure deamon is running.

Installing the script for PRTG
The prerequisite is a working webserver. In my example I've decided for apache2. It's secure, fast, trusty and FREE ;-).

I've created a folder 
and configured it as virtual host.

With the following code snipet you can extract the temperature from every sensor of the pcmeasure.dat file and write it to a separate file into your webfolder for PRTG. The values has to be embedded into opening and closing brackets for PRTG.

#! /bin/sh

# $1 = searchstring in sourcefile i.e. pcmeasure.com1.1.current=
# $2 = sensorcount i.e 1

#echo $1
#echo $2



rawsensor1=`grep $searchstring $sourcefile`
#echo $rawsensor1
position=`expr index "$rawsensor1" =`
#echo $position
length=`expr length "$sensor1"`
#echo $length
z=$(($length - 1))
#echo $z
#echo $sensor1
echo $startbracket$sensor1$endbracket>$targetfile

Voilà!. After executing that script twice for every sensor you should have 2 files. Sensor1.dat and Sensor2.dat. This files should be viewable in your webbrowser.
I recommend to combine the extraction of the sensors into one basic script like

#! /bin/sh

echo Copy Sensor 1
./ pcmeasure.com1.1.current= 1
echo Copy Sensor 2
./ pcmeasure.com1.2.current= 2

Add the basic script into the crontab and execute it in every interval you want. For me every minute is more than enough.

Setup the sensors in PRTG

Start your PRTG Webgui and add a new device "MessPC" with the properties your server has.

Don't choose automatic sensor search. Select "manually" instead.

Add a sensor by clicking "Add sensor"

Sensorgroup is Webserver (HTTP,HTTPS) with type HTTP (Content)

The properties of the sensor1. Repeat it with sensor2. Name it however you want.

Here are the values in PRTG.

Thats it.
Now you should be able to controll the temperature with your PRTG Network Monitor. 

Hope this HowTo helped