Although telegraf (v1.5.2) is easy to use, it can't help you to collect all the data you need by default, such as io data. By default, it only collects the relevant data such as io time, IOPs in process, weighted io time, read, write, etc. it can't collect the iops, await, svctm, util and other data of each disk. Recently, there is such a demand. After checking the official website, telegraf can support this User defined script collects monitoring data and uploads it to infulxdb. Let's go straight to the topic
1. Write your own script to collect iops, await, svctm, util and collect iostat.sh of each disk as follows
#/bin/bash devname=(`lsblk| grep 'disk'|awk '{print $1}'`) dirname=(`lsblk| grep 'disk'|awk '{if ($7=="") print "/";else print $7}'`) #At that time, I wanted to store these directory names in dictionary format, and later changed to variable mode, shell Of[ ] { } * @ $Special characters will drive you crazy #declare -A devdict devnum=`expr ${#devname[@]} - 1` for i in `seq 0 $devnum`;do if [-z "${dirname[$i]}" ];then eval ${devname[$i]}="/" else eval ${devname[$i]}="${dirname[$i]}" fi #devdict+=([${devname[$i]}]="${dirname[$i]}") done #echo ${!devdict[*]} #echo ${devdict[*]} ioarry=`iostat -x | grep sd|awk '{print "datadir=${"$1"}@r="$4",w="$5",await="$10",svctm="$11",util="$12}'` for i in ${ioarry[@]};do eval temp="${i}" #Replace the special character @, and the space in the shell will be truncated to two elements temp=${temp/@/ } echo "exec,${temp}" #Ensure that the final output is in the following format. The first character is the measurement name. If the input.exec plug-in has the configuration name "suffix", the suffix will be added automatically #The output format is measurement name, comma, tag keys (comma separated), space, filed keys (comma separated) #The data format output mismatch will lead to the failure of telegraf to parse the data and go to the influxdb. It took a long time to debug and didn't look at the hole dug by the official website #exec,datadir=/data/data11 r=4.1,w=6.1,await=0.83,svctm=1.35,util=1.46" done
#echo ${devdict[@]}
2. Add a new plug-in for [[inputs.exec]] in the telegraf.conf file
[[inputs.exec]] ##Commands array commands = ["bash /appcom/telegraf/collect_iostat.sh",] timeout='5s' ##Suffix for measurements name_suffix="_collectiostat" data_format="influx"
3. You can telegraf --debug the result
4. After starting the telegraf, go to the influxdb to view the results