diff --git a/ReadMe.md b/ReadMe.md index 6aabce3..84572da 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -30,6 +30,8 @@

+

+ # Java基础 ## 基础知识 @@ -394,6 +396,25 @@ todo # 消息队列 ## Kafka +* [消息队列kafka详解:Kafka快速上手(Java版)](docs/mq/kafka/消息队列kafka详解:Kafka快速上手(Java版).md) +* [消息队列kafka详解:Kafka一条消息存到broker的过程](docs/mq/kafka/消息队列kafka详解:Kafka一条消息存到broker的过程.md) +* [消息队列kafka详解:消息队列kafka详解:Kafka介绍](docs/mq/kafka/消息队列kafka详解:Kafka介绍.md) +* [消息队列kafka详解:Kafka原理分析总结篇](docs/mq/kafka/消息队列kafka详解:Kafka原理分析总结篇.md) +* [消息队列kafka详解:Kafka常见命令及配置总结](docs/mq/kafka/消息队列kafka详解:Kafka常见命令及配置总结.md) +* [消息队列kafka详解:Kafka架构介绍](docs/mq/kafka/消息队列kafka详解:Kafka架构介绍.md) +* [消息队列kafka详解:Kafka的集群工作原理](docs/mq/kafka/消息队列kafka详解:Kafka的集群工作原理.md) +* [消息队列kafka详解:Kafka重要知识点+面试题大全](docs/mq/kafka/消息队列kafka详解:Kafka重要知识点+面试题大全.md) +* [消息队列kafka详解:如何实现延迟队列](docs/mq/kafka/消息队列kafka详解:如何实现延迟队列.md) +* [消息队列kafka详解:如何实现死信队列](docs/mq/kafka/消息队列kafka详解:如何实现死信队列.md) + +## RocketMQ +* [RocketMQ系列:事务消息(最终一致性)](docs/mq/RocketMQ/RocketMQ系列:事务消息(最终一致性).md) +* [RocketMQ系列:基本概念](docs/mq/RocketMQ/RocketMQ系列:基本概念.md) +* [RocketMQ系列:广播与延迟消息](docs/mq/RocketMQ/RocketMQ系列:广播与延迟消息.md) +* [RocketMQ系列:批量发送与过滤](docs/mq/RocketMQ/RocketMQ系列:批量发送与过滤.md) +* [RocketMQ系列:消息的生产与消费](docs/mq/RocketMQ/RocketMQ系列:消息的生产与消费.md) +* [RocketMQ系列:环境搭建](docs/mq/RocketMQ/RocketMQ系列:环境搭建.md) +* [RocketMQ系列:顺序消费](docs/mq/RocketMQ/RocketMQ系列:顺序消费.md) # 大后端 * [后端技术杂谈开篇:云计算,大数据与AI的故事](docs/backend/后端技术杂谈开篇:云计算,大数据与AI的故事.md) diff --git a/docs/monitor/Spring Actuator.md b/docs/monitor/Spring Actuator.md new file mode 100644 index 0000000..a1ee5ef --- /dev/null +++ b/docs/monitor/Spring Actuator.md @@ -0,0 +1,578 @@ +## ǰ�� + +��΢����εͳ�ܹ��У������ļ����DZز����اٴġ�L·ǰ������΢����Ӧ�����ǻ���Spring Cloudε�У�Ҳ����˵�ǻ���Spring Bootε�еġ���ɦʹ��Spring Boot Actuator������΢�����ļ��أ���������ȫ�棬���ҷdz����㡣 + +����ƪ���¡�[Spring Boot Actuator���ɣ��ѵ����������ã�](https://link.juejin.cn?target=https%3A%2F%2Fmp.weixin.qq.com%2Fs%2FBaNQWygQb8UXxktrXetOcw "https://mp.weixin.qq.com/s/BaNQWygQb8UXxktrXetOcw")���������Ѿ����������ν�Actuator���ɵ�Spring Boot��L·�У����ҽ����������Զ���Endpoint���˵㣩������������˵�������룬��ô����ƪ�����أ����ǽ�����Actuatorԭ���˵��Ĺ��ܼ�����ʹ�ó����� + +## Endpoints ���� + +Actuator����ν�� Endpoints ������Ϊ�˵㣩�ṩ���ⲿ����Ӧ�ó������з��ʺͽ����Ĺ��ܡ� ����˵/health�˵��ṩ��Ӧ�ý�����������Ϣ��metrics �˵��ṩ��Ӧ�ó�����ָ�꣨JVM �ڴ�ʹ�á�εͳCPUʹ�õȣ���Ϣ�� + +Actuatorԭ���Ķ˵��ɷ�Ϊ�����ࣺ + +* Ӧ�������ࣺ��ȡӦ�ó����м��ص�Ӧ�����á������������Զ������ñ�������Spring BootӦ���������ص���������Ϣ�� +* ����ָ���ࣺ��ȡӦ�ó������й��������ڼ��صĶ���ָ�꣬���磺�ڴ���Ϣ���̳߳���Ϣ��HTTP����ͳ�Ƶȡ� +* ���������ࣺ�ṩ�˶�Ӧ�õĹرյȲ����๦�ܡ� + +��ͬ�汾��Actuator�ṩ��ԭ���˵��������룬��ʹ�õĹ�������������ʹ�ð汾�Ĺۇٴ��ĵ�Ϊ׼��ͬɦ��ÿ��ԭ���Ķ˵㶼����ͨ�������������Ľ��û����á� + +����Actuator 2.x ��Ĭ�϶˵�������/actuatorǰ׺��ͬɦĬ��ֻ��¶�������˵�Ϊ/actuator/health�� /actuator/info�����ڶ˵㱩¶�����ã��ɲο�ǰһƪ���¡���������Spring Boot 2.2.2.RELEASE�汾���ص㽲��ÿ���˵��Ĺ��ܺ�Ӧ�ó����� + +## actuator�˵� + +Actuator 2.x������Ĭ�϶˵㣬����չʾL·ǰӦ���б�¶�����Ķ˵����ܣ�����������Ϊ���ö˵���L·1⁄4�� + +����URL��[http://localhost:8080/actuator](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator "http://localhost:8080/actuator") ����Ӧչʾ��������ͼ�� + +![image-20230530233537559](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233537559.png) + +����ֻչʾ��һ���ֵĶ˵㣬���ؽ���Ϊ�������������������IJ���-Handler�����˸�ʽ������ͨ��actuator����ֱ�۵L·���L·ǰ��������Щ�˵㣬�Լ���Щ�˵������ƺ�����·���� + +�������ǾͰ�����ʾactuator�˵�չʾ���б���һ���ܡ� + +## auditevents�˵� + +auditevents�˵�������ʾӦ�ñ�¶�������1⁄4� (������֤���롢����ʧ��)����ʹ���Ǵ��������ж˵㣬Ĭ��������Ҳ�ǿ����������˵��ġ���Ϊʹ������ǰ������Ҫ��Spring�����д���һ������ΪAuditEventRepository��Bean�ġ� + +�鿴�������Θ������̳̣������϶��ǽ�����auditevents�˵㹦�ܣ���δչʾ����ɻ�������߾����෽���ԣ����ڸ�����д��һ������������ + +�����漰��Ȩ����֤����Ҫ������spring-boot-starter-security������ + +```` + + org.springframework.boot + spring-boot-starter-security +` +```` + +�������������������Dz����ģ�����Ҫ����security�����ã���ȻAuthorizationAuditListener,AuthenticationAuditListener ����jô�1⁄4���? ����,���Ǽ������ ́��룺 + + +```` +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth.inMemoryAuthentication() + .withUser("admin") + .password(bcryptPasswordEncoder().encode("admin")) + .roles("admin"); + } +```` + +```` + @Bean + public PasswordEncoder bcryptPasswordEncoder() { + return new BCryptPasswordEncoder(); + } +} +```` + +����������securityĬ�εĵ�1⁄4������Ȩ�޿��ƣ�Ҳ����˵���еķ��ʁ���Ҫ���е�1⁄4������1⁄4���û�����������Ϊadmin�� + +���⣬ǰ���ᵽ��Ҫ�õ�AuditEventRepository��Bean��������ʼ��һ����Ӧ��Bean�� + + + + +```` +@Configuration +public class AuditEventConfig { + + @Bean + public InMemoryAuditEventRepository repository(){ + return new InMemoryAuditEventRepository(); + } +} +```` + +InMemoryAuditEventRepository��AuditEventRepository�ӿڵ�Ψһɻ���ࡣ + +������L·��auditevents�˵��������l�����[http://localhost:8080/actuator](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator "http://localhost:8080/actuator") ,��ɦ����ת��Security�ṩ�ĵ�1⁄4ҳ�棺 + +![image-20230530233604253](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233604253.png) + +����������ָ�����û��������룬��1⁄4�ɹ�����ת��/actuatorҳ�棺 + +![image-20230530233625068](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233625068.png) + +���Կ���auditevents�˵��Ѿ��ɹ���ʾ�����l��¿�ҳ������[http://localhost:8080/actuator/auditevents](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fauditevents "http://localhost:8080/actuator/auditevents") ��չʾ�������£� + +![image-20230530233716752](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233716752.png) + +���Կ����Ѿ���1⁄4����Ȩ�����ص��1⁄4������е�һ���1⁄4�������ֱ�ӷ���actuator�˵�ɦ������֮ǰΪ��Ȩ�����棬�����1⁄4�����Ϊ"AUTHORIZATION_FAILURE"��Ҳ������֤ʧ�ܡ���ɦ��ת����1⁄4ҳ�棬Ȼ���ڵ�1⁄4ҳ�������û��������룬��1⁄4�ɹ�����Ӧ���1⁄4�Ϊ"AUTHENTICATION_SUCCESS"�� + +Ҳ����˵auditevents��1⁄4���û���֤��1⁄4εͳ���ص��1⁄4���Ϣ������ɦ��������֤�û����1⁄4����͡����ɻ�ַ��sessionId�ȡ� + +ʾ��Դ����ַ��[github.com/secbr/sprin��](https://link.juejin.cn?target=https%3A%2F%2Fgithub.com%2Fsecbr%2Fspringboot-all%2Ftree%2Fmaster%2Fspringboot-actuator-auditevents "https://github.com/secbr/springboot-all/tree/master/springboot-actuator-auditevents") �� + +## beans�˵� + +/beans�˵��᷵��Spring����������bean�ı��������͡��Ƿ���������������Ϣ�� + +����·��Ϊ[http://localhost:8080/actuator/beans](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fbeans "http://localhost:8080/actuator/beans") ����Χ�������£� + +![image-20230530233748286](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233748286.png) + +�����˵���չʾL·ǰSpring�����г�ʼ��������Bean������һ�£�������������һ��Bean������ȷ���Ƿ��ɹ�ɻ�������Dz��ǾͿ���ͨ�������˿ڲ�ѯһ���أ� + +��������L·�ж���һ��TestController����ע��һ��UserService�� + + +```` +@Controller +public class TestController { + + @Resource + private UserService userService; +} +```` + +����������yö˵㣬�ῴ��������Ϣ�� + +![image-20230530233805161](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233805161.png) + +���Կ���TestController��ɻ�����x�����������UserService�� + +## caches�˵� + +caches�˵���Ҫ���ڱ�¶Ӧ�ó����еĻ��塣������Spring Boot�ṩ��Cache������չʾһ��ɻ���� + +����L·�м���spring-boot-starter-cache������������ + + +```` + + org.springframework.boot + spring-boot-starter-cache + +```` + +Ȼ����������������@EnableCaching������湦�ܡ� + +����һ��CacheController�����䷽��queryAllʹ�û������ƣ� + + +```` +@RestController +public class CacheController { + + @RequestMapping("/queryAll") + @Cacheable(value = "queryAll") + public Map queryAll() { + Map map = new HashMap(); + map.put("1", "Tom"); + map.put("2", "Steven"); + return map; + } +} +```` + +����ʹ��@Cacheableע����ɻ�ֻ��湦�ܣ�������keyΪqueryAll����ɦ������[http://localhost:8080/actuator/caches](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fcaches "http://localhost:8080/actuator/caches") ����չʾ�����ĸ����ݣ������沢û�л��档 + +����һ��[http://localhost:8080/queryAll](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2FqueryAll "http://localhost:8080/queryAll") ��Ҳ���Ǵ���һ�»������ݵ����ɡ���ɦ�ۇٴ������������ӣ������Կ���Ӧ�ó����еĻ�����Ϣ�x� + +![image-20230530233852486](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233852486.png) + +���Կ��������ص����ݲ���չʾ��Ӧ�ó����Ļ�����������ͬɦҲչʾ�˻�����Key�ͻ������ݴ洢������Ϣ�� + +## caches-cache�˵� + +caches-cache�˵��Ƕ�����caches�˵�����չ��caches�˵�չʾ�����еĻ�����Ϣ��������ֱ�ӿ���������һ�����Ϣ��������ʹ��caches-cache�˵㡣 + +���ɻ�URLΪ��[http://localhost:8080/actuator/caches/{cache}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fcaches%2F%257Bcache%257D "http://localhost:8080/actuator/caches/%7Bcache%7D") �����д������ڵ�ֵ�����滻Ϊ������key�� + + + + +`http://localhost:8080/actuator/caches/queryAll` + +��������ռλ������queryAll��������key����ִ�н������£� + +![image-20230530233906164](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233906164.png) + +���Կ�����ֻ��ѯ����ָ���Ļ�����Ϣ����������������������ƣ�key���������Ĵ洢���͡� + +## health�˵� + +health�˵���������Ӧ�õ�����״̬������Ƶʹ�õ�һ���˵㡣����Ӧ��ɻ��������״̬�Լ�Ӧ�ò�����������ԭ�򣬱������ݿ����ӡ����̿ռ䲻���ȡ� + +���ɻ�ַ��[http://localhost:8080/actuator/health](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fhealth "http://localhost:8080/actuator/health") + +չʾ������ + +`{ +"status": "UP" +}` + +������ɻ�����ڼ򵥣�����L·�а����ݿ������ɽ�ȥ�� + +` + +```` + + org.springframework.boot + spring-boot-starter-jdbc + + + mysql + mysql-connector-java +` +```` + +Ȼ����application�����ļ��н������ã� + + + +``` +spring: + datasource: + url: jdbc:mysql://xxx:3333/xxx?characterEncoding=utf8&serverTimezone=Asia/Shanghai + username: root + password: root + driver-class-name: com.mysql.cj.jdbc.Driver +``` + +ͬɦ������Ҫ��application�����ļ�������һ��management.endpoint.health.show-details��ֵ����������������ѡ� + +* never ����չʾ��ϸ��Ϣ��up ���� down ��״̬��Ĭ�����ã� +* when-authorized����ϸ��Ϣ����չʾ��ͨ����֤���û�����Ȩ�Ľ�ɫ����ͨ��management.endpoint.health.roles ���ã� +* always���������û���¶��ϸ��Ϣ�� + +Ĭ��ֵ��never����������ֱ�ӷ��ʿ�����ֻ��UP��DOWN�����ڼ��������ݿ⣬ͬɦ�Ѹ���ֵ����Ϊalways����һ�����飺 + +![image-20230530233934501](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233934501.png) + +���Կ�������״̬ΪUP����������������������ΪUP�������ݿ���MYSQL���������ݿ�������Ϊ��SELECT 1����ͬɦ����չʾ�˴�����Ϣ��ping��״̬�� + +�������ǰ����ݿ����û��������������Ĵ��������ʿɵã� + +![image-20230530233951145](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530233951145.png) + +״̬ΪDOWN��������db���������⣬״̬ΪDOWN��������������error��չʾ�����Կ����ǽ�������ɦ�����l���ɻ���У����ǿ���ͨ��health�˿ڼ������ݿ⡢Redis��MongoDB�����̵Ƚ���������ActuatorԤ�����Ĵ�����Ϊ��DataSourceHealthIndicator, DiskSpaceHealthIndicator, MongoHealthIndicator, RedisHealthIndicator�ȡ� + +����ÿ��ָ�궼���Ե����Ľ��п����͹رգ������ݿ���Ϊ���� + + +```` +management: + health: + db: + enabled: true` +```` + +## info�˵� + +/info �˵������鿴�����ļ� application����info��ͷ��������Ϣ��Ĭ�������� application�в�û�� info �ڵ����ã�����Ĭ��Ϊ�ա� + +application�������������ã� + + + +```` +info: + user: + type: ���ں� + name: �������ӽ� + wechat: zhuan2quan +```` + +����[http://localhost:8080/actuator/info](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Finfo "http://localhost:8080/actuator/info") ��չʾ�������£� + +![image-20230530234019487](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234019487.png) + +## conditions�˵� + +Spring Boot�ṩ���Զ����ù��ܣ�ʹ�������dz����㡣����Щ�Զ���������jô��������Ч�ģ��Ƿ���Ч�DZȽ����Ų��ġ���ɦ������ʹ�� conditions ��Ӧ������ɦ�鿴ij����������jô��������Ч����Ϊjôû����Ч�� + +����URL��[http://localhost:8080/actuator/conditions](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fconditions "http://localhost:8080/actuator/conditions") �����ַ�����Ϣ���£� + +![image-20230530234053134](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234053134.png) + +���Կ���ij���Զ���������Ӧ����Ч��������ʾ��Ϣ�� + +## shutdown�˵� + +shutdown�˵����ڲ����������˵㣬�������Źر� Spring Boot Ӧ�á���Ҫ�������ļ��п����� + + +```` +management: + endpoint: + shutdown: + enabled: true +```` + +�ö˵�ֻ֧��POST������ִ��������ؽ������£� + + +``` +curl -X POST "http://localhost:8080/actuator/shutdown" +{ + "message": "Shutting down, bye..." +} +``` + +ִ��֮�󣬻ᷢ��Ӧ�ó����Ѿ����ر��l����ڸö˵����ر�Ӧ�ó���������ʹ������ҪС�ġ� + +## configprops�˵� + +��Spring Boot��L·�У����Ǿ������õ�@ConfigurationPropertiesע��������ע��һЩ���ԣ���configprops�˵�����������ʾ��Щ����ע����ע�������ࡣ + +����ǰ����info���ã����ǾͿ��Զ���һ����InfoProperties�� + + +```` +@Component +@ConfigurationProperties(prefix = "info") +public class InfoProperties { + + private String type; + + private String name; + + private String wechat; + + // ʡ��getter/setter +} +```` + +����URL��[http://localhost:8080/actuator/configprops](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fconfigprops "http://localhost:8080/actuator/configprops") ��������Ϣ���£� + +![image-20230530234110515](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234110515.png) + +�������Կ���εͳ��Ĭ�ϼ��ɵ���������Ϣ�������Կ��������Զ�������������Ϣ��������Ҫע�����Ƕ�Ӧ������Ҫ����ɻ������@Component���������ܹ������� + +�����Զ��������з�����Bean�����ơ�����ǰ׺��������ProjectInfoProperties��������������Ϣ�� + +## env�˵� + +env�˵����ڻ�ȡȫ���������ԣ�����application�����ļ��е����ݡ�εͳ�����ȡ� + +����URL��[http://localhost:8080/actuator/env�����ز�����Ϣ��](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%25EF%25BC%258C%25E8%25BF%2594%25E5%259B%259E%25E9%2583%25A8%25E5%2588%2586%25E4%25BF%25A1%25E6%2581%25AF%25EF%25BC%259A "http://localhost:8080/actuator/env%EF%BC%8C%E8%BF%94%E5%9B%9E%E9%83%A8%E5%88%86%E4%BF%A1%E6%81%AF%EF%BC%9A") + +![image-20230530234200949](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234200949.png) + +## env-toMatch�˵� + +env-toMatch�˵���caches��caches-cache���ƣ�һ���ǻ�ȡ���еģ�һ���ǻ�ȡָ���ġ�������env-toMatch�˵��ǻ�ȡָ��key�Ļ����������ԡ� + +������ʽΪ��[http://localhost:8080/actuator/env/{toMatch}��](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%2F%257BtoMatch%257D%25E3%2580%2582 "http://localhost:8080/actuator/env/%7BtoMatch%7D%E3%80%82") ɻ��URL��[http://localhost:8080/actuator/env/info.user.name](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fenv%2Finfo.user.name "http://localhost:8080/actuator/env/info.user.name") �����ؽ�������ͼ�� + +![image-20230530234238073](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234238073.png) + +����������Ϣ���������Ե���Դ��valueֵ����Ϣ�� + +## loggers�˵� + +/loggers �˵㱩¶�˳����ڲ����õ����� logger ����Ϣ��������ͬ��package����ͬ��������־������Ϣ�� + +����URL��[http://localhost:8080/actuator/loggers](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers "http://localhost:8080/actuator/loggers") �����ַ��ؽ����� + +![image-20230530234301625](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234301625.png) + +## loggers-name�˵� + +loggers-name�˵�Ҳ��logger�˵���ϸ�֣�����ͨ��name����ijһ��logger�� + +����������ʽ��[http://localhost:8080/actuator/loggers/{name}](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers%2F%257Bname%257D "http://localhost:8080/actuator/loggers/%7Bname%7D") ʾ������URL��[http://localhost:8080/actuator/loggers/com.secbro2.SpringbootActuatorApplication](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Floggers%2Fcom.secbro2.SpringbootActuatorApplication "http://localhost:8080/actuator/loggers/com.secbro2.SpringbootActuatorApplication") �����ؽ������£� + + + +`{ +"configuredLevel": null, +"effectiveLevel": "INFO" +}` + +���Կ���������������־����ΪINFO�� + +## heapdump�˵� + +heapdump�˵��᷵��һ��JVM ��dump��ͨ��JVM�Դ��ļ��ع���VisualVM�ɴ򿪴��ļ��鿴�ڴ����ա������ڴ��Ż������ڶ�ջ���������Ų��������� + +����URL��[http://localhost:8080/actuator/heapdump](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fheapdump "http://localhost:8080/actuator/heapdump") ��Mac����εͳ�����������ʻ�����һ������Ϊheapdump���ļ����޺�׺��30M�� + +������ִ��jvisualvm�������VisualVM�����ε������ļ�װ�롱���ǵ��ļ�����Ҫѡ�񡰶�Dump(_.hprof,_.*)����Ȼ��ѡ��heapdump�� + +![image-20230530234346098](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234346098.png) + +��ɦ������ͨ�����������ж�ջ��Ϣ�ķ����l��������������ķ����ṩ�˼�Ϊ�����ķ�ʽ�� + +## threaddump�˵� + +/threaddump �˵������ɵ�ǰ�̻߳�L·��ա����ճ���λ������ɦ���鿴�̵߳������dz����ã���Ҫչʾ���߳������߳�ID���̵߳�״̬���Ƿ��ȴ�����Դ����Ϣ�� + +����URL��[http://localhost:8080/actuator/threaddump](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fthreaddump "http://localhost:8080/actuator/threaddump") �����ַ��ؽ����� + +![image-20230530234405331](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234405331.png) + +���ǿ�ͨ���߳̿������Ų����������⡣ + +## metrics�˵� + +/metrics �˵�������¶��ǰӦ�õĸ�����Ҫ����ָ�꣬���磺�ڴ���Ϣ���߳���Ϣ������������Ϣ��tomcat�����ݿ����ӳصȡ�2.x�汾����ֻ��ʾ��һ��ָ�����б� + +����URL��[http://localhost:8080/actuator/metrics](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics "http://localhost:8080/actuator/metrics") �� + +```` +{ + "names": [ + "jvm.memory.max", + "jvm.threads.states", + "jvm.gc.pause", + "http.server.requests", + "process.files.max", + "jvm.gc.memory.promoted", + "system.load.average.1m", + "jvm.memory.used", + "jvm.gc.max.data.size", + "jvm.memory.committed", + "system.cpu.count", + "logback.events", + "jvm.buffer.memory.used", + "tomcat.sessions.created", + "jvm.threads.daemon", + "system.cpu.usage", + "jvm.gc.memory.allocated", + "tomcat.sessions.expired", + "jvm.threads.live", + "jvm.threads.peak", + "process.uptime", + "tomcat.sessions.rejected", + "process.cpu.usage", + "jvm.classes.loaded", + "jvm.classes.unloaded", + "tomcat.sessions.active.current", + "tomcat.sessions.alive.max", + "jvm.gc.live.data.size", + "process.files.open", + "jvm.buffer.count", + "jvm.buffer.total.capacity", + "tomcat.sessions.active.max", + "process.start.time" + ] +} +```` + +/metrics�˵������ṩӦ������״̬����������ָ�걨�棬����ܷdz���ɻ�ã����Ƕ��ڼ���εͳ�еĸ������ع��ܣ����ǵļ������ݡ������ռ�Ƶ�ʁ�������ͬ����������ÿ�ζ�ͨ��ȫ����ȡ�����ķ�ʽ���ռ������Դֱ����ۇٴ�Ҳ�ǿ����Ǵ��ڴ˷����L·��ǣ���Spring Boot 2.x֮����/metrics�˵�ֻ��ʾ��ָ�����б� + +������Ҫ�鿴������ij��ָ�꣬����ͨ��/metrics-requiredMetricName�˵���ɻ�֡� + +## metrics-requiredMetricName�˵� + +metrics-requiredMetricName�˵㣬���ڷ���ָ��ָ���ı��棬һ��������/metrics�˵��Ȳ���ָ���б�Ȼ���ٲ�ѯ������ij��ָ�ꡣ + +������ʽ��[http://localhost:8080/actuator/metrics/{requiredMetricName}��](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics%2F%257BrequiredMetricName%257D%25E3%2580%2582 "http://localhost:8080/actuator/metrics/%7BrequiredMetricName%7D%E3%80%82") ɻ��URL��[http://localhost:8080/actuator/metrics/jvm.memory.max](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmetrics%2Fjvm.memory.max "http://localhost:8080/actuator/metrics/jvm.memory.max") �����ؽ������£� + + +```` +{ + "name": "jvm.memory.max", + "description": "The maximum amount of memory in bytes that can be used for memory management", + "baseUnit": "bytes", + "measurements": [ + { + "statistic": "VALUE", + "value": 5606211583 + } + ], + "availableTags": [ + { + "tag": "area", + "values": [ + "heap", + "nonheap" + ] + }, + { + "tag": "id", + "values": [ + "Compressed Class Space", + "PS Survivor Space", + "PS Old Gen", + "Metaspace", + "PS Eden Space", + "Code Cache" + ] + } + ] +} +```` + +��������չʾ�����������ڴ�����������������ָ����չʾ�滻��Ӧ�����ֽ��в鿴���ɡ� + +## scheduledtasks�˵� + +/scheduledtasks�˵�����չʾӦ���еĶ�ɦ������Ϣ�� + +������L·�й���������ɦ������������������������@EnableScheduling������ɦ�������ܡ�Ȼ�󴴽���ɦ�����ࣺ + +```` +@Component +public class MyTask { + + @Scheduled(cron = "0/10 * * * * *") + public void work() { + System.out.println("I am a cron job."); + } + + @Scheduled(fixedDelay = 10000) + public void work1() { + System.out.println("I am a fixedDelay job."); + } +} +```` + +���ж������������͵Ķ�ɦ������work�ǻ���cronɻ�ֵĶ�ɦ������work1�ǻ���fixedDelayɻ�ֵĶ�ɦ������ + +����URL��[http://localhost:8080/actuator/scheduledtasks](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fscheduledtasks "http://localhost:8080/actuator/scheduledtasks") �����ؽ�����Ϣ���£� + +``` +{ + "cron": [ + { + "runnable": { + "target": "com.secbro2.job.MyTask.work" + }, + "expression": "0/10 * * * * *" + } + ], + "fixedDelay": [ + { + "runnable": { + "target": "com.secbro2.job.MyTask.work1" + }, + "initialDelay": 0, + "interval": 10000 + } + ], + "fixedRate": [], + "custom": [] +} +``` + +���Կ�����ͨ���ö˵�������ȷ��֪����ǰӦ���ж����Ķ�ɦ�������Լ�ִ��ģʽ��Ƶ�Ρ� + +## mappings�˵� + +/mappings�˵���������ȫ���� URI ·�����Լ��Ϳ�������ӳ����ε�������������DZȽϳ��õ��x�������εͳ�IJ鿴URL��Ӧ��Controller������������ʹ�ô˶˵㡣 + +����URL��[http://localhost:8080/actuator/mappings](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8080%2Factuator%2Fmappings "http://localhost:8080/actuator/mappings") �����ַ��ؽ������£� + +![image-20230530234501440](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230530234501440.png) + +���˹���Spring Boot Actuator�ṩ�����ж˵��������ϡ� + +## С�� + +����ͨ����Spring Boot Actuator�ṩ���ж˵㹹��ɻ������ʾ�����Ĵ��������ݺ�ɻ������ȫ����һ�����ϡ��ÿ��ܶ��Ų��������⣬�����Ż��ȶ��м����İ���������д���ĵĹ�����ҲԽ��Խ��̾Actuator�Ĺ���֮ǿ����ǿ���Ƽ��������� + +## �ο����� + +���ߣ��������ӽ� +���ӣ�https://juejin.cn/post/6984550846876876814 +��Դ��ϡ������ +����Ȩ���������С���ҵת������ε���߻�����Ȩ������ҵת����ע����� + diff --git a/docs/monitor/SpringBoot Admin.md b/docs/monitor/SpringBoot Admin.md new file mode 100644 index 0000000..7b0c8ab --- /dev/null +++ b/docs/monitor/SpringBoot Admin.md @@ -0,0 +1,495 @@ +## ժҪ + +Spring Boot Admin ���Զ�SpringBootӦ�õĸ���ָ�����м��أ�������Ϊ΢�����ܹ��еļ���������ʹ�ã����Ľ������÷�������ϸ���ܡ� + +## Spring Boot Admin ���� + +SpringBootӦ�ÿ���ͨ��Actuator����¶Ӧ�����й����еĸ���ָ�꣬Spring Boot Adminͨ����Щָ��������SpringBootӦ�ã�Ȼ��ͨ��ͼ�λ��������ֳ�����Spring Boot Admin�������Լ��ص���Ӧ�ã������Ժ�Spring Cloud��ע������������������΢����Ӧ�á� + +Spring Boot Admin �����ṩӦ�õ����1⁄4�����Ϣ�� + +* ����Ӧ�����й����еĸ�����Ϣ�� +* ����ָ����Ϣ������JVM��Tomcat��������Ϣ�� +* ����������Ϣ������εͳ���ԡ�εͳ���������Լ�Ӧ��������Ϣ�� +* �鿴���д�����Bean��Ϣ�� +* �鿴Ӧ���е�����������Ϣ�� +* �鿴Ӧ��������־��Ϣ�� +* �鿴JVM��Ϣ�� +* �鿴���Է��ɻ�Web�˵㣻 +* �鿴HTTP������Ϣ�� + +## ����admin-serverģ�� + +> �������Ǵ���һ��admin-serverģ������Ϊ����������ʾ�书�ܡ� + +* ��pom.xml���������������� + + + + + +```` + + org.springframework.boot + spring-boot-starter-web + + + de.codecentric + spring-boot-admin-starter-server + + +```` + +* ��application.yml�н������ã� + + + + + +````spring: + application: + name: admin-server +server: + port: 9301 +```` + +* ��������������@EnableAdminServer������admin-server���ܣ� + + + + +```` +@EnableAdminServer +@SpringBootApplication +public class AdminServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminServerApplication.class, args); + } + +} +```` + +## ����admin-clientģ�� + +> �������Ǵ���һ��admin-clientģ����Ϊ�ͻ���ע�ᵽadmin-server�� + +* ��pom.xml���������������� + + + +```` + + org.springframework.boot + spring-boot-starter-web + + + de.codecentric + spring-boot-admin-starter-client + +```` + +* ��application.yml�н������ã� + + + + + + + + +``` +spring: + application: + name: admin-client + boot: + admin: + client: + url: http://localhost:9301 #����admin-server��ַ +server: + port: 9305 +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always +logging: + file: admin-client.log #���ӿ���admin����־���� +``` + +* ����admin-server��admin-client������ + +## ������Ϣ��ʾ + +* �������μ�ַ����Spring Boot Admin����ҳ��[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001002163](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001002163.png) + + + + + +* ����wallboard��ť��ѡ��admin-client�鿴������Ϣ�� + +* ������Ϣ������ + +![image-20230531001023644](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001023644.png) + + + + + +* ����ָ����Ϣ������JVM��Tomcat��������Ϣ�� + +![image-20230531001053279](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001053279.png) + + + + + +* ����������Ϣ������εͳ���ԡ�εͳ���������Լ�Ӧ��������Ϣ�� + +![image-20230531001103093](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001103093.png) + + + + + +* �鿴���д�����Bean��Ϣ�� + +![image-20230531001111221](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001111221.png) + + + + + +* �鿴Ӧ���е�����������Ϣ�� + +![image-20230531001124678](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001124678.png) + + + + + +* �鿴��־��Ϣ����Ҫ�����������ò��ܿ����� + + + +`logging: +file: admin-client.log #���ӿ���admin����־����` + +![image-20230531001136184](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001136184.png) + + + + +* �鿴JVM��Ϣ�� + +![image-20230531001144614](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001144614.png) + + + + + +* �鿴���Է��ɻ�Web�˵㣻 + +![image-20230531001156191](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001156191.png) + + + + + +* �鿴HTTP������Ϣ�� + +![image-20230531001206364](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001206364.png) + + + + + +## ����ע������ʹ�� + +> Spring Boot Admin����Spring Cloud ע������ʹ�ã�ֻ�轫admin-server��ע���������ϼ��ɣ�admin-server ���Զ���ע�����Ļ�ȡ�����б�Ȼ�󰤸���ȡ������Ϣ��������Eurekaע������Ϊ��������� ̧ù��ܡ� + +### �޸�admin-server + +* ��pom.xml���������������� + + + + +```` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + +```` + +* ��application-eureka.yml�н������ã�ֻ������ע���������ü��ɣ� + + + + +```` +spring: + application: + name: admin-server +server: + port: 9301 +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +```` + +* ��������������@EnableDiscoveryClient�����÷���ע�Ṧ�ܣ� + + + + + +```` +`@EnableDiscoveryClient +@EnableAdminServer +@SpringBootApplication +public class AdminServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminServerApplication.class, args); + } + +} +```` + +### �޸�admin-client + +* ��pom.xml���������������� + + + +```` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + +```` + +* ��application-eureka.yml�н������ã�ɾ��ԭ����admin-server��ַ���ã�����ע���������ü��ɣ� + + + + + +``` +spring: + application: + name: admin-client +server: + port: 9305 +management: + endpoints: + web: + exposure: + include: '*' + endpoint: + health: + show-details: always +logging: + file: admin-client.log #���ӿ���admin����־���� +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +``` + +* ��������������@EnableDiscoveryClient�����÷���ע�Ṧ�ܣ� + + + + + +``` +@EnableDiscoveryClient +@SpringBootApplication +public class AdminClientApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminClientApplication.class, args); + } + +} +``` + +### ������ʾ + +* ����eureka-server��ʹ��application-eureka.yml��������admin-server��admin-client�� + +* �鿴ע�����ķ��ַ�������ע�᣺[http://localhost:8001/](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A8001%2F "http://localhost:8001/") + +![image-20230531001221519](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001221519.png) + + +* �鿴Spring Boot Admin ��ҳ���ֿ��Կ���������Ϣ��[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001232048](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001232048.png) + + +## ���ӵ�1⁄4��֤ + +> ���ǿ���ͨ����admin-server����Spring Security֧�������õ�1⁄4��֤���ܡ� + +### ����admin-security-serverģ�� + +* ��pom.xml���������������� + + + +``` + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + de.codecentric + spring-boot-admin-starter-server + 2.1.5 + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + +``` + +* ��application.yml�н������ã����õ�1⁄4�û��������룬����admin-security-server�ļ�����Ϣ�� + + + + + +``` +spring: + application: + name: admin-security-server + security: # ���õ�1⁄4�û��������� + user: + name: macro + password: 123456 + boot: # ����ʾadmin-security-server�ļ�����Ϣ + admin: + discovery: + ignored-services: ${spring.application.name} +server: + port: 9301 +eureka: + client: + register-with-eureka: true + fetch-registry: true + service-url: + defaultZone: http://localhost:8001/eureka/ +``` + +* ��SpringSecurity�������ã��Ա�admin-client����ע�᣺ + + + + + +scss + +���ƴ��� + + + + + +``` +/** + * Created by macro on 2019年9月30日. + */ +@Configuration +public class SecuritySecureConfig extends WebSecurityConfigurerAdapter { + private final String adminContextPath; + + public SecuritySecureConfig(AdminServerProperties adminServerProperties) { + this.adminContextPath = adminServerProperties.getContextPath(); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); + successHandler.setTargetUrlParameter("redirectTo"); + successHandler.setDefaultTargetUrl(adminContextPath + "/"); + + http.authorizeRequests() + //1.�������о�̬��Դ�͵�1⁄4ҳ���Թ������� + .antMatchers(adminContextPath + "/assets/**").permitAll() + .antMatchers(adminContextPath + "/login").permitAll() + .anyRequest().authenticated() + .and() + //2.���õ�1⁄4�͵dz�·�� + .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and() + .logout().logoutUrl(adminContextPath + "/logout").and() + //3.����http basic֧�֣�admin-clientע��ɦ��Ҫʹ�� + .httpBasic().and() + .csrf() + //4.��������cookie��csrf���� + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + //5.������Щ·����csrf�����Ա�admin-clientע�� + .ignoringAntMatchers( + adminContextPath + "/instances", + adminContextPath + "/actuator/**" + ); + } +} +``` + +* �޸������࣬����AdminServer��ע�ᷢ�ֹ��ܣ� + + + + + +``` +@EnableDiscoveryClient +@EnableAdminServer +@SpringBootApplication +public class AdminSecurityServerApplication { + + public static void main(String[] args) { + SpringApplication.run(AdminSecurityServerApplication.class, args); + } +} +``` + +* ����eureka-server��admin-security-server������Spring Boot Admin ��ҳ������Ҫ��1⁄4���ܷ��ʣ�[http://localhost:9301](https://link.juejin.cn?target=http%3A%2F%2Flocalhost%3A9301 "http://localhost:9301") + +![image-20230531001242361](https://java-tutorial.oss-cn-shanghai.aliyuncs.com/image-20230531001242361.png) + + + + + +## ʹ�õ���ģ�� + + + + + +``` +springcloud-learning +������ eureka-server -- eurekaע������ +������ admin-server -- admin�������ķ��� +������ admin-client -- admin�������ļ��ص�Ӧ�÷��� +������ admin-security-server -- ����1⁄4��֤��admin�������ķ���` +``` \ No newline at end of file diff --git "a/docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円346円266円210円346円201円257円347円232円204円347円224円237円344円272円247円344円270円216円346円266円210円350円264円271円 .md" "b/docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円346円266円210円346円201円257円347円232円204円347円224円237円344円272円247円344円270円216円346円266円210円350円264円271円.md" similarity index 100% rename from "docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円346円266円210円346円201円257円347円232円204円347円224円237円344円272円247円344円270円216円346円266円210円350円264円271円 .md" rename to "docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円346円266円210円346円201円257円347円232円204円347円224円237円344円272円247円344円270円216円346円266円210円350円264円271円.md" diff --git "a/docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円351円241円272円345円272円217円346円266円210円350円264円271円 .md" "b/docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円351円241円272円345円272円217円346円266円210円350円264円271円.md" similarity index 100% rename from "docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円351円241円272円345円272円217円346円266円210円350円264円271円 .md" rename to "docs/mq/RocketMQ/RocketMQ347円263円273円345円210円227円357円274円232円351円241円272円345円272円217円346円266円210円350円264円271円.md"

AltStyle によって変換されたページ (->オリジナル) /