agent的方式接入Prometheus

275 阅读1分钟

摘自我球的docs文档,我没时间在CSDN上再写一份,见

maven repo:

mvnrepository.com/artifact/io…

在pom中引用:

<!-- https://mvnrepository.com/artifact/io.prometheus.jmx/jmx_prometheus_javaagent -->``<``dependency``>``    ``<``groupId``>io.prometheus.jmx</``groupId``>``    ``<``artifactId``>jmx_prometheus_javaagent</``artifactId``>``    ``<``version``>0.12.0</``version``>``</``dependency``>

在conf资源目录添加:

agent.yml

startDelaySeconds: 10``hostPort: localhost``:``58888``ssl: false``lowercaseOutputName: true``lowercaseOutputLabelNames: true``rules:``- pattern``: ".*"

在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

展示效果:

 

参考地址:

github.com/prometheus/…

github.com/prometheus/…

yunlzheng.gitbook.io/prometheus-…