欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

采集java性能指标数据

程序员文章站 2022-04-29 15:14:19
...

这里我们开发把每个服务的jvm的运行情况和gc的情况卸载java程序里,这里我们访问一个URL地址就可以得到json数据

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

post_influxdb_write='http://10.19.186.40:8086/write?db=test1'
array=(
"http://10.7.16.42:6301/metrics|zhuye_machine1|demo"
"http://10.7.16.42:6301/metrics|zhuye_machine2|demo2"
)

for data in ${array[@]}
do
    get_java_metrics=`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`
        java_metrics_data=`curl $get_java_metrics`
        v_length=${#java_metrics_data}
        if [[ v_length -gt 2  &&  ${java_metrics_data:0:1} = "{" ]]; then
                java_metrics_data1=${java_metrics_data:1:v_length-2}
                java_metrics_data2=${java_metrics_data1//:/=}
        else
                exit
        fi
        insert_sql="${insert_sql}
zgh_test_write,host=${java_host_name},app=${java_service_name} ${java_metrics_data2} ${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