美文网首页
SpringBoot1.x Actuator监控端点使用

SpringBoot1.x Actuator监控端点使用

作者: 砒霜拌辣椒 | 来源:发表于2020-07-27 19:33 被阅读0次

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

    1、Maven导包

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

    2、关闭授权

    很多端点的访问需要授权才允许访问,可以在配置中关闭授权。

    management:
      security.enabled: false # 部分端点访问需要授权,关闭授权
    

    3、端点介绍

    • /health
    {
        "status": "UP",
        "diskSpace": {
            "status": "UP",
            "total": 250685575168,
            "free": 155073470464,
            "threshold": 10485760
        }
    }
    
    • /env
    {
        "profiles": [],
        "server.ports": {
            "local.server.port": 10500
        },
        "servletContextInitParams": {},
        "systemProperties": {
            "java.vendor": "Oracle Corporation",
            "jboss.modules.system.pkgs": "com.intellij.rt",
            "sun.java.launcher": "SUN_STANDARD",
            "sun.nio.ch.bugLevel": "",
            "sun.management.compiler": "HotSpot 64-Bit Tiered Compilers",
            "spring.output.ansi.enabled": "always",
            "os.name": "Mac OS X",
            ......
        }
    }
    
    • /mappings
    {
        "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)"
        },
        "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
        },
        "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
        },
        "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
        },
        "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
        },
        "{[/shutdown || /shutdown.json],methods=[POST],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.ShutdownMvcEndpoint.invoke()"
        },
        "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
            "bean": "endpointHandlerMapping",
            "method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
        }
    }
    
    • /shutdown

    关停服务,需要在配置中放开此端点,并且需要POST请求方式

    endpoints:
      shutdown.enabled: true # 开启远程关闭服务
    
    2019-11-13 23:48:07,929 [INFO] [Thread-16] [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext:984] [] Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@517566b: startup date [Wed Nov 13 23:44:15 CST 2019]; root of context hierarchy
    2019-11-13 23:48:07,931 [INFO] [Thread-16] [org.springframework.context.support.DefaultLifecycleProcessor:358] [] Stopping beans in phase 0
    2019-11-13 23:48:07,933 [INFO] [Thread-16] [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter:449] [] Unregistering JMX-exposed beans on shutdown
    2019-11-13 23:48:07,933 [INFO] [Thread-16] [org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter:241] [] Unregistering JMX-exposed beans
    2019-11-13 23:48:07,934 [INFO] [Thread-16] [org.springframework.jmx.export.annotation.AnnotationMBeanExporter:449] [] Unregistering JMX-exposed beans on shutdown
    2019-11-13 23:48:07,935 [INFO] [Thread-16] [io.undertow.servlet:360] [] Destroying Spring FrameworkServlet 'dispatcherServlet'
    

    SpringBoot2.x Actuator监控端点使用

    相关文章

      网友评论

          本文标题:SpringBoot1.x Actuator监控端点使用

          本文链接:https://www.haomeiwen.com/subject/xkjtrktx.html