Telegraf Exec Input Plugin, Failing with multi-line influx input


I have a script that queries multiple UPS’s, so I can write data out use telegraf. If I just output a single UPS (i.e. single line), no issue at all - it all works. But, trying to have the Plugin accept multiple input lines (and send them one-by-one to influxdb) => then it fails, with an error message,

Error in plugin: metric parse error: expected field at 1:223

Is this a known issue? Can I really not send multiple input lines to this Plugin (in influx format)?


Yes it is possible to process multiple metrics at once. I guess you can’t just append the influx line protocol lines to each other, you have to output each line individually via stdout.
Have you looked at what the script actually outputs?
Can you show the script?

Sure! Here is the output (and it causes an error / failure :frowning_face:)

ups-nut,host=pfSense,ups_name=firewall,model=Back-UPS\ ES\ 550,status=OL battery_charge_percent=100,battery_date="2007/05/11",battery_voltage=13.8,firmware="840.B2.D",input_voltage=124.0,load_percent=2,nominal_battery_voltage=12.0,nominal_input_voltage=120,battery_runtime_sec=3097i 1625014104608969636
ups-nut,host=linuxServer,ups_name=linuxServer,model=Back-UPS\ XS\ 1500M,status=OL battery_charge_percent=100,battery_date="2020/09/04",battery_voltage=27.3,firmware="947.d10 .D",input_voltage=119.0,load_percent=20,nominal_battery_voltage=24.0,nominal_input_voltage=120,nominal_power=900i,battery_runtime_sec=1755i 1625014104658589269


No idea what the problem is, I put these lines in a file and read them with Telegraf, that worked. :thinking:
I can only guess:

  • An unescaped whitespace?
  • A control character?
  • Does your script output each line individually on stdout?
  • What about pipe the exec script output into a file, to examine the output?

Hmmm - let me dig. This is the output from my script (multi-line), and it yells about it. You didn’t process the lines individually, rather as a combined output … right?


I wrote a simple python script that just spits out these two lines separately:

print("""ups-nut,host=pfSense,ups_name=firewall,model=Back-UPS\ ES\ 550,status=OL battery_charge_percent=100,battery_date="2007/05/11",battery_voltage=13.8,firmware="840.B2.D",input_voltage=124.0,load_percent=2,nominal_battery_voltage=12.0,nominal_input_voltage=120,battery_runtime_sec=3097i 1625014104608969636""")
print("""ups-nut,host=linuxServer,ups_name=linuxServer,model=Back-UPS\ XS\ 1500M,status=OL battery_charge_percent=100,battery_date="2020/09/04",battery_voltage=27.3,firmware="947.d10 .D",input_voltage=119.0,load_percent=20,nominal_battery_voltage=24.0,nominal_input_voltage=120,nominal_power=900i,battery_runtime_sec=1755i 1625014104658589269""")

I ran Telegraf with this config:

  commands = ["python"]
  data_format = "influx"

[[outputs.file]]  # only for debugging
  files = ["ups.out"]
  influx_sort_fields = true

It worked, no error messages.

I would try to debug your script output.
Just pipe the output of your script to a file and analyze it.

yourscript > out.txt

Will dig into it, thanks!

Sorry for the slow reply - for some reason, not getting an email for posts / replies (and don’t check it daily). Seems I need to fix that also … LOL!

Hmmm - OK, this may be me, but … if I run telegraf --test => no issues at all. But, if I the restart the service, I get errors, like,

telegraf[1225479]: 2021-07-03T18:11:20Z E! [inputs.exec] Error in plugin: exec: fork/exec /mnt/ProgSSD/upsInflux/ no such file or directory for command '/mnt/ProgSSD/upsInflux/ /mnt/ProgSSD/upsInflux/upsConfig.json'

It also works if I manually run the command. Thinking that perhaps this is related to paths … does the service run from a different path? I can also manually just run telegraf … all good. Very odd!


Yeh , or possibly permssions for telegraf service account that can’t access that location.