petervojtek / usb-thermometer

Read temperature from cheap usb thermometers (based on pcsensor0.0.1 binary)
29 stars 32 forks source link

Problem with collectd integration. #11

Open beepbeepplop opened 8 years ago

beepbeepplop commented 8 years ago

Im having a hell of a time getting collectd to get data from this thermometer. Tried a variety of different things to no avail. It's working from the command line. Could anyone assist by sharing more details of how they achieved working collectd integration? Even just configs might be better than randomly trying stuff. ty

beepbeepplop commented 8 years ago

I explain my issue here: http://stackoverflow.com/questions/39580455/exec-plugin-collectd-issue

xrat commented 8 years ago

I provided a comment, but had to edit it 3 times to get it right ;-)

beepbeepplop commented 8 years ago

Thankyou for the response. This is actually driving me a little mad. It all works from the command line, but as soon as collectd gets involved it just falls apart.

beepbeepplop commented 8 years ago

BTW ive been on irc at #collecd for the past 3-4 days. Noone has been able to help me there.

xrat commented 8 years ago

I don't use collectd, so I can provide only general help. The plugin file wants to execute /usr/local/bin/collectd_pcsensor_temper.sh as nobody. Try running it as such on the console:

su -c /usr/local/bin/collectd_pcsensor_temper.sh nobody
beepbeepplop commented 8 years ago

I changed it from nobody to incognito. I also removed the root requirement through a udev script.

sudo -u incognito /usr/local/bin/collectd_pcsensor_temper.sh

works` fine btw. :)

xrat commented 8 years ago

I am afraid I can't follow. So the plugin works now?

beepbeepplop commented 8 years ago

No. This was one of the first avenues i investigated. :) It has never worked for me inside collectd.

xrat commented 8 years ago

So, what does su -c /usr/local/bin/collectd_pcsensor_temper.sh nobody give you on the console run as root, or sudo su -c ... if you are restricted user.

beepbeepplop commented 8 years ago

Well i changed it to incognito..so let's stick with that. su -c /usr/local/bin/collectd_pcsensor_temper.sh incognito gives me no output.

xrat commented 8 years ago

No output suggests that the exit code is non-zero. Try

su -c /usr/local/bin/collectd_pcsensor_temper.sh incognito ; echo exitcode=$?
beepbeepplop commented 8 years ago

exitcode=1

xrat commented 8 years ago

Let us inspect the contents of /usr/local/bin/collectd_pcsensor_temper.sh.

beepbeepplop commented 8 years ago

Should be identical to this file: https://github.com/petervojtek/usb-thermometer/blob/master/collectd_pcsensor_temper.sh.in

xrat commented 8 years ago

That's not what you posted on stackoverflow. And it cannot be identical. Since there's @@BIN_DIR@@. Please cat the file contents here.

beepbeepplop commented 8 years ago

i posted a test file on SO. Ive been working on this for days. But you're right. collectd_pcsensor_temper.sh

#!/bin/bash -e

set -euo pipefail
IFS=$'\n\t'

PCSENSOR=/usr/local/bin/pcsensor

HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-60}"

${PCSENSOR} -l${INTERVAL} -n | sed -e "s/^.*\$/PUTVAL $HOSTNAME\/pcsensor\/gauge-temper\ interval=$INTERVAL N:\0/"
xrat commented 8 years ago

I guess that the ${PCSENSOR} part is the culprit. But I am afraid we'll need to check it out bit by bit. Put echo before ${PCSENSOR} and \ directly before the | sed, i.e. make it

echo ${PCSENSOR} -l${INTERVAL} -n \| sed -e "s/^.*\$/PUTVAL $HOSTNAME\/pc (...)

and run su -c /usr/local/bin/collectd_pcsensor_temper.sh incognito ; echo exitcode=$? again.

beepbeepplop commented 8 years ago

Thank you for the continued assistance.

exitcode=1

xrat commented 8 years ago

Uhm, I need the full output! Oh, wait, there was no output!?

beepbeepplop commented 8 years ago

That was the full output.

xrat commented 8 years ago

If running a shell script that basically has only an echo command fails without providing any error message then something is very wrong :-/ Of course, one can go on debugging this but that's not an issue with collectd nor usb-termometer/pcsensor. Here's what it returns on my system:

# su -c /usr/local/bin/tmp.sh incognito
/usr/local/bin/temper_pcsensor -l60 -c | sed -e s/^.*$/PUTVAL "localhost\/pc\/gauge" interval=60 N:\0/

And no matter what I do to make it fail, it always shows an error message.

beepbeepplop commented 8 years ago

running as root (sudo su) gave no ouput. Running from my user account gives

/usr/local/bin/pcsensor -l60 -n | sed -e s/^.*$/PUTVAL localhost\/pcsensor\/gauge-temper\ interval=60 N:\0/
exitcode=0
beepbeepplop commented 8 years ago

In my defence I have at least 10 screen tabs, sshing into my server and it's getting late. Plus i have tried many many things to fix this before i ever asked for assistance from anyone. :) Thanks for your continued patience and assistance.

beepbeepplop commented 8 years ago

Could this be the issue: http://stackoverflow.com/questions/39582607/decode-sed-expression?noredirect=1#comment66479338_39582607

Hmm probably not.

beepbeepplop commented 8 years ago

Well i finally got it working. It's a cock-eyed method that presumably could be bettered. But this appears to be working. It's producing a graph as expected. Comments?

#!/bin/bash
 INTERVAL=10
 while true
 do
/usr/local/bin/pcsensor -n > /var/tmp/temperature
cat /var/tmp/temperature  |  sed -e 's/.$//;s/^[0-9][0-9]*\.[0-9]/PUTVAL downloads\/exec-environmental\/temperature-cpu interval=30 N:&/'
sleep $INTERVAL
done

Oh spoke to soon. It has failed after a short period of time with

Could not set configuration 1

This is in the /var/tmp/temperature file. I have no idea. :(

beepbeepplop commented 8 years ago

Last try. So i removed the pcsensor line and just fill it manually from the terminal. ie

/usr/local/bin/pcsensor -l60 -n > /usr/local/share/temperature #yes ive moved the file incase it's a permissions problem

and updated the script to

 #!/bin/bash
 INTERVAL=10
 while true
 do
cat /usr/local/share/temperature  |  sed -e 's/.$//;s/^[0-9][0-9]*\.[0-9]/PUTVAL downloads\/exec-environmental\/temperature-cpu interval=30 N:&/'
    sleep $INTERVAL
 done

Now i get this output. http://pastebin.com/eMqB2cEL If anyone could help I would appreciate it. Thank you :)

beepbeepplop commented 8 years ago

Scrap that. It works. I replaced cat with tail -1 in the script. But boy does it feel like a hack. :) alt text