一.知识回顾
【0.SpringBoot专栏的相关文章都在这里哟,后续更多的文章内容可以点击查看】
【1.SpringBoot初识之Spring注解发展流程以及常用的Spring和SpringBoot注解】
【2.SpringBoot自动装配之SPI机制&SPI案例实操学习&SPI机制核心源码学习】
【3.详细学习SpringBoot自动装配原理分析之核心流程初解析-1】
【4.详细学习SpringBoot自动装配原理之自定义手写Starter案例实操实战-2】
【5.IDEA中集成SpringBoot源码环境详细步骤讲解】
【6.初识SpringBoot核心源码之SpringApplication构造器以及run方法主线流程-3】
【7.详细学习SpringBoot核心源码之SpringApplication构造器&Run方法源码详细流程-4】
【8.详细学习SpringBoot核心源码之监听器原理-5(观察者设计模式、初始化并加载监听器核心流程、事件的发布器核心流程、SpringBoot中默认的监听器以及默认的事件类型)】
【9.详细学习SpringBoot源码之自定义监听器实战演练-6(自定义监听器、自定义监听事件、指定监听事件)】
【10.详细学习SpringBoot源码之属性配置文件加载原理(application.properties|application.yaml)-7】
【11.详细学习SpringBoot源码之属性配置文件加载原理(Bootstrap.properties|Bootstrap.yml)-8】
【12.详细学习SpringBoot源码之内嵌Tomcat启动原理分析&编译部署Tomcat源码过程解析-9】
一年一度的圣诞节来啦,在此祝大家圣诞节快乐,但是作为一名合格的打工人,学习的脚步也不能停下来哦。

二.SpringBoot中的Actuator应用

2.1 Actuator基本概念
通过对SpringBoot专栏源码的学习,我们更加明白了SpringBoot为什么能够很方便快捷的构建Web应用,那么应用部署上线后的健康问题怎么发现呢?在SpringBoot中给我们提供了Actuator来解决这个问题。SpringBoot中Actuator官方手册参考地址
新创建一个项目,并且在项目中导入有关Actuator需要的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
启动项目:访问 http://localhost:8080/actuator

2.2 端点(Endpoints)
2.2.1 端点基本概念介绍
执行器端点(endpoints)可用于监控应用及与应用进行交互,Spring Boot包含很多内置的端点,你也可以添加自己的。例如,health端点提供了应用的基本健康信息。
每个端点都可以启用或禁用。这控制着端点是否被创建,并且它的bean是否存在于应用程序上下文中。要远程访问端点,还必须通过JMX或HTTP进行暴露,大部分应用选择HTTP,端点的ID映射到一个带 /actuator前缀的URL。例如,health端点默认映射到 /actuator/health。
2.2.2 配置文件中端点的相关配置
注意:Spring Boot 2.0的端点基础路径由“/”调整到”/actuator”下,如:/info调整为 /actuator/info 可以通过以下配置改为和旧版本一致:
# 设置actuator访问的路径
management.endpoints.web.base-path=/ljw
默认在只放开了 health和 info两个 Endpoint,如果要放开更多的Endpoint,我们需要配置如下信息
management.endpoints.web.exposure.include=*
现在我们看的 health信息比较少,如果我们需要看更详细的信息,可以配置如下
# health 显示详情
management.endpoint.health.show-details=always
shutdown端点默认是关闭的,我们可以打开它,shutdown只支持post方式提交,我们可以使用 postman来提交或者使用IDEA中提供的工具来提交。
# 放开 shutdown 端点
management.endpoint.shutdown.enabled=true
使用idea来进行提交测试

2.2.3 SpringBoot中提供的Endpoint端点
| ID | 描述 | 默认启用 |
|---|---|---|
| auditevents | 显示当前应用程序的审计事件信息 | Yes |
| beans | 显示一个应用中所有Spring Beans的完整列表 | Yes |
| conditions | 显示配置类和自动配置类(configuration and auto-configuration classes)的状态及它们被应用或未被应用的原因 | Yes |
| configprops | 显示一个所有 @ConfigurationProperties的集合列表 | Yes |
| env | 显示来自Spring的 ConfigurableEnvironment的属性 | Yes |
| flyway | 显示数据库迁移路径,如果有的话 | Yes |
| health | 显示应用的 健康信息(当使用一个未认证连接访问时显示一个简单的’status’,使用认证连接访问则显示全部信息详情) | Yes |
| info | 显示任意的 应用信息 | Yes |
| liquibase | 展示任何Liquibase数据库迁移路径,如果有的话 | Yes |
| metrics | 展示当前应用的 metrics`信息 | Yes |
| mappings | 显示一个所有 @RequestMapping`路径的集合列表 | Yes |
| scheduledtasks | 显示应用程序中的 计划任务` | Yes |
| sessions | 允许从Spring会话支持的会话存储中检索和删除(retrieval and deletion)用户会话。使用Spring Session对反应性Web应用程序的支持时不可用。 | Yes |
| shutdown | 允许应用以优雅的方式关闭(默认情况下不启用) | No |
| threaddump | 执行一个线程dump | Yes |
拓展补充:
如果使用web应用(Spring MVC, Spring WebFlux, 或者 Jersey),你还可以使用以下端点:
| ID | 描述 | 默认启用 |
|---|---|---|
| heapdump | 返回一个GZip压缩的 hprof堆dump文件 | Yes |
| jolokia | 通过HTTP暴露 JMX beans(当Jolokia在类路径上时,WebFlux不可用) | Yes |
| logfile | 返回 日志文件内容(如果设置了logging.file或logging.path属性的话),支持使用HTTP Range头接收日志文件内容的部分信息 | Yes |
| prometheus | 可以被Prometheus服务器抓取的格式显示 metrics信息 | Yes |
2.2.4 监听其它服务步骤
health不仅仅可以监控SpringBoot本身的状态,还可以监控其他组件的信息,比如监控Redis服务。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
添加Redis的配置信息
# Redis的 host 信息
spring.redis.host=IP地址
重启服务,访问测试查看 :http://localhost:8080/ljw/health

三.SpringBoot中Actuator监控类型

3.1 health指标
显示的系统的健康信息,上面详细的介绍了health的相关内容。
3.2 metrics指标
metrics 端点用来返回当前应用的各类重要度量指标,比如内存信息,线程信息,垃圾回收信息等。
各个指标信息的详细描述:
| 序号 | 参数 | 参数说明 | 是否监控 | 监控手段 | 重要度 |
|---|---|---|---|---|---|
| JVM | |||||
| 1 | jvm.memory.max | JVM 最大内存 | |||
| 2 | jvm.memory.committed | JVM 可用内存 | 是 | 展示并监控堆内存和Metaspace | 重要 |
| 3 | jvm.memory.used | JVM 已用内存 | 是 | 展示并监控堆内存和Metaspace | 重要 |
| 4 | jvm.buffer.memory.used | JVM 缓冲区已用内存 | |||
| 5 | jvm.buffer.count | 当前缓冲区数 | |||
| 6 | jvm.threads.daemon | JVM 守护线程数 | 是 | 显示在监控页面 | |
| 7 | jvm.threads.live | JVM 当前活跃线程数 | 是 | 显示在监控页面;监控达到阈值时报警 | 重要 |
| 8 | jvm.threads.peak | JVM 峰值线程数 | 是 | 显示在监控页面 | |
| 9 | jvm.classes.loaded | 加载classes 数 | |||
| 10 | jvm.classes.unloaded | 未加载的classes 数 | |||
| 11 | jvm.gc.memory.allocated | GC 时,年轻代分配的内存空间 | |||
| 12 | jvm.gc.memory.promoted | GC 时,老年代分配的内存空间 | |||
| 13 | jvm.gc.max.data.size | GC 时,老年代的最大内存空间 | |||
| 14 | jvm.gc.live.data.size | FullGC 时,老年代的内存空间 | |||
| 15 | jvm.gc.pause | GC 耗时 | 是 | 显示在监控页面 | |
| TOMCAT | |||||
| 16 | tomcat.sessions.created | tomcat 已创建 session 数 | |||
| 17 | tomcat.sessions.expired | tomcat 已过期 session 数 | |||
| 18 | tomcat.sessions.active.current | tomcat 活跃 session 数 | |||
| 19 | tomcat.sessions.active.max | tomcat 最多活跃 session 数 | 是 | 显示在监控页面,超过阈值可报警或者进行动态扩容 | 重要 |
| 20 | tomcat.sessions.alive.max.second | tomcat 最多活跃 session 数持续时间 | |||
| 21 | tomcat.sessions.rejected | 超过session 最大配置后,拒绝的 session 个数 | 是 | 显示在监控页面,方便分析问题 | |
| 22 | tomcat.global.error | 错误总数 | 是 | 显示在监控页面,方便分析问题 | |
| 23 | tomcat.global.sent | 发送的字节数 | |||
| 24 | tomcat.global.request.max | request 最长时间 | |||
| 25 | tomcat.global.request | 全局request 次数和时间 | |||
| 26 | tomcat.global.received | 全局received 次数和时间 | |||
| 27 | tomcat.servlet.request | servlet 的请求次数和时间 | |||
| 28 | tomcat.servlet.error | servlet 发生错误总数 | |||
| 29 | tomcat.servlet.request.max | servlet 请求最长时间 | |||
| 30 | tomcat.threads.busy | tomcat 繁忙线程 | 是 | 显示在监控页面,据此检查是否有线程夯住 | |
| 31 | tomcat.threads.current | tomcat 当前线程数(包括守护线程) | 是 | 显示在监控页面 | 重要 |
| 32 | tomcat.threads.config.max | tomcat 配置的线程最大数 | 是 | 显示在监控页面 | 重要 |
| 33 | tomcat.cache.access | tomcat 读取缓存次数 | |||
| 34 | tomcat.cache.hit | tomcat 缓存命中次数 | |||
| CPU | |||||
| 35 | system.cpu.count | CPU 数量 | |||
| 36 | system.load.average.1m | load average | 是 | 超过阈值报警 | 重要 |
| 37 | system.cpu.usage | 系统CPU 使用率 | |||
| 38 | process.cpu.usage | 当前进程CPU 使用率 | 是 | 超过阈值报警 | |
| 39 | http.server.requests | http 请求调用情况 | 是 | 显示10 个请求量最大,耗时最长的 URL;统计非 200 的请求量 | 重要 |
| 40 | process.uptime | 应用已运行时间 | 是 | 显示在监控页面 | |
| 41 | process.files.max | 允许最大句柄数 | 是 | 配合当前打开句柄数使用 | |
| 42 | process.start.time | 应用启动时间点 | 是 | 显示在监控页面 | |
| 43 | process.files.open | 当前打开句柄数 | 是 | 监控文件句柄使用率,超过阈值后报警 | 重要 |
如果要查看具体的度量信息的话,直接在访问地址后面加上度量信息即可:http://localhost:8080/ljw/metrics/度量信息的参数指标
添加自定义的统计指标
@RestController
public class UserController {
@GetMapping("/test")
public String test(){
// 1. 记录单个值 比如MQ中的消费者数量
Metrics.gauge("ljw.gauge",100);
// 2.统计当前请求执行的次数
Metrics.counter("ljw.counter","hello","hello").increment();
Metrics.timer("ljw.timer").record(()->{
// Timer 统计的业务代码的时长
try {
Thread.sleep(new Random().nextInt(999));
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// 统计命中率 ...
Metrics.summary("ljw.summary").record(0.25);
return "test";
}
}
访问测试这个请求后查看metrics 信息:http://localhost:8080/test
然后再次测试访问:http://localhost:8080/ljw/metrics/ljw.counter
还可以继续测试访问其它的是接口信息。

3.3 loggers指标
loggers是用来查看当前项目每个包的日志级别的。默认的是info级别。

修改日志级别:发送POST请求到 http://localhost:8080/ljw/loggers/[包路径]
请求参数设置为:DEBUG
{
"configuredLevel":"DEBUG"
}
通过postman来发送消息

然后再查看日志级别发现已经变动了

控制台也可以看到

3.4 info指标
显示任意的应用信息。我们可以在 properties 中来定义

访问:http://localhost:8080/ljw/info

四.定制端点

4.1 自定义Health端点
一般主流的框架组件都会提供对应的健康状态的端点,比如MySQL,Redis,Nacos等,但有时候我们自己业务系统或者自己封装的组件需要被健康检查怎么办,这时我们也可以自己来定义。先来看看 diskSpace磁盘状态。

对应的端点是 DiskSpaceHealthIndicator

有了上面的案例我们就可以自定义一个监控的健康状态的端点了。

启动服务

4.2 自定义info端点
4.2.1 info端点默认是空的
info节点默认情况下就是空的,这时我们可以通过info自定义来添加我们需要展示的信息,实现方式有两种
4.2.2 实现方式1-编写配置文件
在属性文件中配置
info.author=ljw
info.serverName=ActuatorDemo
info.versin=1.1.1
info.mavneProjectName=@project.artifactId@
重启服务

4.2.3 实现方式2-实现InfoContributor
我们可以在自定义的Java类中类实现

然后启动测试

4.3 自定义Metrics端点指标
除了使用metrics端点默认的这些统计指标外,我们还可以实现自定义统计指标,metrics提供了4中基本的度量类型:
- gauge 计量器,最简单的度量类型,只有一个简单的返回值,他用来记录一些对象或者事物的瞬时值。
- Counter 计数器 简单理解就是一种只增不减的计数器,它通常用于记录服务的请求数量,完成的任务数量,错误的发生数量
- Timer 计时器 可以同时测量一个特定的代码逻辑块的调用(执行)速度和它的时间分布。简单来说,就是在调用结束的时间点记录整个调用块执行的总时间,适用于测量短时间执行的事件的耗时分布,例如消息队列消息的消费速率。
- Summary 摘要 用于跟踪事件的分布。它类似于一个计时器,但更一般的情况是,它的大小并不一定是一段时间的测量值。在micrometer 中,对应的类是DistributionSummary,它的用法有点像Timer,但是记录的值是需要直接指定,而不是通过测量一个任务的执行时间。
测试:
@RestController
public class UserController {
@GetMapping("/test")
public String test(){
// 1. 记录单个值 比如MQ中的消费者数量
Metrics.gauge("ljw.gauge",100);
// 2.统计当前请求执行的次数
Metrics.counter("ljw.counter","hello","hello").increment();
Metrics.timer("ljw.timer").record(()->{
// Timer 统计的业务代码的时长
try {
Thread.sleep(new Random().nextInt(999));
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// 统计命中率 ...
Metrics.summary("ljw.summary").record(0.25);
return "test";
}
}

查看具体的指标信息

查看对应的tag信息

4.4自定义Endpoint端点
如果我们需要扩展Endpoint,这时我们可以自定义实现,我们可以在类的头部定义如下的注解
@Endpoint
@WebEndpoint
@ControllerEndpoint
@RestControllerEndpoint
@ServletEndpoint
再给方法添加@ReadOperation,@ WritOperation或@DeleteOperation注释后,该方法将通过JMX自动公开,并且在Web应用程序中也通过HTTP公开。
于方法的注解有以下三种,分别对应get post delete 请求
| Operation | HTTP method |
|---|---|
| @ReadOperation | GET |
| @WriteOperation | POST |
| @DeleteOperation | DELETE |
自定义Endpoint案例:

启动访问测试

写入操作:

五.SpringBoot中的Actuator两种监控方式

- http:也就是上面我们学习的方式
- jmx [Java Management Extensions] Java管理扩展
首先需要我们在配置文件中放开jmx注释
# 放开 jmx 的 endpoint
management.endpoints.jmx.exposure.include=*
spring.jmx.enabled=true
通过jdk中提供的jconsole来查看

双击打开

六.监控系统-SpringBoot Admin

6.1 SpringBoot Admin
6.2 搭建Admin服务器
创建建对应的SpringBoot项目,添加相关依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.5.1</version>
</dependency>
然后放开Admin服务即可

然后启动服务,即可访问

这个时候没有服务注册,所以是空的,这时我们可以创建对应的客户端来监控
6.3 客户端配置
使用我们上面创建的那个SpringBoot项目,并且整合Actuator后添加Admin的客户端依赖
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.5.1</version>
</dependency>
然后在属性文件中添加服务端的配置和Actuator的基本配置
server.port=8081
# 配置 SpringBoot Admin 服务端的地址
spring.boot.admin.client.url=http://localhost:8080
# Actuator的基本配置
management.endpoints.web.exposure.include=*
然后我们再刷新Admin的服务端页面

那么我们就可以在这个可视化的界面来处理操作了

6.4 服务状态
客户端服务配置—我们可以监控下MySQL的状态,先添加对应的依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
然后添加对应的jdbc配置
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mysql-base?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
然后我们在Admin中的health中就可以看到对应的数据库连接信息

注意当我把MySQL数据库关闭后,我们来看看

我们可以看到Admin中的应用墙变灰了


启动服务后,发现又正常了,然后我们修改下数据库连接的超时时间
# 数据库连接超时时间
spring.datasource.hikari.connection-timeout=2000
关闭数据库后,我们发下应用变红了


设置数据库连接超时后即可在有效的时间内发下应用的状态。
- 绿色:正常状态
- 灰色:连接客户端健康信息超时
- 红色:可以看到具体的异常信息
6.5 安全防护
其实我们可以发现在SpringBootAdmin的管理页面中我们是可以做很多的操作的,这时如果别人知道了对应的访问地址,想想是不是就觉得恐怖,所以必要的安全防护还是很有必要的,我们来看看具体应该怎么来处理呢?
由于在分布式 web 应用程序中有几种解决身份验证和授权的方法,Spring Boot Admin 没有提供默认的方法。默认情况下,spring-boot-admin-server-ui 提供了一个登录页面和一个注销按钮。
导入依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
然后添加对应的配置类
@Configuration(proxyBeanMethods = false)
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
private final AdminServerProperties adminServer;
private final SecurityProperties security;
public SecuritySecureConfig(AdminServerProperties adminServer, SecurityProperties security) {
this.adminServer = adminServer;
this.security = security;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
successHandler.setTargetUrlParameter("redirectTo");
successHandler.setDefaultTargetUrl(this.adminServer.path("/"));
http.authorizeRequests(
(authorizeRequests) -> authorizeRequests.antMatchers(this.adminServer.path("/assets/**")).permitAll()
.antMatchers(this.adminServer.path("/actuator/info")).permitAll()
.antMatchers(this.adminServer.path("/actuator/health")).permitAll()
.antMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated()
).formLogin(
(formLogin) -> formLogin.loginPage(this.adminServer.path("/login")).successHandler(successHandler).and()
).logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout"))).httpBasic(Customizer.withDefaults())
.csrf((csrf) -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.ignoringRequestMatchers(
new AntPathRequestMatcher(this.adminServer.path("/instances"),
HttpMethod.POST.toString()),
new AntPathRequestMatcher(this.adminServer.path("/instances/*"),
HttpMethod.DELETE.toString()),
new AntPathRequestMatcher(this.adminServer.path("/actuator/**"))
))
.rememberMe((rememberMe) -> rememberMe.key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600));
}
// Required to provide UserDetailsService for "remember functionality"
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser(security.getUser().getName())
.password("{noop}" + security.getUser().getPassword()).roles("USER");
}
}
然后对应的设置登录的账号密码
spring.security.user.name=user
spring.security.user.password=123456
然后访问Admin管理页面

输入账号密码后可以进入

原因是被监控的服务要连接到Admin服务端也是需要认证的

我们在客户端配置连接的账号密码即可

重启后访问Admin服务管理页面

6.6 注册中心
实际开发的时候我们可以需要涉及到的应用非常多,我们也都会把服务注册到注册中心中,比如nacos,Eureka等,接下来我们看看如何通过注册中心来集成客户端。就不需要每个客户端来集成了。

变为下面的场景

那么我们需要先启动一个注册中心服务,我们以Nacos为例

然后访问下Nacos服务

暂时还没有服务注册,我们可以注册几个服务,每个服务处理需要添加Nacos的注册中心配置外,我们还需要添加Actuator的配置
。此处我们就不做过多的演示了,我们就将admin项目给它配置nacos服务,然后启动相关的服务,可以看到相关的服务


然后我们需要配置下Admin中的nacos
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
spring.application.name=spring-boot-admin-server
spring.cloud.nacos.discovery.server-addr=IP地址:8848
spring.cloud.nacos.discovery.username=nacos
spring.cloud.nacos.discovery.password=nacos
启动服务,我们就可以看到对应的服务了

查看服务的详细监控信息

6.7 邮件通知
如果监控的服务出现了问题,下线了,我们希望通过邮箱通知的方式来告诉维护人员,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
然后配置对应的邮箱信息
# 使用的邮箱服务 qq 163等
spring.mail.host=smtp.qq.com
# 发送者
spring.mail.username=xxx@qq.com
# 授权码
spring.mail.password=查找自己的授权码
#收件人
spring.boot.admin.notify.mail.to=xxx@qq.com
#发件人
spring.boot.admin.notify.mail.from=xxx@qq.com
开启SMTP服务,发送短信开启

然后启动服务,我们关闭服务然后查看服务和邮箱信息

立刻失败

收到邮件通知

好了对应的邮箱通知就介绍到这里,其他的通知方式可以参考官方网站
七.监控系统-Prometheus+Grafana

7.1 Docker安装部署Prometheus
通过wget命令来直接下载
wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz

解压文件

进入解压目录

然后配置Prometheus

- job_name: 'Prometheus'
metrics_path: '/ljw/prometheus'
scrape_interval: 5s
static_configs:
- targets: ['192.168.10.131:8080']
labels:
instance: Prometheus
- job_name:任务名称
- metrics_path: 指标路径
- targets:实例地址/项目地址,可配置多个
- scrape_interval: 多久采集一次
- scrape_timeout: 采集超时时间
执行脚本启动应用
./prometheus --config.file=prometheus.yml

访问应用: http://ip:9090

然后在我们的SpringBoot服务中添加 Prometheus的端点,先添加必要的依赖
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

然后就会有该端点信息

如果出现如下的问题:我配置访问失败的原因是监控的服务和Java项目访问的地址不在同一个网段上,我解决的办法是我Linux服务器是云服务器,这次我在本地上重新配置一台linux服务器重新启动测试,访问成功。

重新修改配置文件
- job_name: 'Prometheus'
metrics_path: '/ljw/prometheus'
scrape_interval: 8s
static_configs:
- targets: ['192.168.10.1:8080']
labels:
instance: Prometheus
Prometheus服务器可以周期性的爬取这个endpoint来获取metrics数据,然后可以看到

7.2 Linux操作系统安装部署Grafana
可视化工具:https://grafana.com/grafana/download
通过wget命令下载
wget https://dl.grafana.com/oss/release/grafana-8.0.6-1.x86_64.rpm
sudo yum install grafana-8.0.6-1.x86_64.rpm

安装Grafana
sudo yum install grafana-8.0.6-1.x86_64.rpm

启动查看运行状态命令
sudo service grafana-server start
sudo service grafana-server status

访问的地址是 http://ip:3000 默认的帐号密码 admin/admin

登录进来后的页面

添加数据源:


添加数据源的信息步骤


网站上搜索网页,添加Dashboards https://grafana.com/grafana/dashboards 搜索SpringBoot的 Dashboards

Spring Boot Statistics

找到Dashboards的ID

然后导入即可


点击Load出现如下界面

然后就可以看到对应的监控数据了

好了,关于【详细学习SpringBoot源码-SpringBoot中的Actuator应用-数据可视化操作之SpringBootAdmin-数据可视化操作之Prometheus+Grafana安装部署-10】就先学习到这里,更多的内容持续创作学习中。

646

被折叠的 条评论
为什么被折叠?



