Periodic temp readings from collectd to log files

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))
logger -t temp "$(head -c2 `find /sys | grep '/temp$' | head -n1`)"

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

IMHO this is over-thinking the issue..I already identified the problem (the fan under the router)...I'm just looking at continued temp reports that show if I am over nominal operating range.

the original answer does everything I want it to do...(obviously if you want to submit your own fix as an addendum (with your reasons why this is better) then I would appreciate the input)

1 Like

Addendum - this is what I use with the Prometheus node exporter for OpenWRT

Stored in: /usr/lib/lua/prometheus-collectors/thermal_zones.lua

local function scrape()
  thermal_metric =  metric("thermal_zone", "gauge" )

  local fd = io.popen("find /sys/class/thermal/*/ -name temp")
  local lines = fd:read("*all")
  -- Report thermal per zone
  for line in lines:gmatch("([^\r\n]*)[\r\n]") do
    if line then
      local zone = string.match(line, "zone%d+")
      local temp = string.gsub(get_contents(line), "n", "")
      local labels = { zone = zone }
      thermal_metric(labels, temp) 
return { scrape = scrape }

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.