Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't start Telegraf Service Inputs.exec Linux #6028

Closed
raider111111 opened this issue Jun 21, 2019 · 18 comments
Closed

Can't start Telegraf Service Inputs.exec Linux #6028

raider111111 opened this issue Jun 21, 2019 · 18 comments

Comments

@raider111111
Copy link

Relevant telegraf.conf:

[[inputs.exec]]
  ## Commands array
  commands = ["telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1"."$2)}'"]
  ## Timeout for each command to complete.
  timeout = "5s"

  ## measurement name suffix (for separating different commands)
  name_suffix = "_mycollector"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "influx"

System info:

Steps to reproduce:

  1. Place command in the command block

Expected behavior:

Display Telegraf version number

Actual behavior:

Process fails to start

Additional info:

Failed to start The plugin-driven server agent for reporting metrics into InfluxDB.

Command executes sucessfully in the terminal:
telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1"."$2)}'
1.11

This is probably just formatting but I'm not sure what I'm doing wrong.

@goller
Copy link
Contributor

goller commented Jun 21, 2019

Hey @raider111111 , would you try escaping the double quotes like this:

  commands = ["telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\".\"$2)}'"]

@raider111111
Copy link
Author

That worked!

Thanks!

@raider111111
Copy link
Author

raider111111 commented Jun 21, 2019

Hi!

That worked but for some reason it isn't sending the data correctly.

Here's my config:

[[inputs.exec]]
  ## Commands array
  commands = ["telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\".\"$2)}'"]
  ## Timeout for each command to complete.
  ## Timeout for each command to complete.
  timeout = "5s"


  ## measurement name suffix (for separating different commands)
  #name_suffix = "_mycollector"
  name_override = "TelegrafVersion"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "value"
  data_type = "integer"

I'm just trying to send only the Telegraf version number out without the second period, like this:"1.11".

Error from the log:
E! [inputs.exec]: Error in plugin: strconv.Atoi: parsing "c9d8f7b0)": invalid syntax

Any idea?

@goller
Copy link
Contributor

goller commented Jun 21, 2019

Hey @raider111111 , because your data_type is integer is it trying to convert the output of your awk command to an integer.

What is the output of your command now? I suspect you have the SHA in there as well.

The resolution will likely be to change the datatype to something other than an integer.

@raider111111
Copy link
Author

Hi @goller ,
I've tried sending it as a string, float, and integer.

Here is what I see:
String:
2019-06-21T17:32:00Z E! [inputs.exec]: Error in plugin: strconv.Atoi: parsing "c9d8f7b0)": invalid syntax

Float:
2019-06-21T17:36:00Z E! [inputs.exec]: Error in plugin: strconv.ParseFloat: parsing "c9d8f7b0)": invalid syntax

@goller
Copy link
Contributor

goller commented Jun 21, 2019

Yes, I read that as telegraf is not able to parse your awk output as either a pure float or integer. Your string example looks like it is running Atoi (that'd be converting the output to an integer).

What is the output of the command line when you run it outside of telegraf?

@raider111111
Copy link
Author

1.11

@raider111111
Copy link
Author

raider111111 commented Jun 21, 2019

Well, actually it doesn't work with your edits, but I've encountered Telegraf parsing commands differently so I assumed that was probably fine.

Your edit:

telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\".\"$2)}'
awk: cmd. line:1: {print($1\".\"$2)}
awk: cmd. line:1:          ^ backslash not last character on line
awk: cmd. line:1: {print($1\".\"$2)}
awk: cmd. line:1:          ^ syntax error

Original:

telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1"."$2)}'
1.11

Do you suggest I run a different command?

@goller
Copy link
Contributor

goller commented Jun 21, 2019

yes, my edits with the escaping of " are only applicable in the telegraf TOML. Those escapes would not be needed when running from the CLI.

try this:

[[inputs.exec]]
  ## Commands array
  commands = ["sh -c \"telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\".\"$2)}'\""]
  ## Timeout for each command to complete.
  ## Timeout for each command to complete.
  timeout = "5s"


  ## measurement name suffix (for separating different commands)
  #name_suffix = "_mycollector"
  name_override = "TelegrafVersion"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "value"
  data_type = "integer"

I don't believe telegraf supports piping without it being in a single shell command.

This config gives me:

telegraf --test --config howdy.conf
2019-06-21T17:41:19Z I! Starting Telegraf 1.11.0
> TelegrafVersion,host=ip-192-168-194-137.ec2.internal value=111i 1561138879000000000

@raider111111
Copy link
Author

Sure thing!

That looks better, though I lose the period in the 1.11.

TelegrafVersion,host=ld08382.homedepot.com value="111" 1561139280000000000
Progress!

Any way to get that . back so it's 1.11?

@goller
Copy link
Contributor

goller commented Jun 21, 2019

Yup, so, we can't use an integer in this case, so, you'll need to doubly escape the period and use a string:

[[inputs.exec]]
  ## Commands array
  commands = ["sh -c \"telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\\\".\\\"$2)}'\""]
  ## Timeout for each command to complete.
  ## Timeout for each command to complete.
  timeout = "5s"


  ## measurement name suffix (for separating different commands)
  #name_suffix = "_mycollector"
  name_override = "TelegrafVersion"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "value"
  data_type = "string"
 telegraf --test --config howdy.conf
2019-06-21T17:51:58Z I! Starting Telegraf 1.11.0
> TelegrafVersion,host=ip-192-168-194-137.ec2.internal value="1.11" 1561139519000000000

@raider111111
Copy link
Author

I'm trying that out.

So, that came out correctly except that the monitoring appliance doesn't accept strings.

Wavefront allows integers and floats as input values.
Is there no way it can be a integer or a float value?

@goller
Copy link
Contributor

goller commented Jun 21, 2019

@raider111111 1.11 could be formatted as a float, yes. Try float out

@raider111111
Copy link
Author

That did it!

Adding the end result.

[[inputs.exec]]
  ## Commands array
  commands = ["sh -c \"telegraf --version | awk '{print($2)}' | awk -F '.' '{print($1\\\".\\\"$2)}'\""]
  ## Timeout for each command to complete.
  ## Timeout for each command to complete.
  timeout = "5s"


  ## measurement name suffix (for separating different commands)
  #name_suffix = "_mycollector"
  name_override = "TelegrafVersion"

  ## Data format to consume.
  ## Each data format has its own unique set of configuration options, read
  ## more about them here:
  ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
  data_format = "value"
  data_type = "float"

Thanks for your help friend!

@danielnelson
Copy link
Contributor

Keep an eye on #5958 too, I think it also will do essentially what you want.

@raider111111
Copy link
Author

@danielnelson Nice!!

@gmigiro
Copy link

gmigiro commented Oct 1, 2021

@goller I am Having similar issue but i am using python script, which runs on a file and produce the value, I have issue with the output see: [inputs.exec] Error in plugin: strconv.Atoi: parsing "forcepoint=0.04563498497009277": invalid syntax

@goller
Copy link
Contributor

goller commented Oct 2, 2021

@gmigiro probably best to open a new issue; my instinct is that you need to specify

  data_type = "float"

as @raider111111 did above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants