SpringBoot学习之SpringBoot执行器

在以往的分布式开发当中,各个服务节点的监控必不可少。监控包含有很多方面,比如说:内存占用情况,节点是否健康等。在spring-boot会给我们提供相关资源监控叫做spring-boot-actuator通过执行器可以帮我管理和监控生产环境下的应用服务。

 一。添加SpringBoot执行器的依赖

添加gradle配置依赖:

dependencies {
    compile(‘org.springframework.boot:spring-boot-starter-actuator‘)
}

 二。关于SpringBoot的端点

端点:可用于监控应用与应用进行交互,springboot包含很多内置内置端点。tips:参考官网的

ID Description Sensitive Default

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时,我们可以访问以下节点:

ID Description Sensitive 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

有几点要补充说明一下:

  1).如果需要访问health端点,那么请在映射中访问http://xxxxx:xxxx/health.

2) 并不是所有端点都可以访问,在上述表格中如果Sensitive(是否敏感)的值如果为true,则访问会报401错误,不过好在在spring-boot配置文件中可以设置相关端点的敏感值,比如说:endpoints.env.sensitive=false

  3) 关于保护敏感端点,首先我们要添加对spring-security的依赖,并设置进行安全验证的用户名,密码以及角色,如果不使用spring-security就要慎重考虑暴露端口的端点了

  

security.user.name=xxxx
security.user.password=xxxx
management.security.role=xxxx

时间: 2024-07-30 02:19:05

SpringBoot学习之SpringBoot执行器的相关文章

SpringBoot学习(四)-->SpringBoot快速入门,开山篇

SpringBoot是伴随着Spring4.0诞生的,旨在简化开发. SpringBoot官方文档:http://spring.io/projects/spring-boot 写个示例:Hello SpringBoot 1.创建Maven工程 工程结构如下: 2.配置pom.xml文件 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchem

Springboot学习记录1--概念介绍以及环境搭建

摘要:springboot学习记录,环境搭建: 官方文档地址:https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/ 本机为Ubuntu 概念:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置.通过这种方式,Spring Boot致力于在蓬勃发展的快速

SpringBoot学习笔记(5):处理前端JSON返回的日期的格式

SpringBoot学习笔记(4):处理前端JSON返回的日期的格式 问题描述 前端页面显示的时间为毫秒格式,不利于直观显示! 解决方法1--后端解决 public class Flow { @JsonFormat(pattern = "yyyy-MM-dd", timezone="GMT+8") private Date flow_date; ..... } 解决方法2--JS处理 function crtTimeFtt(val, row) { if (val !

SpringBoot学习笔记(1):配置Mybatis

SpringBoot学习笔记(1):配置Mybatis 参考资料: 1.AndyLizh的博客 2.xiaolyuh123的博客 快速开始 添加Mybatis依赖(其他依赖已省去) <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId

Springboot学习笔记

Springboot学习笔记(一)-线程池的简化及使用 Springboot学习笔记(二)-定时任务 Springboot学习笔记(三)-常用注入组件方式 原文地址:https://www.cnblogs.com/yw0219/p/9060331.html

SpringBoot学习-SpringMVC自动配置

SpringBoot学习-SpringMVC自动配置 前言 在SpringBoot官网对于SpringMVCde 自动配置介绍 1-原文介绍如下: Spring MVC Auto-configuration Spring Boot provides auto-configuration for Spring MVC that works well with most applications. The auto-configuration adds the following features

Springboot学习05-自定义错误页面完整分析

Springboot学习06-自定义错误页面完整分析 前言 接着上一篇博客,继续分析Springboot错误页面问题 正文 1-自定义浏览器错误页面(只要将自己的错误页面放在指定的路径下即可) 1-1-Springboot错误页面匹配机制(以404错误为例): 1-在模板引擎下:找templates/error/404.html;如果没有,则继续匹配 2-在模板引擎下:找templates/error/4XX.html;如果没有,则继续匹配 3-在静态资源下:找static/error/404.

尚硅谷springboot学习14-自动配置原理

配置文件能配置哪些属性 配置文件能配置的属性参照 自动配置的原理 1).SpringBoot启动的时候加载主配置类,开启了自动配置功能 @EnableAutoConfiguration 2).@EnableAutoConfiguration 作用: 利用EnableAutoConfigurationImportSelector给容器中导入一些组件? 可以查看selectImports()方法的内容: List<String> configurations = getCandidateConfi

SpringBoot学习- 8、整合Shiro

Shiro是什么,引自百度百科:Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序. 关于Shiro网上讲的很多,以下代码是来自网上几篇博客文章的代码集成, 下面是集成步骤 1.pom.xml添加以下内容 <dependency> <groupId>org.apache.shiro</groupId> <