Inputs.exec not creating data

Hi all, I recently built a pfSense router, and installed the Telegraf package to write metrics to my InfluxDB. However, the base Telegraf package for pfSense does not have a measurement for CPU Temperature. So, I figured I could add an inputs.exec entry to the “additional configuration for Telegraf” box.

Here’s what I entered:

[[inputs.exec]]
  commands = ["sysctl -n dev.cpu.0.temperature | tr -d 0.C"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "influx"
  [inputs.exec.tags]
    cpu = "cpu0"

However, this does not result in a new measurement. As far as I can tell, it’s doing nothing. I know that user account access can be an issue, but as far as I can tell there is only one user on my pfSense, and that user has full administrator access.
Can anyone point me in the right direction?

The reason there is no measurement, is because you have the wrong data_format. Set it to value and then set data_type=integer (unless you change your tr to tr -d C, in which case you would set the data_type to float)

This makes perfect sense… I was a little confused about the data_format, and this clears that up. Also, thank you for your note about the tr command. I did choose to trim 0.C because it appears those values are always whole numbers, however it occurred to me that if it ever returned a decimal value, my command would no longer work. I think I will change it to trim off only the C, and set the data_type to float.

With that said, I’ve made the suggested changes and restarted pfSense, but unfortunately the measurement is still not showing up. Seems like there must be something else wrong.

Are there any logs in pfSense that might tell me what is happening? I looked around in the system log, but I didn’t see anything.

Thanks for your help!

Can you ssh into your box and run telegraf manually pointing at this config:

[[outputs.file]]

[[inputs.exec]]
  commands = ["sysctl -n dev.cpu.0.temperature | tr -d C"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "value"
  data_type = "float"
  [inputs.exec.tags]
    cpu = "cpu0"

If there is output that looks like the following, then you just need to debug your configured output:

cpu_temp,cpu="cpu0" cpu_temp=41.0 123498762134

Regarding logging, it depends on your config file. I’m not sure where pfsense’s telegraf config has the logs going to. I manually installed telegraf on my pfsense box. This telegraf issue has some good conversation regarding telegraf on pfsense.

Thanks, I’ll give this a try when I get home tonight. If you can point me in the right direction for how to run telegraf manually from the shell, that would be helpful! However, I’m sure I can google my way there if I need to!

Thanks again, you’ve been very helpful!

If telegraf is in your path (should be after either manual pkgadd or pfsense gui install), you simply call it: telegraf --config /path/to/your/config ctrl-c to end the process.

1 Like

Well, I ran telegraf manually per your instructions (thank you again for that!), and the result is the following error:

Error in plugin [inputs.exec]: exec: exit status 4 for command 'sysctl -n dev.cpu.0.temperature | tr -d C': sysctl: unknown oid '|'...

Google isn’t yielding much for “telegraf inpus.exec exit status 4”… any ideas?

Hi @tkohhh

can you try to put the commands in an executable script , with a shebang and all , and call the script in the inputs.exec plug-in ?The user Telegraf should have execute permissions on that script and you may have to specify the complete path in the commands parameter …

Thanks for the suggestion. I’ll read up on creating scripts and see if I can get that going when I get home tonight!

I was able to get this working. Somebody on reddit suggested using sh -c ‘command here’ in the telegraf command block. That worked great, so here is the telegraf.conf entry that I ended up using:

[[inputs.exec]]
  commands = ["sh -c 'sysctl -n dev.cpu.0.temperature | tr -d C'"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "value"
  data_type = "float"
  [inputs.exec.tags]
    core = "core0"

[[inputs.exec]]
  commands = ["sh -c 'sysctl -n dev.cpu.1.temperature | tr -d C'"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "value"
  data_type = "float"
  [inputs.exec.tags]
    core = "core1"

[[inputs.exec]]
  commands = ["sh -c 'sysctl -n dev.cpu.2.temperature | tr -d C'"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "value"
  data_type = "float"
  [inputs.exec.tags]
    core = "core2"

[[inputs.exec]]
  commands = ["sh -c 'sysctl -n dev.cpu.3.temperature | tr -d C'"]
  name_override = "cpu_temp"
  timeout = "5s"
  data_format = "value"
  data_type = "float"
  [inputs.exec.tags]
    core = "core3"

Thank you both for your help!!!

Tkohhh ,

thank you for this very valuable feedback !