脚本采集数据插入到influxdb数据库里

#!/bin/bash
# 定时收集java服务metrics
# curl http://10.7.16.42:6301/metrics  demo
# 参数:

post_influxdb_write='http://10.19.186.40:8086/write?db=livedb'
array=(
"job|server1|job-server"
"projectservice-server|server1|projectservice-server"
"accountservice-server|server1|accountservice-server"
"accountservice-listener|server1|accountservice-listener"
"loanservice-listener|server1|loanservice-listener"
"tradeservice-listener|server1|tradeservice-listener"
"messageservice-server|server1|messageservice-server"
"tradeservice-server|server1|tradeservice-server"
"loanservice-server|server1|loanservice-server"
"jxbankservice-server|server1|jxbankservice-server"
)

for data in ${array[@]}  
do  
    process_name=`echo $data |awk -F"|" '{print $1}'` 
    java_host_name=`echo $data |awk -F"|" '{print $2}'`
    java_service_name=`echo $data |awk -F"|" '{print $3}'`
    currentTime=`date "+%Y-%m-%d %H:%M:%S"` 
    currentTimeStamp=`date -d "$currentTime" +%s`
    process=`ps aux | grep spring.profiles.active=live | grep -i APPID=$process_name | wc -l`
    insert_sql="${insert_sql}
java_service_monitor,rack=${java_host_name},service_name=${java_service_name} value=${process} ${currentTimeStamp}000000000"
done  

#echo "$insert_sql"
echo "insert data"
curl -i -X POST "$post_influxdb_write" --data-binary "$insert_sql"

#echo "querying data"
#curl -G http://localhost:8086/query  --data-urlencode "q=SELECT * FROM test1..zgh_test_write limit 2"

exit

 以上是检查服务的存活状态。然后结合定时任务写到influxdb里

posted @ 2017-07-19 17:08  BigBao的博客  阅读(1998)  评论(1编辑  收藏  举报