I am tring to send via telegraf.conf a shell script result to influxdb but I am not able to do that.
This is the result of the script
$:/home/monitor# ./gateway_connections.sh
[
{ “connections”: 2056, “gateway”: }
]
This is the telegraf.conf input:
[[inputs.exec]]
commands = [ “/home/monitor/gateway_connections.sh” ]
timeout = “5s”
name_override = “connect”
name_suffix = “”
data_format = “json”
tag_keys = [ “gateway” ]
This is the error running telegraf debug
[inputs.exec] Error in plugin: exec: fork/exec /home/monitor/gateway_connections.sh: exec format error for command ‘/home/monitor/gateway_connections.sh’:
I am new to this and sorry it would be simple to fix.
Your output from the gateway connections script is not valid JSON, the gateway is missing a value. I tried to further reproduce with the following: I used the following shell script:
Per this page it sounds like it may be caused due to your shebang not being the first time. In your cat output, it does look like your first line is empty. You should move the #!/bin/bash up one line.
With you support I managed to send the data to influxdb using the echo script.
It was very helpfull
The point is that my script is very complex but works locally, when tested with telegraf debug but when I check the influxdb the value of my metric is always 0.
I manage to send the data creating a .json file and using a cat command. Now I have the right data but the script runs just once.
I do not know if is there a way to ask telegraf.conf to run the script again after some time.
I am not a bash expert, does this bash script runs infinitely? What is the purpose of the sleep 10 line?
I didn’t quite understand the details of the bash script, but be aware of the difference between these two telegraf input plugins: