Error parsing python script to telegraf metric
Hi,
I'm trying to parse s mongodb python script and insert some of the script's outputs into influxDB via telegraf.
I followed the instructions in this article : https://www.linkedin.com/pulse/mongodb-status-monitoring-using-grafana-santhosh-kumar
But for some reason I can't get the python script data parsed into telegraf. I receive the following error in telegraf log:
"ERROR in input [inputs.exec]: Errors encountered: [unable to parse 'MONGODB_STATUS,host=XX.XX.XX.XX,connections=OK - 0 percent (67 of 51200 connections) used,last_flush_time=OK - Last Flush Time: 43.00ms,replset_state=OK - State: 1 (Primary),component_status=MONGO status=0': invalid field format]"
I'm using a bash script to pull the data from the python script and then run the bash script via telegraf exec input feature.
The bash script looks like this:
#!/bin/bash
host1=XX.XX.XX.XX
port=XXXXX
for i in $host1
do
status=/usr/bin/python /tmp/check_mongodb.py -H $i -u user -p passwsord -P $port -A connect | grep -i "OK - Connection took" | wc -l
if [ $status -gt 0 ]
then
connections=/usr/bin/python /tmp/check_mongodb.py -H $i -u user -p password -P $port -A connections
last_flush_time=/usr/bin/python /tmp/check_mongodb.py -H $i -u user -p password -P $port -A last_flush_time
replset_state=/usr/bin/python /tmp/check_mongodb.py -H $i -u user -p password -P $port -A replset_state
echo "MONGODB_STATUS,host=$i,connections=$connections,last_flush_time=$last_flush_time,replset_state=$replset_state,component_status=MONGO status=0"
else
echo "MONGODB_STATUS,host=$i,component_status=MONGO status=1"
fi done
The configuration in telegraf looks like this:
[[inputs.exec]] commands = ["/bin/bash /tmp/mongo_metric.sh"] timeout = "5s" name_suffix = "_mycollector" data_format = "influx"
I think I may have a problem with printing the python script output, I don't really understand the explanation in the article I've mentioned above. In the article the ask to comment the return line and add a print command which I did but it still didn't work as expected.
Telegraf agent version 1.1.2 Running on centos 6 OS.
Your script is not outputting valid influx line protocol, I would suggest reading docs on what valid line protocol looks like.
Hey.
Which script are you referring to ? Bash or Python ?