springboot 整合 actuator监控详情

这篇具有很好参考价值的文章主要介绍了springboot 整合 actuator监控详情。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境变量、日志信息、线程信息等

pom文件中添加

<!-- actuator start-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>${springboot.version}</version>
</dependency>
<!-- actuator end-->

yaml文件
监控端口必须单独配置,否则请求不到

server:
  port: 8091
#必须配置,否则端点默认禁用
management:
  endpoints:
    web:
      # 路径配置
      # base-path: /manage 修改默认的actuator/* 
      exposure:
        include: "*"
        # “*”号代表启用所有的监控端点,可以单独启用,例如,health,info,metrics等
        # exclude: beans  #关闭部分监控点
  server:
    port: 8091
  endpoint:
    health:
      show-details: always

启动项目,请求接口:http:/localhost:8092/actuator 返回的是可以查看的所有接口

health接口
如果项目中同步引用了oracle和redis,请求接口/health 时会带出状态,但信息不是很详细

{
  "status":"UP",
  "components":{
    "db":{
      "status":"UP",
      "details":{
        "database":"Oracle",
        "validationQuery":"isValid()"
      }
    },
    "diskSpace":{
      "status":"UP",
      "details":{
        "total":427390136320,
        "free":412959125504,
        "threshold":10485760,
        "exists":true
      }
    },
    "ping":{
      "status":"UP"
    },
    "redis":{
      "status":"UP",
      "details":{
        "version":"5.0.5"
      }
    }
  }
}

如果想关闭特定的检查指标

management:
  health:
    redise:
      enabled: false

info接口
就是在配置文件中以info开头的配置信息比如

info:
  app:
    name:
      spring-boot-actuator
    version: 1.0.0
    test: test

调用接口展示如下

{
  "app": {
    "name": "spring-boot-actuator",
    "version": "1.0.0",
    "test":"test"
  }
}

beans
展示了 bean 的别名、类型、是否单例、类的地址、依赖等信息。
conditions
可以在应用运行时查看代码了某个配置在什么条件下生效,或者某个自动配置为什么没有生效。

heapdump
访问actuator/heapdump 会自动生成一个jvm的堆文件heapdump 可以用jdk自带的jvm监控工具visualVM打开查看
shutdown
接口关闭springboot服务,需要配置文件开启

management:
  endpoint:
    shutdown:
      enabled: true

只支持post接口

curl -X POST "http://localhost:8080/actuator/shutdown" 
{
    "message": "stop"
}

mappings
展示全部的uri路径,和控制器的关系
在项目统计的时候还是蛮有用的

{
    "contexts":{
        "application":{
            "mappings":{
                "dispatcherServlets":{
                    "dispatcherServlet":[
                        {
                            "handler":"example.controller.TestController#get(String)",
                            "predicate":"{GET /test/get}",
                            "details":{
                                "handlerMethod":{
                                    "className":"example.controller.TestController",
                                    "name":"get",
                                    "descriptor":"(Ljava/lang/String;)Ljava/lang/Object;"
                                },
                                "requestMappingConditions":{
                                    "consumes":[

                                    ],
                                    "headers":[

                                    ],
                                    "methods":[
                                        "GET"
                                    ],
                                    "params":[

                                    ],
                                    "patterns":[
                                        "/test/get"
                                    ],
                                    "produces":[

                                    ]
                                }
                            }
                        },
                        
                       
                        {
                            "handler":"ResourceHttpRequestHandler [\"classpath:/META-INF/resources/webjars/\"]",
                            "predicate":"/webjars/**",
                            "details":null
                        },
                        {
                            "handler":"ResourceHttpRequestHandler [\"classpath:/META-INF/resources/\", \"classpath:/resources/\", \"classpath:/static/\", \"classpath:/public/\", \"/\"]",
                            "predicate":"/**",
                            "details":null
                        }
                    ]
                },
                "servletFilters":[
                    {
                        "servletNameMappings":[

                        ],
                        "urlPatternMappings":[
                            "/*"
                        ],
                        "name":"webMvcMetricsFilter",
                        "className":"org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter"
                    }
                    
                ],
                "servlets":[
                    {
                        "mappings":[

                        ],
                        "name":"default",
                        "className":"org.apache.catalina.servlets.DefaultServlet"
                    }
                ]
            },
            "parentId":null
        }
    }
}

threaddump接口
会产生当前线程活动的快照,主要展示线程名称、线程id、线程状态等
示例如下

{
    "threads":[
        {
            "threadName":"boundedElastic-evictor-1",
            "threadId":109,
            "blockedTime":-1,
            "blockedCount":0,
            "waitedTime":-1,
            "waitedCount":24,
            "lockName":"java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@20ab793d",
            "lockOwnerId":-1,
            "lockOwnerName":null,
            "inNative":false,
            "suspended":false,
            "threadState":"TIMED_WAITING",
            "stackTrace":[
                {
                    "methodName":"take",
                    "fileName":"ScheduledThreadPoolExecutor.java",
                    "lineNumber":809,
                    "className":"java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue",
                    "nativeMethod":false
                }
            ]
        }
    ]
}

loggers接口
可以查看当前应用的日志级别等信息

metrics接口
http://localhost:8092/actuator/metrics后返回的指标

再任意访问一个参数可以获得对应的指标
http://localhost:8092/actuator/metrics/jvm.buffer.memory.used

{
    "name":"jvm.buffer.memory.used",
    "description":"An estimate of the memory that the Java virtual machine is using for this buffer pool",
    "baseUnit":"bytes",
    "measurements":[
        {
            "statistic":"VALUE",
            "value":65537
        }
    ],
    "availableTags":[
        {
            "tag":"id",
            "values":[
                "direct",
                "mapped"
            ]
        }
    ]
}

序号 参数 参数说明 是否监控 监控手段 重要度
JVM

1 jvm.memory.max JVM 最大内存
2 jvm.memory.committed JVM 可用内存 是 展示并监控堆内存和 Metaspace 重要
3 jvm.memory.used JVM 已用内存 是 展示并监控堆内存和 Metaspace 重要
4 jvm.buffer.memory.used JVM 缓冲区已用内存
5 jvm.buffer.count 当前缓冲区数
6 jvm.threads.daemon JVM 守护线程数 是 显示在监控页面
7 jvm.threads.live JVM 当前活跃线程数 是 显示在监控页面;监控达到阈值时报警 重要
8 jvm.threads.peak JVM 峰值线程数 是 显示在监控页面
9 jvm.classes.loaded 加载 classes 数
10 jvm.classes.unloaded 未加载的 classes 数
11 jvm.gc.memory.allocated GC 时,年轻代分配的内存空间
12 jvm.gc.memory.promoted GC 时,老年代分配的内存空间
13 jvm.gc.max.data.size GC 时,老年代的最大内存空间
14 jvm.gc.live.data.size FullGC 时,老年代的内存空间
15 jvm.gc.pause GC 耗时 是 显示在监控页面
TOMCAT
16 tomcat.sessions.created tomcat 已创建 session 数
17 tomcat.sessions.expired tomcat 已过期 session 数
18 tomcat.sessions.active.current tomcat 活跃 session 数
19 tomcat.sessions.active.max tomcat 最多活跃 session 数 是 显示在监控页面,超过阈值可报警或者进行动态扩容 重要
20 tomcat.sessions.alive.max.second tomcat 最多活跃 session 数持续时间
21 tomcat.sessions.rejected 超过 session 最大配置后,拒绝的 session 个数 是 显示在监控页面,方便分析问题
22 tomcat.global.error 错误总数 是 显示在监控页面,方便分析问题
23 tomcat.global.sent 发送的字节数
24 tomcat.global.request.max request 最长时间
25 tomcat.global.request 全局 request 次数和时间
26 tomcat.global.received 全局 received 次数和时间
27 tomcat.servlet.request servlet 的请求次数和时间
28 tomcat.servlet.error servlet 发生错误总数
29 tomcat.servlet.request.max servlet 请求最长时间
30 tomcat.threads.busy tomcat 繁忙线程 是 显示在监控页面,据此检查是否有线程夯住
31 tomcat.threads.current tomcat 当前线程数(包括守护线程) 是 显示在监控页面 重要
32 tomcat.threads.config.max tomcat 配置的线程最大数 是 显示在监控页面 重要
33 tomcat.cache.access tomcat 读取缓存次数
34 tomcat.cache.hit tomcat 缓存命中次数
CPU
35 system.cpu.count CPU 数量
36 system.load.average.1m load average 是 超过阈值报警 重要
37 system.cpu.usage 系统 CPU 使用率
38 process.cpu.usage 当前进程 CPU 使用率 是 超过阈值报警
39 http.server.requests http 请求调用情况 是 显示 10 个请求量最大,耗时最长的 URL;统计非 200 的请求量 重要
40 process.uptime 应用已运行时间 是 显示在监控页面
41 process.files.max 允许最大句柄数 是 配合当前打开句柄数使用
42 process.start.time 应用启动时间点 是 显示在监控页面
43 process.files.open 当前打开句柄数 是 监控文件句柄使用率,超过阈值后报警 重要

监控页面

<dependency>
  <groupId>cn.pomit</groupId>
  <artifactId>spring-boot-monitor</artifactId>
  <version>0.0.1</version>
</dependency>

启动后访问
http://localhost:8091/monitor

只有一个应用点进去

参考文章:
https://www.pomit.cn/SpringBootMonitor/#/
https://blog.csdn.net/yunfeather/article/details/122581536文章来源地址https://www.toymoban.com/news/detail-809417.html

到了这里,关于springboot 整合 actuator监控详情的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • SpringBoot开启 Actuator springboot开启actuator监控信息

    官网文档: https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/actuator-api/html/ 2.1.5.RELEASE 为对应springboot版本号 include: \\\"*\\\" 表示 公开所有端点 include: \\\"health,metrics,threaddump\\\" 表示只公开这三个 health,metrics,threaddump 端点 所有可选的端点及说明 端点 作用 “*” 公开全部 health 提供应用程序的健

    2024年01月22日
    浏览(49)
  • Springboot Actuator监控

    官网连接: Spring Boot Reference Documentation Spring Boot包括许多附加功能,帮助您在将应用程序推向生产时监视和管理应用程序。您可以选择使用HTTP端点或JMX来管理和监视应用程序。 审计,健康和指标收集 也可以自动应用于应用程序。 spring-boot-actuator 模块提供所有Spring Boot的生产

    2024年02月02日
    浏览(31)
  • 【监控】spring actuator源码速读

    目录 1.前言 2.先搂一眼EndPoint 3.EndPoint如何被注入 4.EndPoint如何被暴露 4.1.如何通过http暴露 4.2.如何通过jmx暴露 5.EndPoint是怎么实现监控能力的 6.知道这些的意义是什么 版本:spring-boot-starter-actuator  2.6.3 阅读源码一定要带着疑问去阅读,这个疑问就是你阅读的主线,不然在浩如

    2024年02月19日
    浏览(28)
  • Springboot 实践(13)spring boot 整合RabbitMq

    前文讲解了RabbitMQ的下载和安装,此文讲解springboot整合RabbitMq实现消息的发送和消费。 1、创建web project项目,名称为“SpringbootAction-RabbitMQ” 2、修改pom.xml文件,添加amqp使用jar包    !--  RabbitMQ --         dependency             groupIdorg.springframework.boot/groupId         

    2024年02月09日
    浏览(42)
  • Spring Boot Actuator详解

    Spring Boot Actuator 模块提供了生产级别的功能,比如 健康检查 , 审计 , 指标收集 , HTTP跟踪 等,帮助我们监控和管理Spring Boot应用。 这个模块是一个采集应用内部信息暴露给外部的模块,上述的功能都可以通过HTTP和JMX访问。 因为暴露内部信息的特性,Actuator也可以和一些外

    2024年02月07日
    浏览(29)
  • spring boot actuator 禁用后,/actuator仍可正常访问

    项目上线后,被测试出actuator没有关闭,关闭后,仍可正常访问/actuator端点,只是类似/actuator/env这样的无法访问,现在就想把/actuator端点也给禁用了。 spring boot 2.x关闭actuator配置,关闭后,仍可正常访问/actuator端点 说明spring boot 2.x无法通过配置的方式禁用/actuator端点 大部分

    2024年01月19日
    浏览(29)
  • SpringBoot 监控神器——Actuator 保姆级教程

    pom.xml info beans conditions heapdump shutdown mappings threaddump loggers 端点 metrics 端点 自定义Endpoint 自定义监控端点常用注解 使用Filter对访问actuator做限制 Spring Boot Monitor做监控页面 SpringBoot自带监控功能Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况、Bean加载情况、环境

    2024年02月16日
    浏览(35)
  • SpringBoot应用监控Actuator使用的安全隐患

    Actuator 是 springboot 提供的用来对应用系统进行自省和监控的功能模块,借助于 Actuator 开发者可以很方便地对应用系统某些监控指标进行查看、统计等。在 Actuator 启用的情况下,如果没有做好相关权限控制,非法用户可通过访问默认的执行器端点(endpoints)来获取应用系统中

    2024年02月05日
    浏览(33)
  • spring boot admin搭建,监控springboot程序运行状况

    新建一个spring boot web项目,添加以下依赖 spring boot的监控端点依赖必须的。 关于版本,springboot的版本前两位是什么,上面依赖的版本就对应什么版本,比如现在spring boot parent的版本是2.3.5,这里的依赖可以选择2.3开头的版本。下面是开启相关的端点功能 添加以上依赖之后,

    2024年04月16日
    浏览(24)
  • 【SpringBoot】Spring Boot 项目中整合 MyBatis 和 PageHelper

    目录 前言         步骤 1: 添加依赖 步骤 2: 配置数据源和 MyBatis 步骤 3: 配置 PageHelper 步骤 4: 使用 PageHelper 进行分页查询 IDEA指定端口启动 总结         Spring Boot 与 MyBatis 的整合是 Java 开发中常见的需求,特别是在使用分页插件如 PageHelper 时。PageHelper 是一个针对 MyBat

    2024年04月25日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包