• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

spring boot整合prometheus

武飞扬头像
我要去学习了
帮助5

1.项目引入依赖

// actuator依赖提供指标
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>2.6.3</version>
</dependency>

// 将指标转换成prometheus可使用的格式
<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <version>1.8.2</version>
</dependency>

2.修改yml配置文件中添加配置

## prometheus配置
management:
  endpoint:
    metrics:
      enabled: true
    prometheus:
      prometheus: true
## 配置为开启 Actuator 服务
  endpoints:
    web:
      exposure:
        include: '*'
  metrics:
    export:
      export:
        enabled: true

3.启动项目

指标数据访问地址:ip:port/actuator/prometheus

4.配置prometheus文件

-  job_name: 'springboot-actuator-prometheus' # job name
     metrics_path: '/actuator/prometheus' # 指标获取路径
     scrape_interval: 20s # 间隔
     static_configs:
     - targets: ['ip:port'] # spring boot 服务部署的实例的地址,默认的协议是http (这里开始有问题,直接写 localhost 是访问容器内的地址,而不是宿主机的。可通过在网页上方 status -> targets 查看对应的服务情况

5.监控指标:

http_server_requests_seconds_max 请求当前消耗时间
http_server_requests_seconds_count 累积请求次数
http_server_requests_seconds_sum 累计消耗时间

tips

后面会出

  • prometheus安装部署
  • grafana安装部署、
  • prometheus整合flink
  • p grafana flink alert 指标监控预警功能

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfhifhh
系列文章
更多 icon
同类精品
更多 icon
继续加载