ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

springboot整合Actuator监控

2022-02-07 22:02:51  阅读:151  来源: 互联网

标签:web springboot No 展示 boot 监控 org Actuator Yes


springboot整合Actuator监控。

1.简要说明:

Actuator提供了对springboot应用程序监视和管理的能力,可以选择通过使用HTTP Endpoint或者使用JMX来管理和监控springboot应用程序。

Actuator 允许通过Endpoints对springboot进行监控和交互。springboot内置的Endpoint包括(两种Endpoint: WEB和JMX, web方式考虑到安全性默认只开启了/health):

ID

JMX

Web

Endpoint功能描述

auditevents

Yes

No

暴露当前应用的audit events (依赖AuditEventRepository)

beans

Yes

No

Spring中所有Beans

caches

Yes

No

暴露可用的缓存

conditions

Yes

No

展示configuration 和auto-configuration类中解析的condition,并展示是否匹配的信息.

configprops

Yes

No

展示所有的@ConfigurationProperties

env

Yes

No

展示环境变量,来源于ConfigurableEnvironment

flyway

Yes

No

flyway数据迁移信息(依赖Flyway)

health

Yes

Yes

展示应用的健康信息

heapdump

N/A

No

web应用时)hprof 堆的dump文件(依赖HotSpot JVM)

httptrace

Yes

No

展示HTTP trace信息, 默认展示前100个(依赖HttpTraceRepository)

info

Yes

No

应用信息

integrationgraph

Yes

No

展示spring集成信息(依赖spring-integration-core)

jolokia

N/A

No

web应用时)通过HTTP暴露JMX beans(依赖jolokia-core)

logfile

N/A

No

web应用时)如果配置了logging.file.name 或者 logging.file.path,展示logfile内容

loggers

Yes

No

展示或者配置loggers,比如修改日志的等级

liquibase

Yes

No

Liquibase 数据迁移信息(依赖Liquibase)

metrics

Yes

No

指标信息

mappings

Yes

No

@RequestMapping映射路径

prometheus

N/A

No

web应用时)向prometheus暴露监控信息(依赖micrometer-registry-prometheus)

quartz

Yes

No

展示 quartz任务信息

scheduledtasks

Yes

No

展示Spring Scheduled 任务信息

sessions

Yes

No

session信息

shutdown

Yes

No

关闭应用

startup

Yes

No

展示ApplicationStartup的startup步骤的数据(依赖通在SpringApplication配置BufferingApplicationStartup)

threaddump

Yes

No

线程dump

当然也可以自己定义暴露哪些endpoint。

2.代码实现:

创建项目actuator

添加依赖

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

yml配置

server:
  port: 8080

management:
  endpoints:
    enabled-by-default: false
    web:
      base-path: /cxh
      exposure:
        include: 'info,health,env,beans,date'
  endpoint:
    info:
      enabled: true
    health:
      enabled: true
    env:
      enabled: true
    beans:
      enabled: true
    date:
      enabled: true

自定义Endpoint

​通过@JmxEndpoint or @WebEndpoint注解来定义自己的endpoint, 然后通过@ReadOperation, @WriteOperation或者@DeleteOperation来暴露操作,比如添加系统时间date的endpoint

import java.time.LocalDateTime;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;


@RestController("custom")
@WebEndpoint(id = "date")
public class CustomEndpointController {

    @ReadOperation
    public ResponseEntity<String> currentDate() {
        return ResponseEntity.ok(LocalDateTime.now().toString());
    }
}

3.实现效果:

运行项目actuator,浏览器打开http://localhost:8080/cxh

 

标签:web,springboot,No,展示,boot,监控,org,Actuator,Yes
来源: https://blog.csdn.net/weixin_39220472/article/details/122809322

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有