搭建 prometheus + grafana + springboot3 监控

news/2024/5/19 0:21:55 标签: prometheus, grafana, 监控, springboot3

下载安装包

下载prometheus:https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.windows-amd64.zip

下载grafana

https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.1.windows-amd64.zip

SpringBoot配置

我使用的是springboot3

导入依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

添加配置

# 暴露 actuator 端点
# 如果配置了拦截器,需要在拦截器中排除 /actuator/**
management:
  endpoints:
    web:
      exposure:
        include: health,info,prometheus,metrics,metrics-requiredMetricName
        exclude:
    # 自定义端点的启用和关闭
    enabled-by-default: true
  endpoint:
    health:
      show-details: ALWAYS
  # 对外暴露tag
  metrics:
    tags:
      application: 修改为你的服务名

添加配置类

@Configuration(proxyBeanMethods = false)
public class MicrometerConfig {

  @Bean
  MeterRegistryCustomizer<MeterRegistry> registryCustom(@Value("${spring.application.name}") String applicationName) {
    return registry -> registry.config().commonTags("application", applicationName);
  }

}

启动springboot服务,访问actuator接口,例如: http://localhost:8001/cloud-web-01/actuator ,接口返回值如下图所示

Prometheus配置

1、解压prometheus-2.42.0.windows-amd64.zip,修改prometheus.yml

添加如下配置,注意:除了scrape_interval可以不改之外,其他的配置项都要修改为你的微服务

  # 被监控的服务是cloud-web-01
  - job_name: 'cloud-web-01'
    scrape_interval: 15s
    # actuator/prometheus的URI
    metrics_path: '/cloud-web-01/actuator/prometheus'
    static_configs:
      # cloud-web-01的ip和端口
      - targets: ['127.0.0.1:8001']

2、双击prometheus.exe启动,访问Prometheus:http://127.0.0.1:9090/

在搜索栏输入jvm,如下图所示,能查看到cloud-web-01的jvm信息

选择jvm_buffer_count_buffers,点击Execute,即可查看jvm_buffer_count_buffers信息

如果你的微服务打印了请求日志,会看到每隔15S,Prometheus就会请求 actuator/prometheus 接口获取微服务的监控数据

grafana配置

1、解压 grafana-enterprise-9.4.1.windows-amd64.zip,双击bin目录下的grafana-server.exe,启动grafana

2、访问grafana:http://localhost:3000/login 默认账号/密码是:admin/admin

3、点击 配置按钮 -> Data sources -> Add data source

选择Prometheus数据源

HTTP URL 修改为 http://127.0.0.1:9090

点击 Save & test 

显示 Data source is working 表明添加成功

4、打开 https://grafana.com/grafana/dashboards/?plcmt=footer ,搜索 jvm

有很多JVM的监控模板供选择,我们选择 JVM (Micrometer)

点击  JVM (Micrometer) ,拷贝模板ID

回到 http://localhost:3000/ 系统,点击 Dashboards -> Import 导入模板

填写模板ID 4071,点击 Load

选择Prometheus数据源,点击Import

就可以监控cloud-web-01服务的JVM了

5、再加一个SpringBoot3的监控模板“SpringBoot APM Dashboard”。

其他的SpringBoot监控模板还未支持SpringBoot3。

模板ID是12900

显示效果

可以在 Dashboards -> Browse 中找到前面新增的Dashboards


http://www.niftyadmin.cn/n/5353582.html

相关文章

Hive(15)中使用sum() over()实现累积求和和滑动求和

目的&#xff1a; 三个常用的排序函数row_number(),rank()和dense_rank()。这三个函数需要配合开窗函数over()来实现排序功能。但over()的用法远不止于此&#xff0c;本文咱们来介绍如何实现累计求和和滑动求和。 1、数据介绍 三列数据&#xff0c;分别是员工的姓名、月份和…

qiankun子应用静态资源404问题有效解决(遇到了http请求静态文件404、css文件引用图片无法显示、svg图片转换成 base64无法显示等问题)

在&#x1f449;&#x1f3fb; qiankun微前端部署&#x1f448;&#x1f3fb;这个部署方式的前提下&#xff0c;遇到的问题并解决问题的过程 >> 问题现象 通过http请求本地的静态json文件404 css中部分引入的图片无法显示 >> 最开始的解决方式 在&#x1f449;…

Springboot 快速集成 ES

1、Springboot 官网给出的版本选择标准 2、选择版本依赖 我的 elasticsearch 服务版本为 7.17.13&#xff0c;所以 springboot 版本我选用 2.7.10 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies<…

LeetCode —— 43. 字符串相乘

&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️Take your time ! &#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️&#x1f636;‍&#x1f32b;️…

Vue3组件通信 详解(下)

Vue3组件通信 详解(上)-CSDN博客 v-model通讯 概述&#xff1a;实现 父↔子 之间相互通信。 v-model本质 组件标签上的v-model的本质&#xff1a;:moldeValue &#xff0b; update:modelValue事件。 <!-- 组件标签上使用v-model指令 --> <AtguiguInput v-model&qu…

运行VUE提示找不到模块validate-engines.js...

原来好好的&#xff0c;突然提示找不到模块validate-engines.js&#xff0c;CMD命令行输入npm -v不是内部或外部命令&#xff0c;node -v可以查看到版本号。 解决&#xff1a; 1. 卸载nodejs&#xff0c;重新下载安装文件&#xff1a;下载nodejs 2. 到目录&#xff1a;C:\Us…

JavaWeb后端登录校验功能(JWT令牌技术,Cookie技术,Session,拦截技术,过滤器)

目录 一.登录校验功能&#xff08;解决直接通过路径访问&#xff09; 1.实现思路 二.会话技术 ​编辑 1.Cookie技术 2.Session 3.令牌技术 1.简介 2.如何生成和解析 3.令牌的使用 三.Filter过滤器 1.什么是过滤器 2.实现步骤&#xff1a; 3.过滤器执行流程 4.拦截路径 5.过…

解决Linux环境下gdal报错:ERROR 4: `/xxx.hdf‘ not recognized as a supported file format.

网上查了一堆资料&#xff0c;五花八门&#xff0c;总结了一下可能的原因&#xff1a; ① gdal不支持该格式 使用命令“gdalinfo --formats” 即可查看当前环境中的gdal所能支持的数据格式。如下图&#xff08;没截完整&#xff0c;下面还有一大串&#xff09;。 这个是很常见…