1、磁盘发现脚本:
磁盘自动发现脚本:vim /etc/zabbix/zabbix_scripts/disk_discovery.sh
#!/bin/bash disk_array=(`grep -E "(vd[a-z]$|sd[a-z]$)" /proc/partitions | awk '{print $4}'`) length=${#disk_array[@]} printf "{ " printf ' '""data":[" for ((i=0;i<$length;i++)) do printf ' {' printf ""{#DISK_NAME}":"${disk_array[$i]}"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf " ] " printf "} "
2、磁盘监控脚本:
磁盘状态监控脚本:vim /etc/zabbix/zabbix_scripts/disk_status.sh
#!/bin/bash #UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}' //磁盘读的次数 #UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}' //磁盘读的毫秒数 #UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}' //磁盘写的次数 #UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}' //磁盘写的毫秒数 #UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}' #UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}' //花费在IO操作上的毫秒数 #UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}' //读扇区的次数(一个扇区的等于512B) #UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}' //写扇区的次数(一个扇区的等于512B) Device=$1 DISK=$2 case $DISK in rops) cat /proc/diskstats | grep $1 | head -1 | awk '{print $4}' ;; readms) cat /proc/diskstats | grep $1 | head -1 | awk '{print $7}' ;; wops) cat /proc/diskstats | grep $1 | head -1 | awk '{print $8}' ;; writems) cat /proc/diskstats | grep $1 | head -1 | awk '{print $11}' ;; ioactive) cat /proc/diskstats | grep $1 | head -1 | awk '{print $12}' ;; ioms) cat /proc/diskstats | grep $1 | head -1 | awk '{print $13}' ;; readsectors) cat /proc/diskstats | grep $1 | head -1 | awk '{print $6}' ;; writesectors) cat /proc/diskstats | grep $1 | head -1 | awk '{print $10}' ;; DiskAvaliable) df -k | head -2 | grep "$Device" | awk '{print $4}' ;; *) echo -e "e[033mUsage: sh $0 [rrqm|wrqm|rps|wps|rKBps|wKBps|avgqu-sz|avgrq-sz|await|svctm|util]e[0m" esac
3、进程发现脚本:
vim /etc/zabbix/zabbix_scripts/process_discovery.sh
#!/bin/bash File="/etc/zabbix/zabbix_scripts/search_proess_name.list" IFS=$' ' discovery () { Proess_Name_Port=($(cat $File|grep -v "^#")) printf '{ ' printf ' "data":[ ' num=${#Proess_Name_Port[@]} for site in ${Proess_Name_Port[@]} do num=$(( $num - 1 )) name=$(echo $site|awk '{print $1}') port=$(echo $site|awk '{print $2}') if [ $num -ne 0 ] ; then printf " {"{#PROCESS_NAME}":""%s"","{#PORCESS_PORT}":""${port}""}, " ${name} else printf " {"{#PROCESS_NAME}":""%s"","{#PORCESS_PORT}":""${port}""} " ${name} printf ' ] ' printf '} ' fi done } discovery
进程发现列表文件:
vim /etc/zabbix/zabbix_scripts/search_proess_name.list
## 程序名称 端口(端口也是可以使用名称代替的)
zookeeper 2181
#rocketmq 9876
#supervisord 9001
#rocketmq-console-ng 9877
#xxl-job-executor-sample-springboot 999999
#dubbo-admin-server 8099
#xxl-job-admin 8888
#bc-admin-server 999999
redis集群监控脚本:
vim /etc/zabbix/zabbix_scripts/redis-cluster.sh
#!/bin/bash REDISCLI="/usr/local/src/app/redis-5.0.5/src/redis-cli" HOST=$1 PORT=$2 if [[ $# == 3 ]];then case $3 in cluster_info) $REDISCLI -h $HOST -p $PORT -c cluster info ;; cluster_nodes) $REDISCLI -h $HOST -p $PORT -c cluster nodes ;; cluster_state) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_state" | awk -F':' '{print $2}'| grep -c ok) echo $result ;; cluster_slots_assigned) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_slots_assigned" | awk -F':' '{print $2}') echo $result ;; cluster_slots_ok) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_slots_ok" | awk -F':' '{print $2}') echo $result ;; cluster_slots_pfail) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_slots_pfail" | awk -F':' '{print $2}') echo $result ;; cluster_slots_fail) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_slots_fail" | awk -F':' '{print $2}') echo $result ;; cluster_known_nodes) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_known_nodes" | awk -F':' '{print $2}') echo $result ;; cluster_size) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_size" | awk -F':' '{print $2}') echo $result ;; cluster_current_epoch) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_current_epoch" | awk -F':' '{print $2}') echo $result ;; cluster_my_epoch) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_my_epoch" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_ping_sent) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_ping_sent" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_pong_sent) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_pong_sent" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_sent) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_sent" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_ping_received) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_ping_received" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_pong_received) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_pong_received" | awk -F':' '{print $2}') echo $result ;; cluster_stats_messages_received) result=$($REDISCLI -h $HOST -p $PORT -c cluster info | grep -w "cluster_stats_messages_received" | awk -F':' '{print $2}') echo $result ;; *) echo -e "