zoukankan      html  css  js  c++  java
  • Spring Boot集成Actuator

    一、Spring-Boot-Actuator简介

    官网:https://docs.spring.io/spring-boot/docs/2.3.4.BUILD-SNAPSHOT/reference/html/production-ready-features.html#production-ready

    Spring-Boot-Actuator是Spring Boot 中的一个模块,当应用集成了此模块之后,应用会多出很多可以使用http访问的端点(endpoint),通过访问这些endpoint可以监控和管理Spring-Boot应用。

    端点(endpoint)可以粗略的理解为一个固定的url,例如,当Spring Boot应用集成了Spring-Boot-Actustor之后,访问http://localhost:8083/actuator/health 就可以监控到应用的健康状态。

    二、集成

    • 1:pom文件中增加相关依赖
    
    <!-- actuator    -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    
    
    • 2:启动应用,访问http://localhost:8083/actuator 返回了一个json的字符串,其中_links下面列出了当前所有可以监控的指标,health是健康状态,info是基本信息,若没有在配置文件中配置info.build,info看到的应该是空json字符串。

    • 3:Spring-Boot-Actuator相关配置文件概述

    Actusator的大部分配置是围绕management.endpoints这个配置节点展开的,旗下有web;jmx。
    通过web.include=* 可以打开web这类别下面所有的endpoint;通过web.exclude=env可以关闭web类别下面env的endpoint,当然web.exclude=*就是关闭web下面所有的endpoint。

    三、通过访问Actuator提供的endpoint来监控应用

    • 1:配置文件修改为
    
    spring.application.name=order-service
    server.port=8083
    
    #json格式化输出
    spring.jackson.serialization.indent_output=true
    
    
    #配置info信息
    info.build.artifact=@project.artifactId@
    info.build.name=@project.name@
    info.build.description=@project.description@
    info.build.version=@project.version@
    
    
    #暴露web下所有的端点
    management.endpoints.web.exposure.include=*
    
    
    #展示详细的健康信息
    management.endpoint.health.show-details=always
    
    
    • 2:查看所有可监控项访问http://localhost:8083/actuator/

    • 3:查看详细的健康信息访问http://localhost:8083/actuator/health

    • 4:查看beans加载情况访问http://localhost:8083/actuator/beans(其实我也不知道展示这个beans的信息有什么价值)

    • 5:查看应用运行环境相关参数访问http://localhost:8083/actuator/env

    • 6:查看引用日志级别访问http://localhost:8083/actuator/loggers

    四、通过访问Actuator提供的endpoint来管理应用

    • 1:修改com.naylor包下面的日志级别
    
    curl -X POST http://localhost:8083/actuator/loggers/com.naylor.logging -H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8" --data '{"configuredLevel":"debug"}'
    
    


  • 相关阅读:
    罗美琪和春波特的故事...
    欢迎参与 KubeVela 官方文档翻译活动
    开源 1 年半 star 破 1.2 万的 Dapr 是如何在阿里落地的?
    Service Mesh 从“趋势”走向“无聊”
    Nacos 2.0 性能提升十倍,贡献者 80% 以上来自阿里之外
    阿里巴巴云原生 etcd 服务集群管控优化实践
    KubeVela 1.0 :开启可编程式应用平台的未来
    知行动手实验室可以用来做什么?
    7. Jackson用树模型处理JSON是必备技能,不信你看
    Linux:sudo,没有找到有效的 sudoers 资源
  • 原文地址:https://www.cnblogs.com/Naylor/p/13597121.html
Copyright © 2011-2022 走看看