Donnerstag, 1. September 2011

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

Hello,

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. (http://www.messpc.de)

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

[global]
interval=5
samples=25000
loop=1000

[network]
networkserverport=4000

[ports]
com1.1=01
com1.2=01




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
./pcmeasure

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

pcmeasure.com1.1.current=27.51
pcmeasure.com1.1.currenttimestamp=0
pcmeasure.com1.1.maxvalue=0.00
pcmeasure.com1.1.maxtimestamp=0
pcmeasure.com1.1.minvalue=0.00
pcmeasure.com1.1.mintimestamp=0

pcmeasure.com1.2.current=48.11
pcmeasure.com1.2.currenttimestamp=0
pcmeasure.com1.2.maxvalue=0.00
pcmeasure.com1.2.maxtimestamp=0
pcmeasure.com1.2.minvalue=0.00
pcmeasure.com1.2.mintimestamp=0

Here we are. The sensors are working. The labels 
 pcmeasure.com1.x.current=xx.xx
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 
/var/www/messpc 
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

sourcefile=/root/pcmeasure/pcmeasure.dat
targetfile=/var/www/messpc/sensor$2.dat

searchstring=$1
startbracket="["
endbracket="]"

rawsensor1=`grep $searchstring $sourcefile`
#echo $rawsensor1
position=`expr index "$rawsensor1" =`
#echo $position
sensor1=${rawsensor1:position}
length=`expr length "$sensor1"`
#echo $length
z=$(($length - 1))
#echo $z
sensor1=${sensor1:0: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
./copy_sensor.sh pcmeasure.com1.1.current= 1
echo Copy Sensor 2
./copy_sensor.sh 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 

3 Kommentare:

  1. I thought this was a pretty interesting read when it comes to this topic. Thank you
    prtg-network-monitor-crack

    AntwortenLöschen
  2. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to Crack Softwares Free Download But thankfully, I recently visited a website named annicrack
    PRTG Network Monitor Crack





    WinZip Driver Updater Crack
    WinVSDC Video Editor Pro Crack
    RedFox AnyDVD HD Crack
    Native Instruments KontaktCrack
    SILKYPIX Developer Studio Pro Crack

    AntwortenLöschen