SpringBoot - 监控管理

监控管理

通过引入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 追踪信息

原文地址:https://www.cnblogs.com/codeDD/p/12699591.html

时间: 2024-08-01 02:37:06

SpringBoot - 监控管理的相关文章

SpringBoot监控管理之Admin监管使用

Spring Boot Admin 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI. Spring Boot Admin是一个社区项目,用于管理和监视Spring Boot®应用程序.其实说作用大也大,说不大也不大.感兴趣的同学可以了解一下.项目实战项目github: 私信: admin获取 代码很简单,了解一下就可以. 如何快速启动一个Admin服务 只需设置一个简单的启动项目(使用start.spring

SpringBoot集成监控管理

(1).添加starter依赖 1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-actuator</artifactId> 4 </dependency> (2).配置相关信息 1 info.app.id=user 2 info.app.version=1.0.0 3 #management.e

服务器远程监控管理(二)-系统安装报错0xc0000001

故障现象:新购的DELL服务器,新的光驱,新刻录的光盘.安装操作系统,报0xc0000001错误,如下图:  (这么多年的老IT竟被安装系统给绊住了,真想骂娘) 故障测试:更换光驱.光盘,反复重起安装,问题依旧. 故障处理: 1. 经和DELL厂商沟通,产生此错误的原因就是光驱或光盘原因导致读盘有问题,因而无法继续安装. 2. 厂商建议1)更换光盘光驱再试    2)采用远程管理卡(IDRAC卡)网络安装操作系统. 解决方法: 1. 对于厂商给的建议1,因为已试过多次,没有再试. 2. 采用厂商

服务器远程监控管理-硬件篇(一)

服务器故障,能够第一时间发现并处理,是每一个网管都希望能够做到的事情.相对于软件故障,服务器硬件故障更让我们担心.服务器运行超过3年以上,硬盘.内存.电脑每一个组件都会让我们心惊肉跳.尤其是硬盘,故障率高,虽然有RAID保护,但如果一块硬盘损坏未及时发现,再坏一块硬盘将会付出惨重的代价.以RAID5为例,坏一块硬盘后,剩余硬盘压力会很大,如果没有热备盘或及时更换,很容易造成下一块硬盘的损坏.笔者曾亲历过2次1块硬盘损坏未及时发现,另一块硬盘再度损坏的场景.(还好有备机和数据备份,及时还原,仍是一

针对license的监控管理报告

针对license的监控管理报告 中国企业越来越多地采用HPC 技术来应对市场的挑战,越来越短的新产品周期,不断提升的技术创新要求等.企业在高性能计算平台建设的投资中,软件的投资已经大大地超过了在硬件上的投资.大量的.昂贵的商业软件成为制约企业扩大计算规模的一个重要原因.企业 HPC 环境中涉及的商业软件包括:建立几何模型使用的CAD软件.进行工程分析前后处理的 CAE 软件.用来进行计算求解的各类求解器.进行数据管理的 PDM/PLM系统.进行工程和实验数据管理的 SDM系统等等. 近几年来,

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LicManager对不同授权license的监控管理 &nbsp;

 LicManager对不同授权license的监控管理 软件授权方式概述 目前,商用软件和共享软件绝大部份都是采用注册码授权的方式来保证软件本身不被盗用,以保证自身的利益.尽管很多常用的许多软件系统的某些版本已经被别人破解,但对于软件特殊行业而言,注册码授权的方式还是一种保护软件系统本身的一种有效的手段. 通常而言,注册码授权方式有以下几种方式: l 安装序列号方式 这是最为常用的方式,Microsoft提供的产品(例如:Windows系列产品.Office系列产品等等)都是采用这种方式.通过

Redis Sentinel(Redis集群监控管理软件)

Redis Sentinel(Redis集群监控管理软件) # Redis-Sentinel的官网地址:http://redis.io/topics/sentinel # 注意:Redis-Sentinel官网提供不是稳定版!个人感觉这个比keepalived+redis来切换好非常多. 配置环境: OS: CentOS6.1 x86  *  4 Software: redis-2.6.9 内存: 16G CPU: E5606  @ 2.13GHz *2 ------------------ I

全球顶级应用性能监控管理服务商分析

  在过去几年里,APM一改传统服务于大型企业的昂贵.复杂.耗费大量时间的IT管理部署方式,以低廉的价格.先试后买的灵活消费方式.以及不依赖专业销售和服务人员的SaaS交付模式,为各路服务商赢得了大量用户.基于此,我们对行业中几家领军企业的市场和竞争策略进行全面剖析. 在<2014年全球应用性能管理市场份额分析>一文中我们提到,新兴APM服务商在2014年的业绩表现远超传统服务商,接下来,我们看看APM业绩排行前五,占据43.4%市场份额,平均增速达到16.1%的APM企业和Newrelic等

污水处理远程监控管理

方案需求 农村污水处理已成为新农村建设的重要组成部分,农村生活污水处理设施维护巡检周期比较长,不能随时掌握各污水处理节点排放的情况的问题也随之产生:针对农村集中供排水的运营管理需求,欣仰邦以智慧服务.移动互联.智慧运营为建设目标,全面提升农村污水行业运营管控能力.决策分析能力,构建标准化运营管理体系,帮助农村供排水打造智慧运营管理模式. 技术部署 采用欣仰邦工业路由器S-IR341,为真正意义上的设备信息化提供高速传输通路:将数据传输至平台,低成本.高效率的后台数据存储技术,灵活的性能及功能可扩