Spring-Actuator是Spring-boot对应用监控的集成模块,提供了我们对服务器进行监控的支持,使我们更直观的获取应用程序中加载的应用配置、环境变量、自动化配置报告等。

使用Spring-Actuator

 1、引入Maven依赖

  

<!-- 监控管理模块 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

引入依赖后启动项目即可。

项目启动时会打印出我们所需的url

-- ::00.169  INFO  --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
-- ::00.169 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.170 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.170 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.171 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
-- ::00.171 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.172 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.173 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
-- ::00.173 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.173 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/pause || /pause.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
-- ::00.174 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/service-registry/instance-status],methods=[POST]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint.setStatus(java.lang.String)
-- ::00.174 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/service-registry/instance-status],methods=[GET]}" onto public org.springframework.http.ResponseEntity org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint.getStatus()
-- ::00.175 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
-- ::00.175 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
-- ::00.175 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.176 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
-- ::00.176 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/refresh || /refresh.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
-- ::00.177 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/resume || /resume.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
-- ::00.178 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.178 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/archaius || /archaius.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.179 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
-- ::00.179 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.value(java.util.Map<java.lang.String, java.lang.String>)
-- ::00.179 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/reset],methods=[POST]}" onto public java.util.Map<java.lang.String, java.lang.Object> org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.reset()
-- ::00.179 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/features || /features.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.180 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/restart || /restart.json],methods=[POST]}" onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
-- ::00.181 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/entity || /entity.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.181 INFO --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
-- ::00.193 INFO --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public java.util.Map<java.lang.String, java.lang.Object> org.springframework.boot.actuate.endpoint.mvc.ManagementErrorEndpoint.invoke()

2、yml配置文件的配置

  (1)配置端口号和不启用某功能模块

  

#制定端口号,不制定则和该服务器server.port相同
management:
port: 4321
#去掉某项不需要查看内容的功能,如不需要health
health:
mail:
#false代表不启用该功能
enabled: false

上述配置表示配置的端口为http端口为4321 并且禁用 /health功能。

  (2)修改映射路径

#修改某配置的映射id的路径
endpoints:
beans:
id: entity

上述配置表示将/beans获取应用上下文创建bean的路径改为/entity

  (3)配置Actuator安全配置

  配置安全需要借助Spring-security

  引入依赖

  

<!-- 用于注册中心访问账号认证 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

  配置账号密码:

security:
basic:
#代表开启账号密码认证
enabled: true
#配置账号和密码
user:
name: root
password: 123

 配置完账号密码后即可通过 http://127.0.0.1:4321进行访问,并且输入配置的账号和密码即可,输入一次当浏览器不关闭时都有效。

  (4)将展示报文显示为json格式

    json格式展示拥有更好的可读性和美观性 

#将acyuator显示的报文打印为json格式
spring:
jackson:
serialization:
indent-output: true

  将上述配置加至application.yml文件中即可

3、启动类配置

  

@SpringBootApplication
@EnableEurekaServer//此行注解代表为一个服务注册组件,此注解仅适用于eureka
public class EurekaServerApplication { public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}

无须做配置即可运行

4、一些主要的配置模块

HTTP请求方式 路径 描述
GET /autoconfig 用于获取应用的自动化配置信息
GET /beans 用于获取应用上下文创建的所有bean
GET /configprops     获取应用中配置的属性信息报告
GET /env   用于获取应用所有可用的环境变量属性报告
GET /mappings 用于获取所有SpringMvc的控制器映射关系报告
GET /info   用于获取应用自定义的信息

  (1) /autoconfig

    该配置下有两个主节点。

      positiveMatches :返回的是条件匹配成功的自动化配置信息

      negativeMatches :返回的是条件匹配不成功的配置信息

  (2) /beans

    该配置文件用于展示由ApplicationContext应用上下文加载的bean对象,包含以下几个节点:

    

 "context" : "bootstrap",
"parent" : null,
"beans" : [ {
"bean" : "propertySourceBootstrapConfiguration",
"aliases" : [ ],
"scope" : "singleton",
"type" : "org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration$$EnhancerBySpringCGLIB$$82fdf928",
"resource" : "null",
"dependencies" : [ ]
}]

  beans为应用上下文加载的类的集合,其包括以下几个标签:

    1)、bean : 应用上下文创建的bean的名称

    2)、scope:创建的bean的作用域

      singleton  : 单例 , 是spring默认的作用域

      prototype : 每一次请求都会产生一个新的实例 ,相当于new的操作

      request  : 每次http请求都会产生一个新的实例,当前bean只在同一个 HttpRequest中有效

      session : 同一个HttpSession中有效

    3)、type : 应用上下文管理bean的类型

       为类的全限定类名

    4)、resource : class文件的具体路径

    5)、dependencies : 依赖bean的名称 ,即bean中有关联关系bean的名称

  (3) /configprops : 获取应用中配置的属性信息报告

    其下有两个子节点

    prefix : 代表属性的配置前缀

    properties : 代表各个属性的名称和值  

  (4) /env 用于获取应用上下文的环境变量属性报告,如环境变量、JVM属性、应用的配置信息、命令行中的参数等。

    1)、server.ports 代表该应用配置的端口号

    2) 、systemProperties获取的为应用的jvm等信息

  (5) /mappings SpringMvc控制器映射的报告,

{
"{[/error]}" : {
"bean" : "requestMappingHandlerMapping",
"method" : "public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)"
}}

     1)  /error代表springMvc的映射路径

       2)  /bean 代表用于处理器映射器映射的类

       3)  /method 代表映射类中的方法

  (6)、info 用于获取application.yml中配置的自定义配置信息

5、度量指标类的配置

  度量指标提供的报告内容是动态变化的,提供了一些快照信息;如内存使用情况、Http请求次数统计、外部资源指标统计等。

  (1)、/metrics 返回当前应用的各类重要度量指标。有以下内容

    1)、系统信息: processors  ----  处理器数量

             instance.uptime  ------  运行时间

           systemload.average  --系统平均负载 等。

    2) 、 men.* : 系统内存概要信息

    3)  、 heap.*  :堆内存使用情况

    4) 、 nonheap.* : 非堆内存使用情况

    5) 、 threads.*  : 线程使用情况

    6) 、 classess.*  : 类加载和卸载情况

    7) 、  gc.*  : 垃圾收集器的详细信息

    8) 、 httpsession.*  : tomcat等容器的绘画情况

    9) 、 guage.*  : 返回一个映射数值,如延迟时间等

    10) 、 conter.*  : 作为计数器使用,记录了增加量与减少量

  (2) /health :各类健康指标

    如下述显示了内存的一些信息.

 "diskSpace" : {
"status" : "UP",
"total" : 21475880960,
"free" : 8916258816,
"threshold" : 10485760
}

  (3) /dump :用于暴露程序中的线程信息

    threadName -- 暴露的线程名称

    threadId  --暴露的线程id 等等

  (4) /trace :用于跟踪基本的http信息

6、操作控制类配置

   (1) /shutdowm 用于关闭该应用的远程操作  --为post请求

spring - boot 监控管理模块搭建的更多相关文章

  1. spring-boot-plus集成Spring Boot Admin管理和监控应用(十一)

    spring-boot-plus集成Spring Boot Admin管理和监控应用 spring boot admin Spring Boot Admin用来管理和监控Spring Boot应用程序 ...

  2. Spring Boot的每个模块包详解

    Spring Boot的每个模块包详解,具体如下: 1.spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2.spring-boot-s ...

  3. spring boot / cloud (十七) 快速搭建注册中心和配置中心

    spring boot / cloud (十七) 快速搭建注册中心和配置中心 本文将使用spring cloud的eureka和config server来搭建. 然后搭建的模式,有很多种,本文主要聊 ...

  4. Spring Boot事务管理(上)

    摘要 本文主要介绍基于Spring Boot的事务管理,尤其是@Transactional注解详细用法.首先,简要介绍Spring Boot中如何开启事务管理:其次,介绍在Spring,Spring ...

  5. Spring Boot事务管理(中)

    在上一篇 Spring Boot事务管理(上)的基础上介绍Spring Boot事务属性和事务回滚规则 . 4 Spring Boot事务属性 什么是事务属性呢?事务属性可以理解成事务的一些基本配置, ...

  6. Spring Boot事务管理(下)

    在上两篇 Spring Boot事务管理(上)和Spring Boot事务管理(中)的基础上介绍注解@Transactional. 5 @Transactional属性 属性 类型 描述 value ...

  7. Spring boot 集成 Dubbo 快速搭建

    架构: 1.ZooKeeper:服务注册中心 2.api工程:提供对外暴露的服务API 3.provider:服务提供者 4.consumer:服务消费者 示例如下: (一)新建 Maven 项目 a ...

  8. Spring Boot 日志管理

    Spring Boot 日志管理 网址 Spring Boot 日志管理 http://blog.didispace.com/springbootlog/ Spring Boot快速入门(四)--日志 ...

  9. Spring Boot + JPA 多模块项目无法注入 JpaRepository 接口

    问题描述 Spring Boot + JPA 多模块项目,启动报异常: nested exception is org.springframework.beans.factory.NoSuchBean ...

随机推荐

  1. R语言︱文本(字符串)处理与正则表达式

    处理文本是每一种计算机语言都应该具备的功能,但不是每一种语言都侧重于处理文本.R语言是统计的语言,处理文本不是它的强项,perl语言这方面的功能比R不知要强多少倍.幸运的是R语言的可扩展能力很强,DN ...

  2. 部署Java Web项目报错(二)

    在编写HighCharts折线时,并且数据源是请求CSV,运行项目时出现错误 Uncaught TypeError: Cannot read property 'prototype' of undef ...

  3. PCI设备内存操作函数总结

    1.  ExAllocatePool() 函数说明: ExAllocatePool allocates pool memory of the specified type and returns a ...

  4. VxWorks6.6 pcPentium BSP 使用说明(一):基本概念

    "VxWorks6.6 BSP 使用说明"将发布pcPentium和idp945两个系列的BSP的使用说明.每个系列约5篇文章.之后还将发布由这两个官方提供的BSP的实战移植方法. ...

  5. 芝麻HTTP:Python爬虫利器之Xpath语法与lxml库的用法

    安装 ​pip install lxml 利用 pip 安装即可 XPath语法 XPath 是一门在 XML 文档中查找信息的语言.XPath 可用来在 XML 文档中对元素和属性进行遍历.XPat ...

  6. Python与Memcached交互

    Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...

  7. Android查缺补漏(线程篇)-- AsyncTask的使用及原理详细分析

    本文作者:CodingBlock 文章链接:http://www.cnblogs.com/codingblock/p/8515304.html 一.AsyncTask的使用 AsyncTask是一种轻 ...

  8. 校园网IPv6加速

    对于广大学生来说,上网是一件很纠结的事情,校园网要么按时间计费,要么按流量计费,要么是校园宽带.按时间计费速度慢,按流量计费费用高,校园宽带还不能共享,只能电脑开热点给手机上网.有没有既能提高网速又经 ...

  9. jquery中的下拉框

    1.1select获取选中的value值 <label for="select"> <select id="key_RedemptionMode&quo ...

  10. 【BZOJ2527】MET-Meteors(整体二分)

    [BZOJ2527]MET-Meteors(整体二分) 题面 BZOJ权限题,良心洛谷链接 题解 其实我也不会做 看了zsy博客才会做... 这题如果直接爆算做显然行不通 如果只有单次询问,我们就可以 ...