您好,登錄后才能下訂單哦!
1.1 導入模板
1.2 添加腳本,配置文件
#!/bin/bash sh_file=/data/sh agent_file=/usr/local/zabbix/etc/zabbix_agentd.conf.d/disk_io.conf #zabbix_bin="/usr/local/zabbix" #nohup soft install rpm -qa coreutils >> /dev/null && [ $? = 0 ] || yum -y install coreutils rpm -qa sysstat >> /dev/null && [ $? = 0 ] || yum -y install sysstat zabbix_bin=`echo ${agent_file%/*}` echo $zabbix_bin if [ ! -e "${zabbix_bin}" ];then exit 2 fi #發現腳本 if [ ! -f "${sh_file}/disk_discovery.sh" ];then cat >> ${sh_file}/disk_discovery.sh <<"EOF" #!/bin/bash diskarray=(`cat /proc/diskstats |grep -E "\bsd[a-z]\b|\bxvd[a-z]\b|\bvd[a-z]\b"|awk '{print $3}'|sort|uniq 2>/dev/null`) length=${#diskarray[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#DISK_NAME}\":\"${diskarray[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n" EOF fi #磁盤狀態監控腳本 if [ ! -f "${sh_file}/disk_status.sh" ];then cat >> ${sh_file}/disk_status.sh <<"EOF" #/bin/sh device=$1 item=$2 case $item in rrqm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $2}' ;; wrqm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $3}';; rps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b"|tail -1|awk '{print $4}' ;; wps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $5}';; rKBps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $6}' ;; wKBps) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $7}' ;; avgrq-sz) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $8}' ;; avgqu-sz) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $9}' ;; await) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $10}' ;; svctm) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $11}' ;; util) /usr/bin/tail -n20 /tmp/iostat_output |grep "\b$device\b" |tail -1|awk '{print $12}' ;; esac EOF fi #添加配置文件 if [ ! -f " ${agent_file}" ];then cat >> ${agent_file} <<"EOF" UserParameter=disk.discovery,/bin/bash ${sh_file}/discovery.sh UserParameter=disk.status[*],${sh_file}/disk_status.sh $1 $2 EOF #添加清空iostat產生的日志文件 if [ ! -f ${sh_file}/clean_output.sh ];then cat >> ${sh_file}/clean_output.sh <<"EOF" #!/bin/bash #清空/tmp/iostat_output文件,重啟進程 Num=`ps aux | grep iostat | grep -v grep |awk '{print $2}' | wc -l` file='/tmp/iostat_output' echo $Num if [ $Num -ne 1 ];then pkill iostat sleep 1 nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi Pid=`ps aux | grep iostat | grep -v grep |awk '{print $2}'` if [ $Pid -gt 1 ];then echo $Pid else nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi count=`cd /tmp/ && ls -lh|grep iostat_output|awk '{print $5}'` if [[ $count > 100K ]];then kill -9 $Pid sleep 1 \mv $file /opt rm -f /opt/iostat_output nohup /usr/bin/iostat -dxkt 1 > $file 2>/dev/null & fi EOF fi [ -e /etc/init.d/zabbix-agentd ] && /etc/init.d/zabbix-agentd reload
1.3 模板請查看附件
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。