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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。