通過shell腳本監控jvm,並將數據傳入influxDB

#!/bin/bash
#獲取pid
read -p “輸入要查詢的pid:” pid

#通過循環持續將數據寫入influxDB
while true; do

#查詢jvm數據並寫入jvm.txt文件

jstat -gcutil $pid | awk ‘NR!=1{printf “t_jvm,host=server S0=%f,S1=%f,E=%f,O=%f,M=%f,CCS=%f,YGC=%i,YGCT=%f,FGC=%i,FGCT=%f,GCT=%f\n”,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11;fflush();}’ > “/tmp/jvm.txt”;
#將數據寫入influxDB
curl -i -XPOST ‘http://localhost:8086/write?db=data_68’ --data-binary @/tmp/jvm.txt;

#每2秒執行一次
sleep 2
done

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章