当前位置: 首页 > 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://www.dtcms.com/wzjs/148445.html

相关文章:

  • 旅游电子商务网站建设费用网络广告投放网站
  • vk网站做婚介友情链接交换方式有哪些
  • 哪做网站比较好万词霸屏百度推广seo
  • 如何开网站做代销广告联盟赚钱app
  • 辛集哪做网站南宁seo咨询
  • 代做网站收费标准域名申请哪家好
  • 网站开发公司怎么做账网络营销企业网站
  • 哪些做海报比较好的网站流量平台
  • 广州化妆品网站制作定制网站开发公司
  • 做英文网站2014seo引擎优化工具
  • 行业网站联盟宣传方式
  • 英文外贸网站建设短视频seo优化
  • 怎么在wordpress建英文网站百度推广技巧方法
  • 设计素材网站会员怎么买划算四川省人民政府官网
  • c 做asp.net网站北京培训seo哪个好
  • 网站建设div设置圆角线上推广方式
  • 上海景朋建设工程有限公司网站汕头疫情最新消息
  • 郑州网站建设 天强科技代运营网店公司
  • 珊瑚绒毯移动网站建设百度搜索引擎网站
  • 万网 公司网站链接秦洁婷seo博客
  • 武汉建站排名怎么营销自己的产品
  • 做网站要分几部分完成公司网站建设北京
  • 怎么做公众号网站seo好学吗入门怎么学
  • 网站营销优化玉林seo
  • 哪个网站可以做批发新闻最新消息今天
  • 大连九死一疯事件抖音seo教程
  • 像网站分类一样的表格图怎么做网络推广方法有哪几种
  • 小游戏链接点开即玩天津seo诊断技术
  • 域名污染优化关键词排名seo软件
  • 建设网站教程全集无锡网站制作