Telegraf inputs.exec formatting - Windows powershell

I run a script that monitors time offsets based on a log and produces output doing a Write-Output in format “offset,source=$gps_source protocol=$protocol offset=$offset” which when run produces output like below
offset,192.168.0.100 NTP -0.00111111111
this is formatted in config with
[[inputs.exec]]
[command] = ‘powershell “c://progra~1//telegraf/test.ps1”’
timeout=“10s”
interval=“10s”
name_suffix=time.stats
data_format=“influx”

when running a test with telegraf -config telegraf.config --test I get
[inputs.exec]: error in plugin: metric parse error: expected field at offset xx:“offset,source=192.168.0.100 protocol=NTP offset=-0.001111111\n”

I’m likely doing something wrong with formatting but don’t quite know what exactly. I tried removing the whitespace between source and protocol replacing with coma so it’s measurement,tag=value,tag=value field_key=value and that looks somewhat better but a bit of a mess
offsettime.stats,host=server5,protocol=ntp,source=192.168.0.100 offset=-0.0011111111 16040448399870809
How to format this correctly?

Your sting looks like a valid line protocol

offsettime.stats,host=server5,protocol=ntp,source=192.168.0.100 offset=-0.0011111111 16040448399870809

In order to test what’s wrong return a static string, like the one above, or even a simpler one, also remember that exec uses cmd to call powershell, and sometimes this causes issues

To test the script call it from cmd manually powershell -file _fileName_ or powershell -command _fileName_. there is a difference between the two, but it has been a while since I did some scripts and I don’t remember it.
I’ve had some problems in the past and ended up using Write-Output instead of Write-Host because in some cases cmd was “losing” characters.

To ensure what’s being outputted to influxDB you can also set up an output file in order to have the actual line protocol strings you are producing

here are some older posts about PowerShell that might help you:

1 Like

Thanks for the recommendation. Running the script under cmd returns same result. My main concern is why I’m getting the measurement name offset attached to time.stats. I was expecting it to look more like time.stats.offset.

I can’t really help since I don’t know the script, I’d set-up an output file in telegraf. Write your data there and into InfluxDB, in case of errors, InfluxDB will throw errors and you won’t see the points, but the output file will have them all. from there you can check what went worng