Telegraf error in plugin exec non-root users

Hey everyone

I am trying to use mtr command and store the output to influxdb by using telegraf inputs.exec plugin in particular.

Telegraf config file:

# # Read metrics from one or more commands that can output to stdout
 [[inputs.exec]]
#   ## Commands array
   commands = ["mtr -C 8.8.8.8 -i 0.2"]
#
#   ## Timeout for each command to complete.
   timeout = "0.2s"
#
#   ## 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 = "csv"
   csv_skip_rows = 1
   csv_column_names=["","", "status","dest","hop","ip","loss","snt","","","avg","best","worst","stdev"]
   name_override = "mtr"
   csv_tag_columns = ["dest", "hop", "ip"]

Telegraf logs throw the following error:

[inputs.exec] Error in plugin: exec: exit status 1 for command 'mtr -C elastic.fmc -i 0.2': mtr: non-root users cannot request an interval < 1.0 seconds

So I tried to give telegraf all rights by changing my /etc/sudoers file for

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL

## Allow telegraf to run command with sudo rights
telegraf    ALL=(ALL)       ALL

But unfortunately the error persists.

If anyone have any ideas how to solve this issue please help :smiley:

Thanks in advance!

Hello there!

Your problem is with the mtr execution itself.

So, you have to add the sudo command to the command itself, and make sure that the sudoers is correct for the user executing this command.

Then the command will run correctly.

Thanks

Marco