To avoid an xy problem, I am trying to log/graph/alert on iperf results to several different iperf servers on our network. We have been having problems with inconsistent and slow traffic over our metro ethernet provider. If someone has a better way of going about this, I'm all ears. I am where I am now from random other guides and instructions so this is the best I have come up with.
I am trying to run iperf with telegraf in a bash script and within that script run jq to parse the data to just the average results. Here is the bash script:
#!/bin/bash
# A simple Bash script
filename='district_list_test.txt'
#echo "Start"
while read DISTRICT
do
#echo $DISTRICT
Address=$(/usr/bin/jq -r '.District_List[]."'"${DISTRICT}"'"' District_list1.json)
#echo $Address
/usr/bin/iperf3 --client ${Address} -t 5 --connect-timeout 250 --json --bidir >> $DISTRICT
download=$(/usr/bin/jq '.end.streams[0] | .sender.bits_per_second' ${DISTRICT})
upload=$(/usr/bin/jq '.end.streams[1] | .sender.bits_per_second' ${DISTRICT})
time=$(/usr/bin/jq '.start.timestamp.timesecs' ${DISTRICT})
echo "{\"District\":$DISTRICT,\"TimeStamp\":$time,\"download\":$download,\"upload\":$upload}" #>> /home/core/test_iperf_output.txt
rm $DISTRICT
done <"$filename"
district_list_test.txt will be a longer list that matches the keys in District_list1.json but for testing its just one device. district_list_test.txt:
iperf_server
District_list1.json
{
"District_List": [
{
"iperf_server": "10.115.5.5"
}
]
}
The script runs great when I run it manually and it runs in telegraf because I can see the iperfs on the server and for testing I added a file output which it makes in the telegraf config. telegraf.conf:
[[inputs.exec]]
commands=["bash /home/core/iperf_test4.sh"]
interval = "30s"
timeout = "15s"
data_format = "json"
json_query = "end"
name_override = "iPerf_testing"
[[outputs.file]]
files = ["/home/core/text.txt"]
data_format = "json"
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
data_format = "json"
token = "$INFLUX_TOKEN"
organization = "Test"
bucket = "telegraf"
user_agent = "core"
the file output file, text.txt is blank and I do not see any data in influxdb.
Running the debug for telegraf, all i see is this:
2022-05-04T15:30:41Z I! Starting Telegraf 1.22.0
2022-05-04T15:30:41Z I! Loaded inputs: exec
2022-05-04T15:30:41Z I! Loaded aggregators:
2022-05-04T15:30:41Z I! Loaded processors:
2022-05-04T15:30:41Z I! Loaded outputs: file influxdb_v2
2022-05-04T15:30:41Z I! Tags enabled: host=Iperf-Speedtest
2022-05-04T15:30:41Z I! [agent] Config: Interval:1m0s, Quiet:false, Hostname:"Iperf-Speedtest", Flush Interval:1m0s
2022-05-04T15:30:41Z D! [agent] Initializing plugins
2022-05-04T15:30:41Z D! [agent] Connecting outputs
2022-05-04T15:30:41Z D! [agent] Attempting connection to [outputs.file]
2022-05-04T15:30:41Z D! [agent] Successfully connected to outputs.file
2022-05-04T15:30:41Z D! [agent] Attempting connection to [outputs.influxdb_v2]
2022-05-04T15:30:41Z D! [agent] Successfully connected to outputs.influxdb_v2
2022-05-04T15:30:41Z D! [agent] Starting service inputs
2022-05-04T15:31:41Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:31:41Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:32:41Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:32:41Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:33:41Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:33:41Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:34:41Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2022-05-04T15:34:41Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
I can't figure out what I am missing or how to troubleshoot the issue at this point. Thanks in advance for any thoughts or suggestions and sorry for the long post.