Periodic temp readings from collectd to log files

I have a wrt1900ACS router running the divested build (which tbh isn't relevant to this question) and I've added the luci-app-statistics module to the webGUI so I can monitor the temperature of my router (cos it's in a hard to reach place up high (heat rises) and I recently had an external cooling fan fail resulting in an outage.

As the external fan is pretty critical, I would like to have periodic temperature readings spat out to the log file (say every 10mins?)...I've tried to find this and I think I can do it by sending the output of the temp sensor to the log via a cron job, but I don't know where to look to find the actual temp reading that is obtained from collectd. (I looked in /tmp/rrd but it's not human-readable)

Where should I look for a text output of the temperature reading? or is this something I have to accomplish using other means?

or am I going about this wrong?

now I have to install bash, thanks anyway

Not really, Ash is more than enough to work with sysfs.

yeah, it isn't as simple as the example says...remember this is openwrt not a standard linux install.

I found the query to get me a 6 digit integer of the temperature, now I'm trying to convert it (and my shell skills are extremely rusty)

echo $(($(cat /path/to/temp)/1000))
2 Likes
logger -t temp "$(head -c2 `find /sys | grep '/temp$' | head -n1`)"
2 Likes

wow, it's over 100 degrees?

my mistake, 5 digits..

Well, if it ever goes above 99.999 (or below 10.000) then you'll either need to use the $(( x / 1000 )) method ... or, if you want to keep the fractional part

logger -t temp "$(cat $(find /sys -name temp) | head -1 | sed -e 's/...$/.&/')"

perfect!...thanks to everyone for their quick help!

that will give false values if the temperature falls outside of 10.000 -> 99.999

If you don't care about the fractions

logger -t temp "$(($(cat $(find /sys -name temp) | head -1) / 1000))"

sorted, now using your version...it was definitely what I wanted though even if it wouldn't go over 100c

I always think of edge cases :stuck_out_tongue:

dude, when you are in the tropics the temperature is something you need to be aware of, so it may be an edge case but it's still relevant!

thanks a bunch for the help guys!

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

one more quick question..my cron job runs as planned now and everything shows up fine, however the level status is Error in the log. Any idea what could be causing this?

this is a typical output in the log
Thu Nov 11 19:45:00 2021 cron.err crond[28182]: USER root pid 28352 cmd /usr/sbin/get_temp
Thu Nov 11 19:45:00 2021 user.alert System_Temp: 51.789

That is a quirk, cron uses a log function in busybox that has no input for error levels and is fixed to log everything as an "error." So every log message will be an error, whether it is an actual error or not.

What you can do, however, is set cron itself to a different error level, it will internally decide what to send to the log -- see the cronloglevel option in /etc/config/system. Personally I set it to 9, so it will really only send actual errors.

1 Like

thanks for the help!

@batkung I would not average it out if the reported temperatures are not "uniform"

Figuring out what the thermal zones are and then averaging that out as a monitoring post-op makes more sense. You might want to know the cause of a change.

My 2c.

FYI, cellular modems do expose internal temperatures that can also be extracted and monitored against the suggested operating temperatures.