OPNsense Forum

English Forums => Tutorials and FAQs => Topic started by: MTR on July 04, 2020, 07:30:22 PM

Title: Getting Telegraf to log CPU temperatures to Influx
Post by: MTR on July 04, 2020, 07:30:22 PM
Hi,

I was fiddling around with the Telegraf plugin and a TICK-stack server and i thought it would be nice to graph the CPU temperatures as well. But adding [[inputs.temp]] to /usr/local/etc/telegraf.conf throws an error:
QuoteE! [inputs.temp] Error in plugin: plugin is not supported on this platform: not implemented yet
Hm, bummer. So i tried some stuff to get it to work and i came up with a workaround utilizing [[inputs.exec]].

This might or might not work on different systems than the one i'm using but it does work for a Intel i7-4500U CPU. I use this one-liner to get a properly formed output of my cpu temperatures from sysctl (you might need to change this to make it work for your system):
sysctl dev.cpu | grep temperature | sed 's/[a-z\.]*/systemp cpu/;s/\.[a-z]*\: /=/;s/.$//'
The output looks like this:
Quotesystemp cpu3=47.0
systemp cpu2=47.0
systemp cpu1=46.0
systemp cpu0=46.0

To get it all going:
1) Create /usr/local/etc/telegraf-scripts/cputemp.sh which contains above mentioned one-liner
2) Add these lines to /usr/local/etc/telegraf.conf:
[[inputs.exec]]
  commands = [
    "sh /usr/local/etc/telegraf-scripts/cputemp.sh",
  ]
  timeout = "5s"
  data_format = "influx"

3) Restart telegraf: service telegraf restart

That's it. You should now be able to graph your CPU temperatures from the newly created systemp measurement on your Influx server.

Title: Re: Getting Telegraf to log CPU temperatures to Influx
Post by: xedmada on October 07, 2021, 01:22:23 PM
Thank you for sharing. After discovering your post I made a small adjustment to the sed used in order to output a format setting the cpu# as a feature tag so it more closely matches the existing Telegraf sensors format:

sysctl dev.cpu | grep temperature | sed 's/[a-z\.]*/sensors,feature=cpu/;s/\.[a-z]*\: / temp_input=/;s/.$//'

Title: Re: Getting Telegraf to log CPU temperatures to Influx
Post by: MTR on October 12, 2021, 07:37:52 PM
Nice, thanks!
Title: Re: Getting Telegraf to log CPU temperatures to Influx
Post by: bluemorph on November 03, 2024, 01:38:35 AM
still worked like a charm!

Thank you :heart: