Prometheus监控Spring Cloud Gateway

news/2024/7/4 7:26:12

📚概述

API网关作为应用服务与外部交互的入口,通过对API网关的监控,可以清晰的知道应用整体的请求量,以便根据不同的并发情况进行扩容处理。
API网关的监控也是相当必要的。

通过Prometheus监控Gateway与监控普通Springboot项目几乎没有区别。基本步骤都是引入pom依赖,然后修改端点暴露metrics接口即可。

📗Gateway配置

🔖gateway服务pom配置

  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      <version>${springboot.version}</version>
  </dependency>

  <dependency>
      <groupId>io.micrometer</groupId>
      <artifactId>micrometer-registry-prometheus</artifactId>
      <version>1.9.6</version>
  </dependency>

🔊注意:
需要注意的是micrometer-registry-prometheus的版本号需要跟spring-boot-dependencies中定义的保持一致。Springboot较高版本的定义统一在micrometer-bom中,低版本的直接在spring-boot-dependencies中定义。

💡application.yml配置文件

--- # 暴露监控端点 配置
management:
  endpoints:
    # web端点配置属性
    web:
      # 默认端点前缀为/actuator,可修改
      base-path: /actuator
      exposure:
        # 包含端点,全用直接使用'*'即可,多个场景['prometheus','health']
        include: [ 'prometheus','health' ]
        # 排除端点
        exclude: [ 'shutdown' ]
    # JMX 端点配置属性
    jmx:
      exposure:
        include: [ 'prometheus' ]
        exclude: [ 'shutdown' ]
  metrics:
    tags:
      application: ${spring.application.name}
    export:
      prometheus:
        descriptions: true
        enabled: true

🔊注意:
按照实际使用情况,开放对应监控端点即可,为了保护应用安全,不使用的不开启

📙Prometheus相关配置

📃prometheus.yml配置

# consul服务发现配置
  - job_name: 'api_gatway'
    consul_sd_configs:
      - server: '10.0.107.55:8500' #consul的服务地址
        services: ["api_gateway"]
    relabel_configs:
      - source_labels: ["__meta_consul_tags"]
        regex: .*api_gateway.*
        action: keep
      - regex: __meta_consul_service_metadata_(.+)
        action: labelmap
    # 指标标签兼容,spring cloud  gateway 3.x版本前缀加了spring_cloud_
    metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'gateway(.*)'
        target_label: '__name__'
        replacement: 'spring_cloud_gateway$1'
# file_sd服务发现配置
  - job_name: 'api_gateway'
    file_sd_configs:
      - files:
        - './api_gateway_config/*.json'
        refresh_interval: 15s
    # 指标标签兼容,spring cloud  gateway 3.x版本前缀加了spring_cloud_
    metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'gateway(.*)'
        target_label: '__name__'
        replacement: 'spring_cloud_gateway$1'

🔊注意:
spring cloud gateway在不同的版本中指标名称不一致,在3.X版本中指标名称加了前缀spring_cloud_,所以在prometheus配置文件中使用metric_relabel_configs对指标进行统一处理

💡Grafana面板

官方面板:https://github.com/spring-cloud/spring-cloud-gateway/blob/main/docs/src/main/asciidoc/gateway-grafana-dashboard.json
Grafana中的面板:https://grafana.com/grafana/dashboards/11506-spring-cloud-gateway/ 编号11506

grafana官方提供的仅支持2.xgateway,对于3.xgateway存在问题。因此,我们在使用面板的时候同时兼容了2.x和3.x版本,需要根据gateway官方的面板进行自定义。
自定义面板:

image.png

🗞️指标选取

🧩监控指标选取

指标PromQL
运行状态up
近5分钟QPSsum by(instance) (rate(spring_cloud_gateway_requests_seconds_count{uri!~“.actuator.”}[5m]))
近5分钟请求失败次数sum by(instance) (increase(spring_cloud_gateway_requests_seconds_count{outcome!=“SUCCESSFUL”}[5m]))

📖参考资料

  1. gateway + prometheus + grafana - _Meditation - 博客园
  2. Springcloud gateway结合grafana简单自定义监控_kingpand的博客-CSDN博客_gateway_requests_seconds_count

http://lihuaxi.xjx100.cn/news/1023805.html

相关文章

九耶丨阁瑞钛伦特-教会你对商场顾客数据集的可视化分析!

在实际场景中&#xff0c;比如本项目的商场顾客数据集&#xff0c;只包含一批顾客的背景信息&#xff0c;但并不包含顾客的类别信息&#xff08;顾客是属于什么类别的&#xff09;。我们面对的许多真实数据集都是没有提供属性标签的&#xff0c;对于这种无标签的数据&#xff0…

0401脚手架配置代理-ajax-react

1 场景 跨域 现在很多web应用都是基于b\s架构并且实现前后端分离&#xff0c;当前端&#xff08;js&#xff09;向后端发送请求响应数据&#xff0c;但是由于浏览器的同源策略&#xff0c;会产生跨域问题。 关于同源策略和跨域问题的产生&#xff0c;可参考跨域问题及跨域解…

持续集成流水线:如何通过自动化解放你的双手?

你好&#xff0c;我是黄俊彬。 在过去的很多咨询项目中&#xff0c;我遇到了很多团队都没有很好运用持续集成流水线的实践。从团队协作的角度上来看&#xff0c;在版本发布过程中&#xff0c;经常出现测试依赖开发手工生成制品、版本发布也从开发本地出版本的问题。 而且项目…

CANoe创建仿真节点,并配合CAPL按需改变信号值

CANoe创建仿真节点,并配合CAPL按需改变信号值 写在前面 本文章只针对一路CAN进行仿真,主要目的是记录一下如何使用节点仿真搭配CAPL编程来模拟信号的发送,解决信号不断跳变的仿真场景,当然如果有多路信号需要仿真,只需要参考一路的方法,重复配置其他几路即可。 新建一个…

【自定义表格穿梭框】自定义封装jqgrid表格穿梭框,支持分页复选全选(附完整源码及效果图)

【写在前面】其实之前业务中也有这个方面的需求&#xff0c;但是总觉得自己写的有点乱&#xff0c;此时也就借这个机会重新封装一个公共的函数去实现这个穿梭框的效果&#xff0c;支持分页勾选&#xff0c;页面展示已选中和未选择的数据&#xff0c;使得系统操作更友好。 涉及知…

前端项目打包并部署

一、vue项目打包 1.1 vue项目命令行打包 在当前项目路径下&#xff0c;执行命令 npm run build 在当前项目路径下&#xff0c;生成 一个dist文件夹。 将来部署项目&#xff0c;是部署的dist这个文件。 1.2 vue ui打包项目 选中项目&#xff0c;选择build 二、部署项目 1、…

轻量级网络论文精度笔记(三):《Searching for MobileNetV3》

MobileNetV3论文链接论文名字参考文献1. 研究背景2. 创新贡献3. 相关工作3.1 高效移动端构建块4. 网格搜索5. 网络的改进5.1 重新设计计算复杂层5.2 设计Hard-Swish5.3 Large squeeze-and-excite5.4 MobileNetV3 Definitions6.仿真分析6.1 分类6.1.1 训练设置6.1.2 测量设置6.2…

Games106学习记录第一课

本文地址&#xff1a;https://blog.csdn.net/t163361/article/details/130139998 前段时间看到Games106课程&#xff0c;讲的是流水线的知识&#xff0c;比较感兴趣&#xff0c;准备跟着课程学习。 Games这个组织刚开始做公开课就混到群里了。讲的都是图形学上的东西。邀请的都…