agent的方式接入Prometheus

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

maven repo:

https://mvnrepository.com/artifact/io.prometheus.jmx/jmx_prometheus_javaagent

在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

展示效果:

参考地址:

https://github.com/prometheus/client_java

https://github.com/prometheus/jmx_exporter

https://yunlzheng.gitbook.io/prometheus-book/part-ii-prometheus-jin-jie/exporter/custom_exporter_with_java/client_library_java

发布了212 篇原创文章 · 获赞 68 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/singgel/article/details/101120564