springboot-监控管理

codedd      2022-05-06     637

关键词:

监控管理

通过引入spring-boot-starter-actuator,可以使用SpringBoot提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP,JMX,SSH协议来进行操作,自动得到审计、健康等指标信息

SpringBoot整合监控管理

步骤

  1. 引入spring-boot-starter-actuator
  2. 开启访问端点
  3. 通过http方式访问监控端点
  4. 可以进行shutdown远程关闭(POST提交,此端点默认关闭)

测试运行

启动项目,先不进行配置,浏览器访问http://localhost:8080/actuator

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        "health-component": {
            "href": "http://localhost:8080/actuator/health/{component}",
            "templated": true
        },
        "health-component-instance": {
            "href": "http://localhost:8080/actuator/health/{component}/{instance}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:8080/actuator/info",
            "templated": false
        }
    }
}

可以看出,默认只暴露了health和info两个端点

application.properties中添加配置

springboot 2.x版本配置暴露所有端点,http访问时默认需要加上/actuator前缀

management.endpoints.web.exposure.include=*

再次访问http://localhost:8080/actuator

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/actuator",
            "templated": false
        },
        "auditevents": {
            "href": "http://localhost:8080/actuator/auditevents",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:8080/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:8080/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://localhost:8080/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8080/actuator/health",
            "templated": false
        },
        "health-component-instance": {
            "href": "http://localhost:8080/actuator/health/{component}/{instance}",
            "templated": true
        },
        "health-component": {
            "href": "http://localhost:8080/actuator/health/{component}",
            "templated": true
        },
        "conditions": {
            "href": "http://localhost:8080/actuator/conditions",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:8080/actuator/configprops",
            "templated": false
        },
        "env": {
            "href": "http://localhost:8080/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:8080/actuator/env/{toMatch}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:8080/actuator/info",
            "templated": false
        },
        "loggers": {
            "href": "http://localhost:8080/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://localhost:8080/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://localhost:8080/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:8080/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8080/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8080/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:8080/actuator/scheduledtasks",
            "templated": false
        },
        "httptrace": {
            "href": "http://localhost:8080/actuator/httptrace",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:8080/actuator/mappings",
            "templated": false
        }
    }
}

显示了所有端点

修改默认根路径

management.endpoints.web.base-path=/

浏览器访问http://localhost:8080/health,显示如下

{
    "status": "UP"
}

health端点默认只显示"status":"UP",配置显示详细信息

management.endpoint.health.show-details=always

再次访问http://localhost:8080/health,显示如下

{
    "status": "UP",
    "details": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 64424505344,
                "free": 8456863744,
                "threshold": 10485760
            }
        }
    }
}

设置启用单个端点(/shutdown)

开启shutdown端点,可远程关闭应用,注意访问时需要post提交,除shutdown外其他端点默认启用

management.endpoint.shutdown.enabled=true

配置http访问端点的端口,如果改成-1会关闭所有端点

management.server.port=8081

现在需要访问http://localhost:8081/health才会显示端点信息

设置不暴露某个端点

management.endpoint.web.exposure.exclude=端点名

自定义健康健康状态指示器

  1. 编写一个指示器,实现HealthIndicator接口
  2. 指示器的名字是xxxHealthIndicator
  3. 加入容器中
@Component
public class MyAppHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        return Health.down().withDetail("msg","服务异常").build();
    }
}

再次访问http://localhost:8081/health

{
    "status": "DOWN",
    "details": {
        "myApp": {
            "status": "DOWN",
            "details": {
                "msg": "服务异常"
            }
        },
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 64424505344,
                "free": 8456863744,
                "threshold": 10485760
            }
        }
    }
}

health端点status变成了DOWN,也多了myApp的提示信息

端点详细信息

端点名 描述
autoconfig 所有自动配置信息
auditevents 审计事件
beans 所有Bean的信息
configprops 所有配置属性
dump 线程状态信息
env 当前环境信息
health 应用健康状况
info 当前应用信息
metrics 应用的各项指标
mappings 应用@RequestMapping映射路径
shutdown 关闭当前应用(默认不启用)
trace 追踪信息

springboot(21)——监控和管理接口(代码片段)

SpringBoot提供的监控和管理接口SpringBoot提供了收集一些系统信息和对系统进行管理的功能,并会把它们以JMX或Http的方式发布出来,用户可以把它们集成到自己的监控系统。需要使用这些功能时需要添加如下依赖。<dependency><... 查看详情

笔记:springboot监控与管理

...集信息,而这些接口往往有很大一部分指标都是类似的,SpringBoot作为微服务框架时,除了强大的快速开 查看详情

springboot2.0之监控管理

Springboot监控中心: 针对微服务的服务状态,服务器的内存变化(内存、线程、日志管理等)检测服务配置连接地址是否有用(有些懒加载的情况下,用的时候发现卧槽不能用)模拟访问,懒加载。统计有多少个bean(Spring容器... 查看详情

springboot监控管理之admin监管使用

SpringBootAdmin用于监控基于SpringBoot的应用,它是在SpringBootActuator的基础上提供简洁的可视化WEBUI。SpringBootAdmin是一个社区项目,用于管理和监视SpringBoot®应用程序。其实说作用大也大,说不大也不大。感兴趣的同学可以了解一下... 查看详情

springboot集成监控管理

(1)、添加starter依赖1<dependency>2<groupId>org.springframework.boot</groupId>3<artifactId>spring-boot-starter-actuator</artifactId>4</dependency>(2)、配置相关信息1info.app.id=u 查看详情

springboot整合actuator实现监控管理(代码片段)

SpringBoot使用actuator监控管理  1.在pom文件中导入相关的依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>  查看详情

重学springboot系列应用程序监控管理(代码片段)

重学SpringBoot系列应用程序监控管理Actuator应用监控快速入门SpringBootActuator简介Actuator开启与配置开启监控默认开放访问的监控端点开放端点配置(exposure)开启端点配置(enabled)常用监控端点说明Actuator服务保护缓... 查看详情

springboot与检索任务安全分布式热部署监控管理(代码片段)

SpringBoot与检索、任务、安全、分布式、热部署、监控管理一、检索概念整合ElasticSearch测试二、任务异步任务定时任务邮件任务三、安全Web&安全四、分布式各类应用架构特点单一应用架构垂直应用架构分布式服务架构流动计... 查看详情

Spring Boot 微服务监控与管理

】SpringBoot微服务监控与管理【英文标题】:SpringBootMicroservicesMonitoring&Management【发布时间】:2019-08-0214:09:48【问题描述】:我们正计划为我们的应用程序构建一个基于微服务的分布式架构。我们也对几个概念进行了PoC。但是... 查看详情

springboot2.0actuator的健康检查

参考技术A在当下流行的ServiceMesh架构中,由于Springboot框架的种种优点,它特别适合作为其中的应用开发框架。说到ServiceMesh的微服务架构,主要特点是将服务开发和服务治理分离开来,然后再结合容器化的Paas平台,将它们融合... 查看详情

springboot-actuator应用后台监控

一前言springboot额外的特色是提供了后台应用监控,可以通过HTTP或者JMX的方式管理监控应用,本文主讲HTTP方式;其主要的功能是监控应用的健康状态,查看环境变量等;二pom.xmlspringboot2.1.1,主要引入actuator依赖,web依赖用于测试... 查看详情

springboot情操陶冶-jmx解析

承接前文springboot情操陶冶[email protected]注解解析,近期笔者接触的项目中有使用到了jmx的协议框架,遂在前文的基础上讲解下springboot中是如何整合jmx的知识储备JMX:JavaManagementExtension(Java管理应用扩展),这种机制可以方便的... 查看详情

springboot2---指标监控(代码片段)

指标监控1、SpringBootActuator1、简介2、1.x与2.x的不同3、如何使用2、ActuatorEndpoint1、最常使用的端点最常用的Endpoint2、HealthEndpoint3、MetricsEndpoint4、管理Endpoints1、开启与禁用Endpoints2、暴露Endpoints(监控端点)定制Endpoint1、定制一个组件... 查看详情

springboot监控-springbootadmin(代码片段)

01:SpringBoot高级–SpringBoot监控02:SpringBoot监控-SpringBootAdmin1.SpringBootAdmin使用游览器地址栏访问SpringBoot的监控信息太繁琐了,所以SpringBootAdmin就诞生了,以UI界面的方式来显示监控信息。SpringBootAdmin说明:SpringBootAdmi... 查看详情

springboot中加入druid对sql进行监控

springboot作为现在十分流行的框架,简化Spring应用的初始搭建以及开发过程,现在我们就使用springboot来进行简单的web项目搭建并对项目sql进行监控。项目的搭建就省略了,springboot项目搭建好以后,进行一下操作,本例子的项目使用mav... 查看详情

springboot添加应用jvm监控,实现数据可视化,深入浅出全是精华(代码片段)

...监控都太重要了。本文介绍Prometheus+Grafana的方法监控Springboot2.X,实现美观漂亮的数据可视化。2.添加监控Spring-boot-actuatormodule可帮助您在将应用程序投入生产时监视和管理应用程序。您可以选择使用HTTP端点或JMX来管理和监... 查看详情

springboot自动配置原理源码分析+自定义starter启动器+可视化监控+mybatisplus使用(代码片段)

一、springBoot自动化配置原理1.starter管理机制通过依赖了解SpringBoot管理了哪些starter通过依赖spring-boot-dependencies搜索starter-发现非常多的官方starter,并且已经帮助我们管理好了版本。项目中使用直接引入对应的starter即可,... 查看详情

springbootadmin,贼好使!

来源|Java中文社群(ID:javacn666)SpringBootAdmin(SBA)是一个开源的社区项目,用于管理和监控SpringBoot应用程序。应用程序可以通过http的方式,或SpringCloud服务发现机制注册到SBA中,然后就可以实现对... 查看详情