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

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

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

endpoint描述是否敏感
actuatorProvides a hypermedia-based “discovery page” for the other endpoints. Requires Spring HATEOAS to be on the classpath.true
auditeventsExposes audit events information for the current application.true
autoconfigDisplays an auto-configuration report showing all auto-configuration candidates and the reason why they ‘were’ or ‘were not’ applied.true
beansDisplays a complete list of all the Spring beans in your application.true
configpropsDisplays a collated list of all @ConfigurationProperties.true
dumpPerforms a thread dump.true
envExposes properties from Spring’s ConfigurableEnvironment.true
flywayShows any Flyway database migrations that have been applied.true
healthShows application health information (when the application is secure, a simple ‘status’ when accessed over an unauthenticated connection or full message details when authenticated).false
infoDisplays arbitrary application info.false
loggersShows and modifies the configuration of loggers in the application.true
liquibaseShows any Liquibase database migrations that have been applied.true
metricsShows ‘metrics’ information for the current application.true
mappingsDisplays a collated list of all @RequestMapping paths.true
shutdownAllows the application to be gracefully shutdown (not enabled by default).true
traceDisplays trace information (by default the last 100 HTTP requests).true

如果使用了Spring MVC, 还额外提供了以下的 endpoint:

IDDescriptionSensitive Default
docsDisplays documentation, including example requests and responses, for the Actuator’s endpoints. Requires spring-boot-actuator-docs to be on the classpath.false
heapdumpReturns a GZip compressed hprof heap dump file.true
jolokiaExposes JMX beans over HTTP (when Jolokia is on the classpath).true
logfileReturns 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 来监控你的服务》

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

对于 Spring Boot Admin 就简单的介绍到这,整个 MCloud 系列项目还有很多模块,后续会一一介绍。

    原文作者:Spring Boot
    原文地址: https://blog.csdn.net/github_39939645/article/details/78836738
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞