当前位置: 首页 > wzjs >正文

网站开发前期准备门户网站设计说明

网站开发前期准备,门户网站设计说明,团购网站大全做相册,如何做社群营销模式文章目录 Spring Boot Prometheus 实现应用监控(基于 Actuator 和 Micrometer)环境准备示例结构启动和验证验证 Spring Boot 应用Prometheus 抓取配置(静态方式)Grafana 面板配置总结 Spring Boot Prometheus 实现应用监控&…

文章目录

  • Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)
  • 环境准备
  • 示例结构
  • 启动和验证
  • 验证 Spring Boot 应用
  • Prometheus 抓取配置(静态方式)
  • Grafana 面板配置
  • 总结


Spring Boot + Prometheus 实现应用监控(基于 Actuator 和 Micrometer)

在微服务架构中,监控是保障系统稳定运行的关键组成部分。本文将介绍如何通过 Spring Boot 的 actuatormicrometer 组件,将应用的运行指标暴露出来,并使用 Prometheus 定时采集这些指标数据。

环境准备

  • JDK:21
  • Spring Boot:3.2.5
  • 构建工具:Maven
  • 监控工具:Prometheus 2.53.4 安装参考
  • 面板工具:Grafana v9.1.2 安装参考

示例结构

test/
├── pom.xml                                           # Maven 项目对象模型文件
├── src
│   └── main
│       ├── java
│       │   └── com
│       │       └── example
│       │           └── DemoMonitorApplication.java   # 主类(示例控制器)
│       └── resources
│           └── application.yml                       # 应用配置文件

pom.xml 文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><!-- ✅ 加入 Spring Boot 官方 parent,自动管理版本号 --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.5</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo-monitor</artifactId><version>1.0.0</version><packaging>jar</packaging><name>demo-monitor</name><properties><java.version>21</java.version></properties><dependencies><!-- Web 服务 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Actuator 监控端点 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Prometheus 指标导出 --><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency></dependencies><build><plugins><!-- Spring Boot 插件 --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
模块用途
spring-boot-starter-web提供 Web 支持
spring-boot-starter-actuator暴露监控端点(如 /actuator/health
micrometer-registry-prometheus让 Prometheus 能采集指标
spring-boot-maven-pluginMaven 构建可执行 jar 的插件

src/main/java/com/example/DemoMonitorApplication.java 内容如下:

package com.example;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoMonitorApplication {public static void main(String[] args) {SpringApplication.run(DemoMonitorApplication.class, args);}
}

src/main/resources/application.yml 内容如下:

server:port: 8080management:endpoints:web:exposure:include: "*"endpoint:health:show-details: alwaysmetrics:export:prometheus:enabled: true

说明:

  • management.endpoints.web.exposure.include: 暴露的端点,必须包含 prometheus
  • management.metrics.export.prometheus.enabled: 启用 Prometheus 导出
  • 默认 Prometheus 指标路径为 /actuator/prometheus
  • 注意:上述依赖中未显式声明版本号,是因为使用了 Spring Boot 的官方 parent

启动和验证

使用 Maven 启动项目:

./mvnw spring-boot:run

或打包后运行:

mvn clean package
java -jar target/demo-monitor-1.0.0.jar

然后就可以看到有个 8080 端口启动了


验证 Spring Boot 应用

启动应用后,访问指标接口:

http://localhost:8080/actuator/prometheus

你可以看到形如以下格式的指标输出:

在这里插入图片描述

Prometheus 抓取配置(静态方式)

Prometheus 配置示例(prometheus.yml):

scrape_configs:- job_name: 'spring-boot-app'metrics_path: '/actuator/prometheus'static_configs:- targets: ['localhost:8080']

启动 Prometheus 后,访问 http://localhost:9090 ,你就可以查询该 Spring Boot 应用的各类指标了,如:
在这里插入图片描述
在这里插入图片描述

Grafana 面板配置

表盘市场导入仪表盘:访问地址
ID:14370

在这里插入图片描述

总结

  • 依赖配置简单:通过引入 spring-boot-starter-actuatormicrometer-registry-prometheus,即可在 Spring Boot 中集成监控能力。
  • 指标暴露统一:所有 JVM、应用及自定义指标统一暴露在 /actuator/prometheus 接口上。
  • Prometheus 易于集成:通过 Prometheus 的 scrape_configs 采集配置,即可定时拉取指标数据。
  • 适用于单体与微服务架构:无论是本地部署还是容器化,Spring Boot + Prometheus 都是轻量而强大的监控方案。

若后续部署在 Kubernetes 集群中采集多实例指标。欢迎继续探讨 👇


文章转载自:

http://ahHQbebH.kxgqy.cn
http://pxmVXTTN.kxgqy.cn
http://1J4tYIYc.kxgqy.cn
http://blHva38G.kxgqy.cn
http://MtQPWOxh.kxgqy.cn
http://OxH5EB78.kxgqy.cn
http://1WajWuCN.kxgqy.cn
http://9n8fvoPL.kxgqy.cn
http://AjERPVne.kxgqy.cn
http://T8f2NopN.kxgqy.cn
http://iJQS8MSo.kxgqy.cn
http://M6PtxJAV.kxgqy.cn
http://Xl5faxJH.kxgqy.cn
http://ss1sNwrZ.kxgqy.cn
http://obe6zBoZ.kxgqy.cn
http://LxRztGEl.kxgqy.cn
http://teFcTtgq.kxgqy.cn
http://eS5OAQph.kxgqy.cn
http://CpNwL8xc.kxgqy.cn
http://Xd9GH1Wc.kxgqy.cn
http://bLDDhVrg.kxgqy.cn
http://A46LK4mL.kxgqy.cn
http://j3095ylC.kxgqy.cn
http://LqYvQzsg.kxgqy.cn
http://r10lhWcM.kxgqy.cn
http://wibL8Azu.kxgqy.cn
http://zc6CGX2z.kxgqy.cn
http://lZAzmcJq.kxgqy.cn
http://Pr20COPZ.kxgqy.cn
http://G0boxzGX.kxgqy.cn
http://www.dtcms.com/wzjs/705800.html

相关文章:

  • 万江做网站北京网络营销培训
  • 行业网站网址医疗网站建设渠道
  • wordpress入门建站教程二建筑方案设计流程步骤
  • 个人备案网站做电影站查网站是什么公司做的
  • 做网站下载那个数据库好电子商务主要学什么内容
  • 做网站设计都需要什么数码类网站名称
  • 深圳动态科技集团网站互联网建站网站
  • 广州市网站建设 骏域贵阳网络营销推广专家
  • 网站怎么没有排名做网站一定需要虚拟主机吗
  • 网站模板 自适应京东店铺购买平台
  • 成都营销型网站建设及推广那家好四川seo推广
  • 怎么随便搞个网站网址关键词查询
  • 网站应该怎么做的网页设计培训班
  • 长沙商业网站建设淄博论坛网站建设
  • 上海网站定制公司怎么免费弄网站
  • 手机网站和电脑网站样式的区别厦门找一家做网站的公司
  • 问卷调查网站怎么做自适应平台网站模板
  • 郑州高端网站建设团队阿里云服务器租用
  • 青岛网站域名备案查询镇海官方网站建设
  • 个人做流量大的网站申请注册邮箱
  • 石家庄seo网站建设互联网内容服务商
  • 广西南宁电商网站建设用静态网站更新
  • wordpress自动网站地址域名的作用
  • 烟台网站推广排名关于网站建设文章
  • 网站建设 源码无锡百度推广代理商
  • 哪个网站可以做图交易平台广州建工集团有限公司官网
  • 网站运营服务商中国建设银行官网下载中心
  • 什么样的企业需要做网站阿里云要求的网站建设方案
  • 08服务器做网站域名注册好了 怎么做网站
  • logo设计网站哪个好一些在网站加上一个模块怎么做