您的位置:首页 > 编程语言 > Java开发

使用 Spring Boot Admin 来监控你的服务

2017-12-18 20:22 806 查看
Spring boot 的出现,大大的简化了传统的软件开发流程,同时,软件的架构也在向微服务靠拢。而Spring 基于此,给我们提供了非常强大的基础设施 – Spring cloud 系列项目。本文将基于 Spring cloud 以及 Spring boot, 介绍怎样使用 Spring boot admin 来监控Spring cloud 提供的微服务基础设施。

当我们使用 Spring boot 进行开发之时, 它提供了一个非常有用的模块:
spring-boot-starter-actuator
, 这个模块提供了以下的 endpoint 用于监控我们的服务:

endpoint描述是否敏感
actuator
Provides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath.true
auditevents
Exposes audit events information for the current application.true
autoconfig
Displays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied.true
beans
Displays a complete list of all the Spring beans in your application.true
configprops
Displays a collated list of all
@ConfigurationProperties
.
true
dump
Performs a thread dump.true
env
Exposes properties from Spring’s
ConfigurableEnvironment
.
true
flyway
Shows any Flyway database migrations that have been applied.true
health
Shows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated).false
info
Displays arbitrary application info.false
loggers
Shows and modifies the configuration of loggers in the application.true
liquibase
Shows any Liquibase database migrations that have been applied.true
metrics
Shows ‘metrics’ information for the current application.true
mappings
Displays a collated list of all
@RequestMapping
paths.
true
shutdown
Allows the application to be gracefully shutdown (not enabled by default).true
trace
Displays trace information (by default the last 100 HTTP requests).true
如果使用了Spring MVC, 还额外提供了以下的 endpoint:

IDDescriptionSensitive Default
docs
Displays documentation, including example requests and responses, for the Actuator’s endpoints. Requires
spring-boot-actuator-docs
to be on the classpath.
false
heapdump
Returns a GZip compressed
hprof
heap dump file.
true
jolokia
Exposes JMX beans over HTTP (when Jolokia is on the classpath).true
logfile
Returns the contents of the logfile (if
logging.file
or
logging.path
properties have been set). Supports the use of the HTTP
Range
header to retrieve part of the log file’s content.
true
但是光有对应的 API 而没有界面, 这样也不便于我们查看,所以这里介绍一个开源项目: Spring Boot Admin ,它提供了对 Spring boot 的 endpoint UI 界面支持, 同时也提供了对 Spring cloud 的一些支持。

因为用到的配置项和涉及的模块有点多,所以在此就不具体介绍配置,只是简单介绍一下我们会使用到的几个服务,其他的配置项,可以自行查看源码

在本篇文章中,我们只需用到以下三个模块:

mcloud-blog 这个模块是个简单的博客系统,这里仅用作示例

mcloud-monitoring 最重要的就是这个模块,使用了 Spring Boot Admin 实现了整个服务的监控

mcloud-eureka 非常简单的一个模块,主要提供了服务注册与发现功能,用于 Spring Boot Admin 查找可用的服务

下载源码并启动上面三个模块后,访问
http://localhost:18080/monitoring/
,就可以看到最终的效果:





对于 Spring Boot Admin 就简单的介绍到这,整个 MCloud 系列项目还有很多模块,后续会一一介绍。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息