openfalcon-zookeeper监控 "zkmon"

代码

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

# 共享参数
endpoint="10.0.123.130"

# 获取数据
echo stat | nc 127.0.0.1 2181 > tmp.stat
echo wchs | nc 127.0.0.1 2181 > tmp.wchs
echo ruok | nc 127.0.0.1 2181 > tmp.ruok

# stat 命令的结果处理
zookeeper_stat_received=`cat tmp.stat | grep "Received:" | awk '{print $2}'`
zookeeper_stat_sent=`cat tmp.stat | grep "Sent:" | awk '{print $2}'`
zookeeper_stat_connections=`cat tmp.stat | grep "Connections:" | awk '{print $2}'`
zookeeper_stat_outstanding=`cat tmp.stat | grep "Outstanding:" | awk '{print $2}'`
zookeeper_stat_nodecount=`cat tmp.stat | grep "Node count:" | awk '{print $3}'`

# wchs 命令的结果处理
zookeeper_wchs_connections=`cat tmp.wchs | head -n1 | awk '{print $1}'`
zookeeper_wchs_watchingpaths=`cat tmp.wchs | head -n1 | awk '{print $4}'`
zookeeper_wchs_totalwatches=`cat tmp.wchs | grep 'Total watches' | awk -F\: '{print $2}'`

# ruok 命令的结果处理
zookeeper_ruok=`cat tmp.ruok | grep 'imok' | wc -l`

#echo $zookeeper_stat_received $zookeeper_stat_sent $zookeeper_stat_connections $zookeeper_stat_outstanding $zookeeper_stat_nodecount $zookeeper_wchs_connections $zookeeper_wchs_watchingpaths $zookeeper_wchs_totalwatches

# 最后删除临时文件
rm -f tmp.stat tmp.wchs tmp.ruok

# 数据上报
endpoint="10.0.123.130"
timenow=`date +%s`

function upload() {
curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://127.0.0.1:1988/v1/push -vv --data @<(cat <<EOF
[{
    "metric": "$name", "endpoint": "$endpoint", "timestamp": $timenow, "step": 60,"value": "$value", "counterType": "$type", "tags": ""
}]
EOF
)
}

name="zookeeper_stat_received"
value="$zookeeper_stat_received"
type="COUNTER"
upload

name="zookeeper_stat_sent"
value="$zookeeper_stat_sent"
type="COUNTER"
upload

name="zookeeper_stat_connections"
value="$zookeeper_stat_connections"
type="GAUGE"
upload

name="zookeeper_stat_outstanding"
value="$zookeeper_stat_outstanding"
type="COUNTER"
upload

name="zookeeper_stat_nodecount"
value="$zookeeper_stat_nodecount"
type="GAUGE"
upload

name="zookeeper_wchs_connections"
value="$zookeeper_wchs_connections"
type="GAUGE"
upload

name="zookeeper_wchs_watchingpaths"
value="$zookeeper_wchs_watchingpaths"
type="GAUGE"
upload

name="zookeeper_wchs_totalwatches"
value="$zookeeper_wchs_totalwatches"
type="GAUGE"
upload

name="zookeeper_ruok"
value="$zookeeper_ruok"
type="GAUGE"
upload

配置

  • hosntame,一般我喜欢改成ip地址

指标解释

这里写图片描述

报警设置

这里写图片描述

关键技术

curl发送带有变量的json

  • 代码
function upload() {
curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" http://127.0.0.1:1988/v1/push -vv --data @<(cat <<EOF
[{
    "metric": "$name", "endpoint": "$endpoint", "timestamp": $timenow, "step": 60,"value": "$value", "counterType": "$type", "tags": ""
}]
EOF
)
}
  • 必须带有[],要不openfalcon会decode error
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值