Sping Cloud hystrix.stream 自动发现-监控

 

 

相关组件安装脚本

[root@java_gateway4 java_tps]# cat cront_install.sh
#!/bin/bash
yum install jq -y
mkdir /home/java_tps
touch /tmp/hystrix.data.back
chmod -R 777 /tmp/hystrix.data.back
#scp -P10036 10.81.2.46:/home/java_tps/* /home/java_tps/
cp /home/java_tps/*.conf /etc/zabbix/zabbix_agentd.d/
service zabbix-agent restart
prom1=`ps aux|grep gateway/gateway|grep -v 'auto'|awk 'END {print$2}'`
#echo $prom1
prom2=`ss -tnlp|grep $prom1|awk '{print$4}'|awk -F ':' '{print$2}'`
#echo $prom2
#for((i=1;i<=5;i++));do
# curl -s -m 1 "http://localhost:$prom2/hystrix.stream" >/tmp/hystrix.data.back
# cp /tmp/hystrix.data.back /tmp/hystrix.data
# sleep 9
# echo $i
#done
echo "* * * * * curl -s -m 1 'http://localhost:$prom2/hystrix.stream' >/tmp/hystrix.data.back">> /var/spool/cron/root

cront -l

ll /home/java_tps/*
service zabbix-agent status
ll /etc/zabbix/zabbix_agentd.d/*.conf

 

ZABBIX客户端配置文件

[root@java_gateway4 java_tps]# cat tps_mod.conf
UnsafeUserParameters=1
UserParameter=check.hystrix[*],/home/java_tps/discovery2.sh $1 $2 $3 $4 $5

数据获取文件

[root@java_gateway4 java_tps]# cat discovery2.sh
#!/bin/bash
#prom1=`ps aux|grep gateway/gateway|grep -v 'auto'|awk 'END {print$2}'`
#prom2=`ss -tnlp|grep $prom1|awk '{print$4}'|awk -F ':' '{print$2}'`
#curl -s -m 1 "http://localhost:$prom2/hystrix.stream" > /tmp/hystrix.data.back
discovery_api(){
API_NAMES=($(sed 's/data: //' /tmp/hystrix.data.back | grep -i $1 | jq -r .name 2>/dev/null | sort | uniq))
LENGTH=${#API_NAMES[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$LENGTH;i++));do
printf '\n\t\t{'
printf "\"{#API_NAME}\":\"${API_NAMES[$i]}\"}"
if [ $i -lt $[$LENGTH-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
}

get_result(){
echo $3 | grep -i -q latencyTotal

if [ $? -ne 0 ];then
result=$(grep $1 /tmp/hystrix.data.back | grep -i $2 | tail -2 | head -1 | sed 's/data: //' | jq -r .${3})
echo $result
else
result=$(grep $1 /tmp/hystrix.data.back | grep -i $2 | tail -2 | head -1 | sed 's/data: //' | jq -r .${3}[\"$4\"])
echo $result
fi
}

$1 $2 $3 $4 $5

 

模板自动发现创建

参考资料

鸡哥

 

posted on 2018-12-17 19:26  net2817  阅读(1082)  评论(0编辑  收藏  举报

导航