ICode9

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

Spring Boot基础(六)SpringBoot监控

2022-01-22 18:02:32  阅读:183  来源: 互联网

标签:http SpringBoot Spring Boot 8080 href templated actuator localhost


添加依赖,开启监控功能

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

 

 在properties文件中开启完整健康信息和埋点(由于安全等因素,默认只显示不完整的health信息)

#开启完整健康信息
management.endpoint.health.show-details=always

#将所有endpoint暴露
management.endpoints.web.exposure.include=*

 

启动SpringBoot项目,启动时注意查看启动日志,会发现有这行:

2022-01-22 16:36:12.697  INFO 11064 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 13 endpoint(s) beneath base path '/actuator'

因此访问的路径为IP:port/actuator,访问后得到一串json,可以在json.cn中解析出来查看:

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

 

 

 

 

 beans可以查看创建的所有Bean

 

 

 

//这是我之前重写的初始化类
"myApplicationContextInitializer":{ "aliases":[], "scope":"singleton", "type":"com.yz.sprintbootmyun.listener.MyApplicationContextInitializer", "resource":"file [E:\\Work\\Workspace\\sprintboot-my-un\\target\\classes\\com\\yz\\sprintbootmyun\\listener\\MyApplicationContextInitializer.class]", "dependencies":[] },

 

mappings可查查看当前所有url路径

 

 

 "handler":"com.yz.sprintbootmyun.UserController#findAll()",
                            "predicate":"{ [/user/findAll]}",
                            "details":{
                                "handlerMethod":{
                                    "className":"com.yz.sprintbootmyun.UserController",
                                    "name":"findAll",
                                    "descriptor":"()Ljava/lang/String;"
                                },

 

 

这些都是json串,看起来尤其不直观,如果想图形化更直观地查看,可以使用IDEA自带的插件,可以查看常用的几个功能

 

 

如果这还不能狗满足监控使用,那么就可以用SpringBoot-Admin了,admin由一个server和一个或若干个client组成

 

在client中,需要在配置文件中指定server的路径,以及actuator开启的功能

spring.boot.admin.client.url=http://localhost:9000

management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

在server中,只需在主类上添加@EnableAdminServer注解即可。如果在同一机器上启动server或client,注意端口不要重复

访问指定的网址:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

v

标签:http,SpringBoot,Spring,Boot,8080,href,templated,actuator,localhost
来源: https://www.cnblogs.com/yuan-zhou/p/15834270.html

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

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

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

ICode9版权所有