当前位置:网站首页>微服务系统设计——微服务监控与系统资源监控设计
微服务系统设计——微服务监控与系统资源监控设计
2022-06-27 04:11:00 【庄小焱】
摘要
各个微服务模块基本已经就位,但系统运行的情况是怎么样,有没有办法查看的到呢?本篇就带你一起看看如何查看系统运行时的一些信息。帮助开发工程师排序问题,同时也是运维工程师提供数据的监控和服务的保护。本博文将介绍的微服务的监控功能设计。
一、Actuator 插件
细心的小伙伴发现了,每个微服务的 pom 文件配置中都有如下的 jar 引用,这是 Spring Boot 提供的一系列额外特性组件以帮助你监控管理运行中的系统应用。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>除了需要引入对应 jar 包外,还需要指定的配置。由于默认只开放了 health、info 两个 API,其它 API 要正常使用,需将 exposure 配置项置为 *,才能正常使用 Actuator 暴露出来的接口。
management.endpoints.web.exposure.include=*下图是 Actuator 提供的所有对外接口,左上角四个是 Web 应用独有的。

启动任意一个应用后,在浏览器中输入网址 http://localhost:10065/actuator/ 就可以查看所有接口地址,响应信息均是以 JSON 形式输出。举例,访问 http://localhost:10065/actuator/metrics,浏览器响应信息如下:

通过访问不同的地址,就可以获取关于服务的相关信息,更多 Actuator 组件相关的文档介绍可参见 Spring Boot Actuator官方文档介绍。但插件返回的信息全部是文本信息,不够直观明了,对监控者而言需要花费不少精力才能解读背后的信息。
二、Spring Boot Admin
这里引入 Spring Boot Admin,它是一个 Web 应用,官网地址:
GitHub - codecentric/spring-boot-admin: Admin UI for administration of spring boot applications,
它是基于 Actutor,在其上做了 UI 美化,对使用者而言可用性大大提高,下面我们来直观地体验一下。



2.1 新建监控服务端
基于 Spring Boot 快速建立 parking-admin 子模块,pom.xml 中加入依赖:
<properties>
<spring.boot.admin.version>2.1.2</spring.boot.admin.version>
</properties>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>${spring.boot.admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>application.yml 配置文件:
server:
port: 10090
management:
endpoints:
web:
exposure:
include: \\*
security:
enabled: false
endpoint:
health:
show-details: ALWAYS
spring:
application:
name: parking-admin
应用主类也很简单,增加 @EnableAdminServer 注解即可:
@EnableAdminServer
@SpringBootApplication
public class BootAdminApplication {
public static void main(String[] args) {
SpringApplication.run(BootAdminApplication.class, args);
}
}启动应用后,服务端就算完工了,浏览器打开 localhost:8081 查看 Spring Boot Admin 主页面:页面一直处于 Loading 状态,直接到有被监控端应用加入进来。

2.2 添加监控端应用
直接在相应的需要监控的模块中,引入相应的 client jar 即可。(版本建议与 spring-boot-admin-starter-server 保持一致)
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>相应的 application.properties 中增加配置:
#必须暴露出来,不然admin-server无法获取health数据
management.endpoints.web.exposure.include=*
management.security.enabled=false
management.endpoint.health.show-details=ALWAYS
#admin server address
spring.boot.admin.client.url=http://localhost:10090就这么两步,其它无须做过多更改,启动主程序类,我们为资源服务为例,返回监控页面,会发现资源服务实例已经被监控到,并罗列在界面中:

点击应用实例,进入更详细的信息查看,至此通过 Spring Boot Admin 实现的应用监控已可以正常使用。监控虽然已经跨出代码开发行列,但时下 DevOps、SRE 概念的盛行,开发与运维的界线越为越模糊,合作越来越紧密,了解一些监控知识是很必要的。另外,监控微服务是任何一个微服务架构中都不可或缺的一环。但 Spring Boot Admin 仅仅只能监控应用本身的信息,应用所属的宿主机信息无法监控到,你知道有什么方法可以监控吗?
三、grafana+prometheus监控系统资源
博文参考
边栏推荐
猜你喜欢

渗透测试-文件上传/下载/包含

办公室VR黄片,骚操作!微软HoloLens之父辞职!

1.5 use of CONDA

Games101 job 7 improvement - implementation process of micro surface material

如何让 EF Core 6 支持 DateOnly 类型

2022-06-26: what does the following golang code output? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { type

2021:Graphhopper: Multi-Hop Scene Graph Reasoning for Visual Question Answering
![Promise [II. Promise source code] [detailed code comments / complete test cases]](/img/ac/abf3181fa7b3345efcc9abc046cea5.png)
Promise [II. Promise source code] [detailed code comments / complete test cases]
![[promise I] introduction of promise and key issues of hand rolling](/img/14/94bd986d3ac8a0db35c83b4234fa8a.png)
[promise I] introduction of promise and key issues of hand rolling
![[BJDCTF2020]The mystery of ip](/img/f8/c3a7334252724635d42c8db3d1bbb0.png)
[BJDCTF2020]The mystery of ip
随机推荐
Promise [II. Promise source code] [detailed code comments / complete test cases]
A^2=e | the solution of the equation | what exactly can this equation tell us
Fastdds server records - Translation-
Fplan powerplan instance
从某种意义来讲,互联网业已成为了一个孵化器,一个母体
2020:MUTANT: A Training Paradigm for Out-of-Distribution Generalizationin Visual Question Answering
Basic functions of promise [IV. promise source code]
苹果手机证书构体知识
013 C语言基础:C指针
Cultural tourism light show breaks the time and space constraints and shows the charm of night tour in the scenic spot
缓存综合项目--秒杀架构
iOS开发:对于动态库共享缓存(dyld)的了解
Penetration test - directory traversal vulnerability
MySql的开发环境
Ledrui ldr6035 usb-c interface device supports rechargeable OTG data transmission scheme.
WPF 开源控件库Extended WPF Toolkit介绍(经典)
Il manque beaucoup de fichiers et de répertoires tels que scripts pendant et après l'installation d'anaconda3
ERP demand and sales management Kingdee
办公室VR黄片,骚操作!微软HoloLens之父辞职!
如何让 EF Core 6 支持 DateOnly 类型