当前位置: 首页> 游戏> 手游 > 上海定制app开发公司_筑业网_百度推广怎么推_西安网络推广公司

上海定制app开发公司_筑业网_百度推广怎么推_西安网络推广公司

时间:2025/7/9 8:16:30来源:https://blog.csdn.net/qq_42217906/article/details/145873997 浏览次数:0次
上海定制app开发公司_筑业网_百度推广怎么推_西安网络推广公司

在 Spring Boot 2.1.3.RELEASE 中实现监控信息可视化可以通过多种方式,下面为你详细介绍使用 Spring Boot Actuator 结合 Grafana 和 Prometheus 以及使用 Spring Boot Admin 这两种常见方法。

方法一:Spring Boot Actuator + Grafana + Prometheus

1. 添加依赖

pom.xml 中添加以下依赖:

<dependencies><!-- Spring Boot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Micrometer Registry Prometheus --><dependency><groupId>io.micrometer</groupId><artifactId>micrometer-registry-prometheus</artifactId></dependency>
</dependencies>
2. 配置 Spring Boot Actuator

application.properties 中添加以下配置:

# 开启所有端点
management.endpoints.web.exposure.include=*
3. 启动 Prometheus
  • 下载 Prometheus 并解压。
  • 编辑 prometheus.yml 文件,添加对 Spring Boot 应用的监控配置:
scrape_configs:- job_name: 'spring-boot-app'metrics_path: '/actuator/prometheus'static_configs:- targets: ['localhost:8080']
  • 启动 Prometheus:在解压后的目录下执行 ./prometheus --config.file=prometheus.yml
4. 启动 Grafana
  • 下载并安装 Grafana。
  • 启动 Grafana 服务。
  • 登录 Grafana 界面(默认地址:http://localhost:3000,默认用户名和密码:admin/admin)。
  • 配置 Prometheus 作为数据源:在 Grafana 中,点击 Configuration -> Data Sources -> Add data source,选择 Prometheus,并填写 Prometheus 的地址(如 http://localhost:9090)。
  • 创建仪表盘(Dashboard):点击 Create -> Dashboard,然后添加各种图表来展示从 Prometheus 获取的监控指标。

方法二:Spring Boot Admin

1. 创建 Spring Boot Admin Server

创建一个新的 Spring Boot 项目,添加以下依赖:

<dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-server</artifactId><version>2.1.6</version></dependency>
</dependencies>

application.properties 中添加以下配置:

server.port=8080

在主应用类上添加 @EnableAdminServer 注解:

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@EnableAdminServer
public class AdminVisualServerApplication {public static void main(String[] args) {SpringApplication.run(AdminVisualServerApplication.class, args);}
}
2. 将 Spring Boot 应用注册到 Admin Server

新创建一个服务,在需要监控的 Spring Boot 应用中添加以下依赖:

<dependencies><dependency><groupId>de.codecentric</groupId><artifactId>spring-boot-admin-starter-client</artifactId><version>2.1.6</version></dependency>
</dependencies>

application.properties 中添加以下配置:

server.port=8081
spring.boot.admin.client.url=http://localhost:8080
management.endpoints.web.exposure.include=*

创建启动类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class AdminVisualClientApplication {public static void main(String[] args) {SpringApplication.run(AdminVisualClientApplication.class, args);}
}
3. 访问 Spring Boot Admin 界面

启动 Spring Boot Admin Server 和需要被监控的应用,访问 http://localhost:8080 即可看到监控信息的可视化界面。

在这里插入图片描述
在这里插入图片描述

注意事项

  • 确保各组件的版本兼容性,避免因版本不匹配导致的问题。
  • 可以根据实际需求对监控指标和可视化界面进行进一步的定制和优化。
关键字:上海定制app开发公司_筑业网_百度推广怎么推_西安网络推广公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: