From 1cbf0703bc5fd9083f498e57b0cceec2a19ae464 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 18 Nov 2025 11:21:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=B1=A0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=BF=9E=E6=8E=A5=E6=97=B6=E8=AE=B0=E5=BD=95=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1551594485678080]数据库连接池获取不到连接时记录线程信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1551594485678080 --- .../api/healthcheck/ClearExecutingSQLApi.java | 44 +++++++++++++++++ .../api/healthcheck/GetExecutingSQLApi.java | 48 +++++++++++++++++++ .../tenant/api/healthcheck/ThreadDumpApi.java | 42 +--------------- 3 files changed, 94 insertions(+), 40 deletions(-) create mode 100644 src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java create mode 100644 src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java new file mode 100644 index 00000000..93b48211 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java @@ -0,0 +1,44 @@ +/* + * + * Copyright (C) 2025 TechSure Co., Ltd. All Rights Reserved. + * This file is part of the NeatLogic software. + * Licensed under the NeatLogic Sustainable Use License (NSUL), Version 4.x – 2025. + * You may use this file only in compliance with the License. + * See the LICENSE file distributed with this work for the full license text. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +package neatlogic.module.tenant.api.healthcheck; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.ADMIN; +import neatlogic.framework.dao.plugin.ExecutingSQLInterceptor; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; + +@Service +@AuthAction(action = ADMIN.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class ClearExecutingSQLApi extends PrivateApiComponentBase { + + @Override + public String getName() { + return "清空正在执行的sql"; + } + + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + ExecutingSQLInterceptor.clearThread2ExecutingSQLMap(); + return null; + } + + @Override + public String getToken() { + return "/healthcheck/executingsql/clear"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java new file mode 100644 index 00000000..3bc87c92 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java @@ -0,0 +1,48 @@ +/* + * + * Copyright (C) 2025 TechSure Co., Ltd. All Rights Reserved. + * This file is part of the NeatLogic software. + * Licensed under the NeatLogic Sustainable Use License (NSUL), Version 4.x – 2025. + * You may use this file only in compliance with the License. + * See the LICENSE file distributed with this work for the full license text. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +package neatlogic.module.tenant.api.healthcheck; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.ADMIN; +import neatlogic.framework.dao.plugin.ExecutingSQLInterceptor; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; + +import java.util.Map; + +@Service +@AuthAction(action = ADMIN.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class GetExecutingSQLApi extends PrivateApiComponentBase { + + @Override + public String getName() { + return "查看正在执行的sql"; + } + + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + JSONObject resultObj = new JSONObject(); + Map thread2ExecutingSQLMap = ExecutingSQLInterceptor.getThread2ExecutingSQLMap(); + resultObj.put("executingSQLMap", thread2ExecutingSQLMap); + return resultObj; + } + + @Override + public String getToken() { + return "/healthcheck/executingsql/get"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/ThreadDumpApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/ThreadDumpApi.java index 2e27798b..213f7809 100644 --- a/src/main/java/neatlogic/module/tenant/api/healthcheck/ThreadDumpApi.java +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/ThreadDumpApi.java @@ -21,18 +21,10 @@ import neatlogic.framework.restful.annotation.Description; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.ThreadUtil; import org.springframework.stereotype.Service; -import java.io.IOException; import java.io.StringWriter; -import java.io.Writer; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; @Service @AuthAction(action = ADMIN.class) @@ -54,41 +46,11 @@ public class ThreadDumpApi extends PrivateApiComponentBase { return null; } - private static void dumpTraces(ThreadMXBean mxBean, Map threadInfoMap, Writer writer) throws IOException { - Map stacks = Thread.getAllStackTraces(); - long now = System.currentTimeMillis(); - writer.write("=================" + stacks.size() + " thread of " + RequestContext.get().getRequest().getLocalAddr() + " at " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z").format(new Date(now)) + " start.serverId is " + Config.SCHEDULE_SERVER_ID + "=================\n\n"); - for (Map.Entry entry : stacks.entrySet()) { - Thread thread = entry.getKey(); - writer.write("\"" + thread.getName() + "\" prio=" + thread.getPriority() + " tid=" + thread.getId() + " " + thread.getState() + " " + (thread.isDaemon() ? "deamon" : "worker")); - ThreadInfo threadInfo = threadInfoMap.get(thread.getId()); - if (threadInfo != null) { - writer.write(" native=" + threadInfo.isInNative() + ", suspended=" + threadInfo.isSuspended() + ", block=" + threadInfo.getBlockedCount() + ", wait=" + threadInfo.getWaitedCount()); - writer.write(" lock=" + threadInfo.getLockName() + " owned by " + threadInfo.getLockOwnerName() + " (" + threadInfo.getLockOwnerId() + "), cpu=" + (mxBean.getThreadCpuTime(threadInfo.getThreadId()) / 1000000L) + ", user=" + (mxBean.getThreadUserTime(threadInfo.getThreadId()) / 1000000L) + "\n"); - } - for (StackTraceElement element : entry.getValue()) { - writer.write("\t\t"); - writer.write(element.toString()); - writer.write("\n"); - } - writer.write("\n"); - } - writer.write("=================" + stacks.size() + " thread of " + RequestContext.get().getUrl() + " at " + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z").format(new Date(now)) + " end.=================\n\n"); - - } - @Description(desc = "打印线程快照接口") @Override public Object myDoService(JSONObject paramObj) throws Exception { - ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); - ThreadInfo[] threadInfos = mxBean.getThreadInfo(mxBean.getAllThreadIds(), 0); - Map threadInfoMap = new HashMap<>(); - for (ThreadInfo threadInfo : threadInfos) { - threadInfoMap.put(threadInfo.getThreadId(), threadInfo); - } - StringWriter writer = new StringWriter(); - dumpTraces(mxBean, threadInfoMap, writer); + ThreadUtil.dumpTraces(writer); return writer.toString(); } } -- Gitee From a55ae3883eab0e4fd748a43d229142641759e7fa Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 18 Nov 2025 12:02:47 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=B1=A0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=BF=9E=E6=8E=A5=E6=97=B6=E8=AE=B0=E5=BD=95=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1551594485678080]数据库连接池获取不到连接时记录线程信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1551594485678080 --- .../tenant/api/healthcheck/GetExecutingSQLApi.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java index 3bc87c92..826289c7 100644 --- a/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java @@ -16,9 +16,12 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.ADMIN; import neatlogic.framework.dao.plugin.ExecutingSQLInterceptor; +import neatlogic.framework.dto.healthcheck.DataSourceInfoVo; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.store.mysql.DatasourceManager; +import neatlogic.framework.store.mysql.NeatLogicBasicDataSource; import org.springframework.stereotype.Service; import java.util.Map; @@ -38,6 +41,16 @@ public class GetExecutingSQLApi extends PrivateApiComponentBase { JSONObject resultObj = new JSONObject(); Map thread2ExecutingSQLMap = ExecutingSQLInterceptor.getThread2ExecutingSQLMap(); resultObj.put("executingSQLMap", thread2ExecutingSQLMap); + NeatLogicBasicDataSource datasource = DatasourceManager.getDatasource(); + DataSourceInfoVo dataSourceInfoVo = new DataSourceInfoVo(); + dataSourceInfoVo.setPoolName(datasource.getPoolName()); + if (datasource.getHikariPoolMXBean() != null) { + dataSourceInfoVo.setIdleConnections(datasource.getHikariPoolMXBean().getIdleConnections()); + dataSourceInfoVo.setActiveConnections(datasource.getHikariPoolMXBean().getActiveConnections()); + dataSourceInfoVo.setThreadsAwaitingConnection(datasource.getHikariPoolMXBean().getThreadsAwaitingConnection()); + dataSourceInfoVo.setTotalConnections(datasource.getHikariPoolMXBean().getTotalConnections()); + } + resultObj.put("dataSourceInfoVo", dataSourceInfoVo); return resultObj; } -- Gitee From 8d8772c72e902fb62a2819cf6cf94b277a76b2b8 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Wed, 19 Nov 2025 08:23:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=B1=A0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=BF=9E=E6=8E=A5=E6=97=B6=E8=AE=B0=E5=BD=95=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1551594485678080]数据库连接池获取不到连接时记录线程信息 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1551594485678080 --- .../module/tenant/api/healthcheck/ClearExecutingSQLApi.java | 4 ++-- .../module/tenant/api/healthcheck/GetExecutingSQLApi.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java index 93b48211..00f3b9c4 100644 --- a/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/ClearExecutingSQLApi.java @@ -15,10 +15,10 @@ package neatlogic.module.tenant.api.healthcheck; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.ADMIN; -import neatlogic.framework.dao.plugin.ExecutingSQLInterceptor; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.store.mysql.SQLTransientConnectionExceptionAudit; import org.springframework.stereotype.Service; @Service @@ -33,7 +33,7 @@ public class ClearExecutingSQLApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { - ExecutingSQLInterceptor.clearThread2ExecutingSQLMap(); + SQLTransientConnectionExceptionAudit.clearExecutingSQL(); return null; } diff --git a/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java index 826289c7..76b27a18 100644 --- a/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java +++ b/src/main/java/neatlogic/module/tenant/api/healthcheck/GetExecutingSQLApi.java @@ -15,13 +15,13 @@ package neatlogic.module.tenant.api.healthcheck; import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.ADMIN; -import neatlogic.framework.dao.plugin.ExecutingSQLInterceptor; import neatlogic.framework.dto.healthcheck.DataSourceInfoVo; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.store.mysql.DatasourceManager; import neatlogic.framework.store.mysql.NeatLogicBasicDataSource; +import neatlogic.framework.store.mysql.SQLTransientConnectionExceptionAudit; import org.springframework.stereotype.Service; import java.util.Map; @@ -39,8 +39,8 @@ public class GetExecutingSQLApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { JSONObject resultObj = new JSONObject(); - Map thread2ExecutingSQLMap = ExecutingSQLInterceptor.getThread2ExecutingSQLMap(); - resultObj.put("executingSQLMap", thread2ExecutingSQLMap); + Map executingSQLMap = SQLTransientConnectionExceptionAudit.getExecutingSQL(); + resultObj.put("executingSQLMap", executingSQLMap); NeatLogicBasicDataSource datasource = DatasourceManager.getDatasource(); DataSourceInfoVo dataSourceInfoVo = new DataSourceInfoVo(); dataSourceInfoVo.setPoolName(datasource.getPoolName()); -- Gitee