[inputs.exec] Error in plugin: exec: exit status 1 for command

Hello,
I’d like to use the Speed Test CLI as a [[inputs.exec]] but the Telegraf logs tell me:

May 25 13:45:05 rockpro64 telegraf[4432]: 2020-05-25T13:45:05Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command ‘/usr/bin/speedtest --format json’: ==============================================================================…

My telegraf.conf has the following section:

[[inputs.exec]]
  interval = "300s"
  commands = ["/usr/bin/speedtest --format json | jq '{packetLoss: .packetLoss}'"]
  # commands = ["cat /tmp/speedtest.json"]
  timeout = "60s"
  data_format = "json"
  name_suffix = "_speedtest"

I tried running the command as telegraf and it works correctly (here I added the echo $? to double check that the result code is 0)

sudo -u telegraf /usr/bin/speedtest --format json; echo $?

I thought that the json format could the problem but if I replace the inputs.exec with a simple cat /tmp/speedtest.json of a json saved from the command ran manually, it works as expected and all the json values are published to the influxdb output

Any idea why is telegraf reporting that the command exits with a 1 status or how could I debug more?

cheers
Jan

I’m getting exact same error with same command :slight_smile: . Did you found some work around ?

Cheers!

I think this is probably due to the shell pipeline in the command, if you want to use these types of constructs you need to run the command in a shell explicitly:

commands = ['sh -c "echo foo bar=1 | cat"']

I do find it a bit easier to parse this command using the --csv flag, here is what I have been doing:

[[inputs.exec]]
  name_override = "speedtest"
  interval = "1h"
  timeout = "30s"
  commands=["speedtest --csv"]
  csv_column_names = ["server_id", "sponsor", "server_name", "timestamp", "distance", "ping", "download", "upload", "share", "ip_address"]
  csv_column_types = ["string", "string", "string", "string", "float", "float", "float", "float", "string", "string"]
  csv_timestamp_column = "timestamp"
  csv_timestamp_format = "2006-01-02T15:04:05.000000Z"
  csv_tag_columns = ["ip_address", "server_name"]
  data_format = "csv"

Hi,
sorry for the late answer. I eventually found out the it was indeed the command itself that was failing.

sudo -u telegraf /usr/bin/speedtest worked fine but not

sudo su - telegraf
/usr/bin/speedtest

The speedtest commands is looking for a file in ~/.config/ookla/speedtest-cli.json that was not present.

Now for the telegraf part, I believe it would be really helpful to see the error output in the telegraf logs when the command fails. It would have saved me quite some time.

cheers
Jan

1 Like

On more thing related to the speedtest command (and unrelated to my original question) . The json output bandwidth values are in bits per second:

{
  "download": {
    "bandwidth": 116566437,
    "bytes": 1501215368,
    "elapsed": 14607
  },
  "upload": {
    "bandwidth": 6050120,
    "bytes": 85190976,
    "elapsed": 15013
  }
}

but I wanted to have them in Mbps so I transform them json using jq

#! /bin/bash

/usr/bin/speedtest --format json | jq '.download.bandwidth = .download.bandwidth / 125000 |  .upload.bandwidth = .upload.bandwidth / 125000'

{
  "type": "result",
  "timestamp": "2020-05-25T13:55:18Z",
  "ping": {
    "jitter": 3.928,
    "latency": 25.169
  },
  "download": {
    "bandwidth": 932.531496,
    "bytes": 1501215368,
    "elapsed": 14607
  },
  "upload": {
    "bandwidth": 48.40096,
    "bytes": 85190976,
    "elapsed": 15013
  }
}

I have the above script in my speedtest.sh that I call from Telegraf:

[[inputs.exec]]
  commands = [
    "/home/rock64/speedtest.sh"
    ]

Hope it helps
Jan

I am hitting the same problem but I run the docker image of telegraf. I can manually execute the speedtest binary, but for some reason telegraf isn’t running it.

1 Like

Getting the same problem as the previous persons. I can run the whole /usr/bin/speedtest -f json-pretty from outside of my docker container using either the root or telegraf user. I’ve giving and created the correct .config folders inside of the container. It returns JSON string without issue. But if Telegraf runs this then it returns with exit code 1.

It would be nice to get more debug data on what’s been output when the error occurs.

Hello @prlombaard,
Have you tried setting debug=True in the agent portion of your telegraf config?