Bladeren bron

:sparkles: 添加新特性。 解决spring boot admin 只保存最近事件

冷冷 6 jaren geleden
bovenliggende
commit
3f44a50980

+ 5 - 0
pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/CommonConstant.java

@@ -71,4 +71,9 @@ public interface CommonConstant {
 	 * 路由存放
 	 */
 	String ROUTE_KEY = "gateway_route_key";
+
+	/**
+	 * spring boot admin 事件key
+	 */
+	String EVENT_KEY = "event_key";
 }

+ 4 - 24
pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/dto/UserInfo.java

@@ -20,6 +20,8 @@
 package com.pig4cloud.pigx.admin.api.dto;
 
 import com.pig4cloud.pigx.admin.api.entity.SysUser;
+import lombok.Data;
+import lombok.ToString;
 
 import java.io.Serializable;
 
@@ -33,6 +35,8 @@ import java.io.Serializable;
  * commit('SET_INTRODUCTION', data)
  * commit('SET_PERMISSIONS', data)
  */
+@Data
+@ToString
 public class UserInfo implements Serializable {
 	/**
 	 * 用户基本信息
@@ -47,28 +51,4 @@ public class UserInfo implements Serializable {
 	 * 角色集合
 	 */
 	private Integer[] roles;
-
-	public SysUser getSysUser() {
-		return sysUser;
-	}
-
-	public void setSysUser(SysUser sysUser) {
-		this.sysUser = sysUser;
-	}
-
-	public String[] getPermissions() {
-		return permissions;
-	}
-
-	public void setPermissions(String[] permissions) {
-		this.permissions = permissions;
-	}
-
-	public Integer[] getRoles() {
-		return roles;
-	}
-
-	public void setRoles(Integer[] roles) {
-		this.roles = roles;
-	}
 }

+ 15 - 0
pigx-visual/pigx-monitor/pom.xml

@@ -33,12 +33,27 @@
 	<description>pigx 监控模块,基于 spring boot admin</description>
 
 	<dependencies>
+		<dependency>
+			<groupId>com.pig4cloud</groupId>
+			<artifactId>pigx-common-core</artifactId>
+			<version>1.7.0</version>
+		</dependency>
+		<dependency>
+			<groupId>com.pig4cloud</groupId>
+			<artifactId>pigx-common-cache</artifactId>
+			<version>1.7.0</version>
+		</dependency>
 		<!--监控服务端-->
 		<dependency>
 			<groupId>de.codecentric</groupId>
 			<artifactId>spring-boot-admin-starter-server</artifactId>
 			<version>${monitor.version}</version>
 		</dependency>
+		<!--Redis-->
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
+		</dependency>
 		<!--配置中心客户端-->
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>

+ 55 - 0
pigx-visual/pigx-monitor/src/main/java/com/pig4cloud/pigx/monitor/support/RedisEventStore.java

@@ -0,0 +1,55 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.monitor.support;
+
+import com.pig4cloud.pigx.common.core.constant.CommonConstant;
+import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
+import de.codecentric.boot.admin.server.eventstore.InMemoryEventStore;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import reactor.core.publisher.Mono;
+
+import java.util.List;
+
+/**
+ * @author lengleng
+ * @date 2018/11/12
+ * <p>
+ * redis store event
+ * default 100
+ */
+@Slf4j
+@Configuration
+public class RedisEventStore extends InMemoryEventStore {
+	@Autowired
+	private RedisTemplate redisTemplate;
+
+	@Override
+	public Mono<Void> append(List<InstanceEvent> events) {
+		events.forEach(event -> {
+			String key = event.getInstance().getValue() + "_" + event.getTimestamp().toString();
+			log.info("保存实例事件的KEY:{},EVENT: {}", key, event.getType());
+			redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(InstanceEvent.class));
+			redisTemplate.opsForHash().put(CommonConstant.EVENT_KEY, key, event);
+		});
+		return super.append(events);
+	}
+}