当前位置:   article > 正文

如何做好springboot监控集成

如何做好springboot监控集成

1. 引入prometheus 到 pom.xml

  
       <!-- 作为web项目必须的依赖 -->
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-actuator</artifactId>
       </dependency>

       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-actuator-autoconfigure</artifactId>
       </dependency>

       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-security</artifactId>
       </dependency>

       <dependency>
           <groupId>io.micrometer</groupId>
           <artifactId>micrometer-registry-prometheus</artifactId>
       </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

2. 在aop切面中写一个Counter

            Counter.builder("request.times." + action).description("kkkk").
                    tag(action, method)
                    .register(meterRegistry)
                    .increment();
  • 1
  • 2
  • 3
  • 4

3. .properties配置

.properties

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=
management.endpoint.enabled=true
management.endpoint.httptrace.enabled=true
management.endpoint.shutdown.enabled=true
management.endpoint.metrics.enabled=true
management.endpoint.prometheus.enabled=true
management.endpoint.health.show-details=ALWAYS
management.enabled-by-default=true
management.metrics.export.appoptics.enabled: true
management.metrics.export.appoptics.step: 10s
management.metrics.export.appoptics.api-token: fake
# actuator的metrics接口是否需要安全保证
management.endpoints.metrics.sensitive = false
# actuator的metrics接口是否开启
management.endpoints.metrics.enabled=true
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

*.yml

spring:
  ##去除有问题的指标,因为指标名重复产生bug
  metrics:
    servo:
      enabled: false
management:
  security:
    enabled: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4. 下载相关服务

prometheus-2.17.1.windows-amd64.tar.gz
grafana-6.7.2.windows-amd64.zip

5.开启prometheus服务

5.1 根据情况补充 metrics_path 和 targets 到prometheus.yml配置中
5.2 执行 prometheus.exe

效果图

6. 启动 grafana 连接 prometheus服务

在这里插入图片描述

7.补充

7.1. 可以通过请求获取可用的资源
curl http://localhost:9090/api/v1/label/__name__/values
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/856554
推荐阅读
相关标签
  

闽ICP备14008679号