您好,登錄后才能下訂單哦!
1.1 導(dǎo)入模板
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 #發(fā)現(xiàn)腳本 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 #磁盤狀態(tài)監(jiān)控腳本 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產(chǎn)生的日志文件 if [ ! -f ${sh_file}/clean_output.sh ];then cat >> ${sh_file}/clean_output.sh <<"EOF" #!/bin/bash #清空/tmp/iostat_output文件,重啟進(jìn)程 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 模板請(qǐng)查看附件
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。