[SOLVED] Running telegraf as Windows service always results in Error in plugin [inputs.exec]

telegraf
#1

I am using telegraf 1.3.0 to run a custom powershell script using input.exec. The output is line protocol and is supposed to write to influxdb.

When I run the telegraf from command prompt, every thing works fine. I can see all the metrics getting written to influxdb.

I am expecting line protocol output in following format:
Exports,Id=123456,Profile=Profile_Name,Status=Completed,HH=NN,MM=NN Count=12345 time

However when I run the telegraf as a service I keep getting errors like the below ones:

2017-09-05T07:22:02Z E! Error in plugin [inputs.exec]: metric parsing error, reason: [invalid field format], buffer: [Exports,Id=1060848,Profile=Initial\ Item\ Export,Status=Completed,HH=0,MM=20 Co], index: [79] metric parsing error, reason: [invalid field format], buffer: [unt=0 1504596045240000000], index: [25] metric parsing error, reason: [missing fields], buffer: [ 1504596103010000000], index: [20] metric parsing error, reason: [invalid field format], buffer: [Exports,Id=1060850,Profile=Enriched\ Item\ Export,Status=Completed,HH=0,MM=21 C], index: [79] metric parsing error, reason: [invalid field format], buffer: [ount=0 1504596068890000000], index: [26]

I have tried using file as ouput also but still the same issue happens.

#2

There has been several fixes to this code since 1.3.0, could you try with the 1.4.0 release candidate and see if it helps? If you still get the error, can you show some of the output when running from a command prompt with a file output?

#3

Hi Daniel,

I tried with the suggested release candidate and the issue persists. Here are few additional details:

Looks like it’s a issue with the message length for the line protocol. If line protocol has more than 80 characters, it is getting truncated and based on the truncated message the error occurs.

I modified my powershell script to simply return hardcoded line protocol to see what works and what fails

Scenario 1: Line protocol length >80 characters
Message: “Exports,Id=1061237,Profile=Enriched,Status=Completed,HH=10,MM=58 Count=2 1504634289773000000”

Result via Windows Service: Failed. Error Log: 2017-09-05T19:17:01Z E! Error in plugin [inputs.exec]: metric parsing error, reason: [missing fields], buffer: [4289773000000], index: [13]

Result via Command Prompt: Success. Event successfully written to desired outputs

Scenario 2: Line protocol length <80 characters
Message: “Expt,Id=1061237,Prf=Enr,Stat=C,HH=1,MM=5 Cnt=2 1504634289773000000”

Result via Windows Service: Success. Event successfully written to desired outputs

Result via Command Prompt: Success. Event successfully written to desired outputs

#4

Any chance the powershell script is adding line breaks before the end of the line?

#5

Looks like the issue is with powershell v2.0. I was able to run things properly with v4.0. powershell v2.0 by default uses standard width of command prompt (80 characters) and adding line breaks after that. I looked into other forums and found that we can change that behavior by adding following line to powershell script:

$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)

#6

Glad you got it working, that’s very interesting behavior on powershells part.