摘自我球的docs文档,我没时间在CSDN上再写一份,见
maven repo:
https://mvnrepository.com/artifact/io.prometheus.jmx/jmx_prometheus_javaagent
在pom中引用:
|
在conf资源目录添加:
agent.yml
|
在shell的启动脚本添加:
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=58888
-Djava.rmi.server.hostname=localhost
-javaagent:${BASE}/lib/jmx_prometheus_javaagent-0.12.0.jar=18080:${BASE}/conf/${ENVIRONMENT}/agent.yml
在Prometheus中添加源:
- job_name: xueqiu-sms.dev #你的项目名
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /mertrics
scheme: http
static_configs:
- targets:
- 192.168.64.51:18080 #你的IP和PORT
展示效果:
参考地址:
https://github.com/prometheus/client_java