脚本采集数据插入到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="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

 

posted @ 2019-06-03 18:17  侃豺小哥  阅读(1497)  评论(0编辑  收藏  举报