主要使用宏变量由客户端将要监控的主机通过宏变量传递给zabbbixserver
编辑配置文件zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=tag.cluster.ip,/opt/zabbix/script/check-tag-cluster_everyipmem discovery
UserParameter=tag.cluster.ip.mem[*],/opt/zabbix/script/check-tag-cluster_everyipmem check $1
重启服务
/opt/zabbix/script/check-tag-cluster_everyipmem
#!/bin/bash
#author: LG
TAG_CLUSTER_IP_discovery(){
TAG_CLUSTER_IP=(`cat /opt/online_deploy/hosts/tag-cluster.ip`)
first=1
printf '{\n'
printf '\t"data":[\n'
for((i=0;i<${#TAG_CLUSTER_IP[@]};i++))
{
num=$(echo $((${#TAG_CLUSTER_IP[@]}-1)))
if [ "$i" != ${num} ];then
if [ $first -eq 0 ]
then
printf "\t,\n"
fi
printf "\t{\n"
printf "\t\t\"{#TAGIP}\":\"${TAG_CLUSTER_IP[$i]}\"\n"
printf "\t}\n"
else
printf "\t,\n"
printf "\t{\n"
printf "\t\t\"{#TAGIP}\":\"${TAG_CLUSTER_IP[$num]}\"\n"
printf "\t}\n"
printf "\t]\n"
printf "}\n"
fi
first=0
}
}
check_memory(){
/usr/local/bin/redis-cli -h $1 -p 7500 info memory |grep used_memory_human | awk -F ':' '{print int($2)}'
}
case "$1" in
discovery)
TAG_CLUSTER_IP_discovery
;;
check)
check_memory $2
;;
*)
echo "Usage:$0 {tag.cluster.ip.mem[IP]}"
esac
创建discovery rules
{#TAGIP}要与客户端写的脚本中的宏变量一致
创建 ITem prototype
创建图形
自动创建10个item和graph
阅读(1194) | 评论(0) | 转发(0) |