当前位置:网站首页>微服务系统设计——微服务监控与系统资源监控设计
微服务系统设计——微服务监控与系统资源监控设计
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监控系统资源
博文参考
边栏推荐
- 733. image rendering
- How to make ef core 6 support dateonly type
- 如何让 EF Core 6 支持 DateOnly 类型
- 010 C语言基础:C函数
- 013 C语言基础:C指针
- 2021:Zero-shot Visual Question Answering using Knowledge Graphs使用知识图的零次视觉问答
- Games101 job 7 improvement - implementation process of micro surface material
- 真xx相来了?测试/开发程序员为什么不愿意加班,这是个疯狂的状态......
- 2022-06-26: what does the following golang code output? A:true; B:false; C: Compilation error. package main import “fmt“ func main() { type
- windows上安装MySQL
猜你喜欢

ERP需求和销售管理 金蝶

Anaconda3安裝過程及安裝後缺失大量文件,沒有scripts等目錄

1.5 use of CONDA

真xx相来了?测试/开发程序员为什么不愿意加班,这是个疯狂的状态......

1.5 conda的使用

2021:passage retrieval for outside knowledgevisual question answering

fplan-电源规划

How to make ef core 6 support dateonly type

Quickly master asp Net authentication framework identity - reset password by mail
![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]
随机推荐
实践 DevOps 时,可能面临的六大挑战
021 C语言基础:递归,可变参数
再探Handler(下)(Handler核心原理最全解析)
面试-01
从某种意义来讲,互联网业已成为了一个孵化器,一个母体
Cache comprehensive project - seckill architecture
电商产品如何在知乎上进行推广和打广告?
面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
JMeter takes the result of the previous request as the parameter of the next request
1.5 conda的使用
QChart笔记2: 添加鼠标悬停显示
There are two problems when Nacos calls microservices: 1 Load balancer does not contain an instance for the service 2. Connection refused
fplan-Powerplan实例
跟着BUU学习Crypto(周更)
Further exploration of handler (I) (the most complete analysis of the core principle of handler)
MySql的开发环境
Anaconda3安裝過程及安裝後缺失大量文件,沒有scripts等目錄
[array]bm94 rainwater connection problem - difficult
PostgreSQL基础命令教程:创建新用户admin来访问PostgreSQL
018 C语言基础:C文件读写