Spring Boot2.xx开启监控 Actuator

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

                       Spring Boot2.xx开启监控 Actuator,spring boot,后端,java

docker实战(一):centos7 yum安装docker

docker实战(二):基础命令篇

docker实战(三):docker网络模式(超详细)

docker实战(四):docker架构原理

docker实战(五):docker镜像及仓库配置

docker实战(六):docker 网络及数据卷设置

docker实战(七):docker 性质及版本选择

认知升维: 道、法、术、器、势

 


spring boot actuator介绍

  • Spring Boot包含许多其他功能,可帮助您在将应用程序推送到生产环境时监视和管理应用程序。

  • 您可以选择使用HTTP端点或JMX来管理和监视应用程序。

  • 审核,运行状况和指标收集也可以自动应用于您的应用程序。


    总之Spring Boot Actuator就是一款可以帮助你监控系统数据的框架,其可以监控很多很多的系统数据,它有对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息,如:
    显示应用程序员的Health健康信息

    显示Info应用信息

    显示HTTP Request跟踪信息

    显示当前应用程序的“Metrics”信息

    显示所有的@RequestMapping的路径信息

    显示应用程序的各种配置信息

    显示你的程序请求的次数 时间 等各种信息


引入Actuactor三角坐标依赖 

<!-- 端点监控的配置-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.hateoas</groupId>
    <artifactId>spring-hateoas</artifactId>
</dependency>

访问: http://localhost:9999/actuator/         响应信息如下所示

{
    "_links": {
        "self": {
            "href": "http://localhost:9999/actuator",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:9999/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:9999/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://localhost:9999/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://localhost:9999/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:9999/actuator/health/{*path}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:9999/actuator/info",
            "templated": false
        },
        "conditions": {
            "href": "http://localhost:9999/actuator/conditions",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:9999/actuator/configprops",
            "templated": false
        },
        "configprops-prefix": {
            "href": "http://localhost:9999/actuator/configprops/{prefix}",
            "templated": true
        },
        "env": {
            "href": "http://localhost:9999/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:9999/actuator/env/{toMatch}",
            "templated": true
        },
        "loggers": {
            "href": "http://localhost:9999/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://localhost:9999/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://localhost:9999/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:9999/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:9999/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:9999/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:9999/actuator/scheduledtasks",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:9999/actuator/mappings",
            "templated": false
        }
    }


访问health端点: http://localhost:9999/actuator/health  响应信息如下:

{
    "status": "UP",
    "components": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 1333606182912,
                "free": 1269725843456,
                "threshold": 10485760,
                "exists": true
            }
        },
        "elasticsearch": {
            "status": "UP",
            "details": {
                "cluster_name": "elasticsearch",
                "status": "green",
                "timed_out": false,
                "number_of_nodes": 1,
                "number_of_data_nodes": 1,
                "active_primary_shards": 0,
                "active_shards": 0,
                "relocating_shards": 0,
                "initializing_shards": 0,
                "unassigned_shards": 0,
                "delayed_unassigned_shards": 0,
                "number_of_pending_tasks": 0,
                "number_of_in_flight_fetch": 0,
                "task_max_waiting_in_queue_millis": 0,
                "active_shards_percent_as_number": 100.0
            }
        },
        "ping": {
            "status": "UP"
        },
        "r2dbc": {
            "status": "UP",
            "details": {
                "database": "Jasync-MySQL",
                "validationQuery": "validate(REMOTE)"
            }
        }
    }
}

开启 Info端点:  yml文件中配置

# 显示任意的应用信息,默认关闭 springBoot版本:2.7.5 CURRENT GA如果是更低一些的版本默认是开启的

# 在spring boot 2.0以后,actuator默认只开启了info和health两个端点,要想使用其他的端点,需要在application.yml中打开
management:
  endpoint:
    health:
      show-details: always  # 配置health端点显示详细信息
  info:
    env:
      enabled: true  # 显示任意的应用信息,默认关闭  springBoot版本:2.7.5 CURRENT  GA如果是更低一些的版本默认是开启的
  endpoints:
    web:
      exposure:
        include: "*"
      cors:
        allowed-headers: "*"

info:
  app:
    encoding: @project.build.sourceEncoding@
    java:
      source: @java.version@
      target: @java.version@

访问info端点: http://localhost:9999/actuator/info   响应信息如下:

{
    "app": {
        "encoding": "UTF-8",
        "java": {
            "source": "1.8.0_221",
            "target": "1.8.0_221"
        }
    }
}


拓展info端点:

package org.jd.websocket.auth.data.reactor.help;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class CustomBuildInfoContributor implements InfoContributor {
    @Override
    public void contribute(Info.Builder builder) {
        Map<String,Object> details= new ConcurrentHashMap<>();
        details.put("build",Collections.singletonMap("timestamp",new Date()));
        details.put("author","YangGe");
        builder.withDetails(details);
    }
}

再次访问info端点: http://localhost:9999/actuator/info   响应信息如下: 


{
    "app": {
        "encoding": "UTF-8",
        "java": {
            "source": "1.8.0_221",
            "target": "1.8.0_221"
        }
    },
    "build": {
        "timestamp": "2023-08-07T15:14:28.463+00:00"
    },
    "author": "YangGe"
}











management:
  endpoints:
    web:
      base-path: /actuator  #配置端点访问前缀
      exposure:
        include: info,health  #只暴露info,health两个端点; “*” 表示暴露所有端点
        exclude: health  #可以将以暴露的端点排除(不暴露)
 


其他更细节的配置可以看官网

spring boot 热部署导入devtool依赖idea窗口钝化

yml yet anothor markup language

actuator是spring boot 提供的对应系统的自省和监控的基础功能,当出现问题时可以及时的定位问题。


拓展Metrics端点:

http://localhost:9999/actuator/metrics   访问该端点,响应信息如下

{
    "names":[
        "application.ready.time",
        "application.started.time",
        "disk.free",
        "disk.total",
        "executor.active",
        "executor.completed",
        "executor.pool.core",
        "executor.pool.max",
        "executor.pool.size",
        "executor.queue.remaining",
        "executor.queued",
        "http.server.requests",
        "jvm.buffer.count",
        "jvm.buffer.memory.used",
        "jvm.buffer.total.capacity",
        "jvm.classes.loaded",
        "jvm.classes.unloaded",
        "jvm.gc.live.data.size",
        "jvm.gc.max.data.size",
        "jvm.gc.memory.allocated",
        "jvm.gc.memory.promoted",
        "jvm.gc.overhead",
        "jvm.gc.pause",
        "jvm.memory.committed",
        "jvm.memory.max",
        "jvm.memory.usage.after.gc",
        "jvm.memory.used",
        "jvm.threads.daemon",
        "jvm.threads.live",
        "jvm.threads.peak",
        "jvm.threads.states",
        "logback.events",
        "process.cpu.usage",
        "process.start.time",
        "process.uptime",
        "system.cpu.count",
        "system.cpu.usage"
    ]
}

对应这些端点信息,用于实现生产级的度量工具. 这些指标包括内存总量,空闲内存数据,处理器数量,系统正常运行时间,堆信息等,如果想了解某项指标的信息,

http://localhost:9999/actuator/metrics

端点后加上上述指标的名称即可。如当前内存使用情况可以通过:

http://localhost:9999/actuator/metrics/jvm.memory.used  就会得到如下响应信息:


{
    "name":"jvm.memory.used",
    "description":"The amount of used memory",
    "baseUnit":"bytes",
    "measurements":[
        {
            "statistic":"VALUE",
            "value":479145136
        }
    ],
    "availableTags":[
        {
            "tag":"area",
            "values":[
                "heap",
                "nonheap"
            ]
        },
        {
            "tag":"id",
            "values":[
                "Compressed Class Space",
                "PS Survivor Space",
                "PS Old Gen",
                "Metaspace",
                "PS Eden Space",
                "Code Cache"
            ]
        }
    ]
}


http://localhost:9999/actuator/metrics/jvm.memory.usage.after.gc  gc回收内存的情况


{
    "name":"jvm.memory.usage.after.gc",
    "description":"The percentage of long-lived heap pool used after the last GC event, in the range [0..1]",
    "baseUnit":"percent",
    "measurements":[
        {
            "statistic":"VALUE",
            "value":0.0014572154044711605
        }
    ],
    "availableTags":[
        {
            "tag":"area",
            "values":[
                "heap"
            ]
        },
        {
            "tag":"pool",
            "values":[
                "long-lived"
            ]
        }
    ]
}文章来源地址https://www.toymoban.com/news/detail-631885.html

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

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

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

相关文章

  • 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)
  • Spring Boot中的Actuator是什么?Spring Boot中的Starter依赖是什么?

    在Spring Boot中,Actuator是一种用于监控和管理应用程序的工具。它提供了一些额外的端点和功能,使开发人员能够更好地了解和控制他们的应用程序。 Actuator提供了以下功能: 指标收集:Actuator可以收集并显示有关应用程序的指标,例如内存使用情况、线程数、请求处理时间等

    2024年02月09日
    浏览(34)
  • Spring Boot Actuator未授权访问漏洞

    Spring Boot Actuator 端点的未授权访问漏洞是一个安全性问题,可能会导致未经授权的用户访问敏感的应用程序信息。 可是并不用太过担心,Spring Boot Actuator 默认暴漏的信息有限,一般情况下并不会暴露敏感数据。 注册中心有些功能集成了actuator,如果同时使用eureka和actuator,可

    2024年02月13日
    浏览(30)
  • 关于Spring Boot Actuator漏洞补救方案

    在浏览器中范围于http://192.168.0.119:81/dev-api/actuator(http://IP:端口/actuator),如下图 几个漏洞属于配置不当引起路由暴露。 1.读取用户的认证字段获取敏感信息 可以直接尝试访问网站目录下的/trace 路径,读取用户认证字段信息,比如在trace 路径下,会有用户的敏感信息,可能

    2024年02月04日
    浏览(30)
  • 如何解决 Spring Boot Actuator 的未授权访问漏洞

    Spring Boot Actuator  的作用是提供了一组管理和监控端点,允许你查看应用程序的运行时信息,例如健康状态、应用程序信息、性能指标等。这些端点对于开发、 测试  和运维团队来说都非常有用,可以帮助快速诊断问题、监控应用程序的性能,并采取必要的措施来维护和管理

    2024年02月07日
    浏览(25)
  • 如何在Spring Boot中禁用Actuator端点安全性?

    在Spring Boot中,禁用Actuator端点的安全性可以通过配置来实现。Actuator端点是Spring Boot应用程序的管理和监控端点,它们默认受到Spring Security的保护。如果希望完全禁用Actuator端点的安全性,我们可以按照以下步骤进行操作: 确保我们的pom.xml文件中包含了Spring Boot Starter依赖项。

    2024年02月04日
    浏览(27)
  • java Spring Boot 2 /actuator/health 返回 HTTP 404

    spring-boot-starter-actuator官方文档 Spring Boot 包含许多附加功能,可帮助您在将应用程序投入生产时监控和管理应用程序。您可以选择使用 HTTP 端点或 JMX 来管理和监控您的应用程序。审核、运行状况和指标收集也可以自动应用于您的应用程序。 该spring-boot-actuator模块提供了 Spri

    2024年01月18日
    浏览(32)
  • spring boot actuator 未授权访问(env泄露redis密码)

    Actuator Actuator是Spring Boot提供的服务监控和管理中间件,默认配置会出现接口未授权访问,部分接口会泄露网站流量信息和内存信息等,使用Jolokia库特性甚至可以远程执行任意代码,获取服务器权限。 渗透过程 访问浏览器访问actuator 访问env获取到敏感信息redis服务器地址以及

    2024年02月11日
    浏览(27)
  • java Spring Boot2.7写一个接口 提供图片预览 前端可以直接用接口地址当src为图片地址使用

    我们特别是在做小程序开发时 很多图片会比较大 而小程序本身就对自身大小要求非常高 所以 图片放在服务器上提供访问链接是一种非常好的选择 我想很多前端会误认为 直接将图片放在服务器上就可以了 但其实没那么简单 因为服务器其实也可以理解为一个电脑 你就想 你自

    2024年02月07日
    浏览(38)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包