I am extracting the cpu temperature from a Raspberry Pi using the following in my telegraf.conf
[[inputs.file]] files = ["/sys/class/thermal/thermal_zone0/temp"] name_override = "cpu_temperature" data_format = "value" data_type = "integer"
This entry is working but unfortunately the value in the “temp” file is stored as an integer to allow for 3 decimal places of precision i.e. 50.307 is written to the file as 50307 so I get a displayed CPU temperature of 50k C instead of 50 C.
I would like to use a starlark processor to divide the original value by 1000 so that the outputted value is in the correct form but have been unable to get the processor to work. I have tried the following:
[[processors.starlark]] source=''' original = metric.fields["cpu_temperature"] metric.fields["cpu_temperature"] = original / 1000 return metric '''
but using this code I get as error telling me that the cpu_temperature field does not exist. I have tried to log out the metric object to see what the actual structure is after the name_override but this has also not been successful.
[[processors.starlark]] load("logging.star", log) log.debug(metric)
I also tried a more generic loop to see if I could avoid the naming issue but this seemed to try and apply the logic in the loop to every measure in the conf rather than just the one in
[[inputs.file]] (possible indentation requirement to restrict processor to specific input?)
[[processors.starlark]] for k, v in metric.fields.items(): if type(v) == "int": metric.fields[k] = v * 10 return metric
From all of this I have three questions
- How do I modify the value of my “name overridden” measurement so that the outputted value is divided by 1000?
- How do I log out items and/or values when running Telegraf? (it would be good to be able to see what’s in the metric object)
- How do I ensure that the processor only applies its logic to the enclosing “input” and is not applied to the entire list of inputs?
Many thanks in advance