diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java
index 24504e17d4..07c98ac4a7 100755
--- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java
+++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemBlockException.java
@@ -29,8 +29,8 @@ public SystemBlockException(String resourceName, String message, Throwable cause
this.resourceName = resourceName;
}
- public SystemBlockException(String resourceName, String limitType) {
- super(limitType);
+ public SystemBlockException(String resourceName, String limitType, SystemRule systemRule) {
+ super(limitType, systemRule);
this.resourceName = resourceName;
}
diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java
index 64d54be9e1..231aedb89c 100755
--- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java
+++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java
@@ -15,13 +15,6 @@
*/
package com.alibaba.csp.sentinel.slots.system;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
import com.alibaba.csp.sentinel.Constants;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.concurrent.NamedThreadFactory;
@@ -32,6 +25,15 @@
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper;
import com.alibaba.csp.sentinel.slots.block.BlockException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
*
* Sentinel System Rule makes the inbound traffic and capacity meet. It takes
@@ -88,6 +90,8 @@ public final class SystemRuleManager {
private final static SystemPropertyListener listener = new SystemPropertyListener();
private static SentinelProperty> currentProperty = new DynamicSentinelProperty>();
+ private static final Map ruleMap = new HashMap<>();
+
@SuppressWarnings("PMD.ThreadPoolCreationRule")
private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("sentinel-system-status-record-task", true));
@@ -247,6 +251,7 @@ public static void loadSystemConf(SystemRule rule) {
highestSystemLoad = Math.min(highestSystemLoad, rule.getHighestSystemLoad());
highestSystemLoadIsSet = true;
checkStatus = true;
+ ruleMap.put("load", rule);
}
if (rule.getHighestCpuUsage() >= 0) {
@@ -257,6 +262,7 @@ public static void loadSystemConf(SystemRule rule) {
highestCpuUsage = Math.min(highestCpuUsage, rule.getHighestCpuUsage());
highestCpuUsageIsSet = true;
checkStatus = true;
+ ruleMap.put("cpu", rule);
}
}
@@ -264,17 +270,20 @@ public static void loadSystemConf(SystemRule rule) {
maxRt = Math.min(maxRt, rule.getAvgRt());
maxRtIsSet = true;
checkStatus = true;
+ ruleMap.put("rt", rule);
}
if (rule.getMaxThread() >= 0) {
maxThread = Math.min(maxThread, rule.getMaxThread());
maxThreadIsSet = true;
checkStatus = true;
+ ruleMap.put("thread", rule);
}
if (rule.getQps() >= 0) {
qps = Math.min(qps, rule.getQps());
qpsIsSet = true;
checkStatus = true;
+ ruleMap.put("qps", rule);
}
checkSystemStatus.set(checkStatus);
@@ -304,30 +313,30 @@ public static void checkSystem(ResourceWrapper resourceWrapper, int count) throw
// total qps
double currentQps = Constants.ENTRY_NODE.passQps();
if (currentQps + count > qps) {
- throw new SystemBlockException(resourceWrapper.getName(), "qps");
+ throw new SystemBlockException(resourceWrapper.getName(), "qps", ruleMap.get("qps"));
}
// total thread
int currentThread = Constants.ENTRY_NODE.curThreadNum();
if (currentThread > maxThread) {
- throw new SystemBlockException(resourceWrapper.getName(), "thread");
+ throw new SystemBlockException(resourceWrapper.getName(), "thread", ruleMap.get("thread"));
}
double rt = Constants.ENTRY_NODE.avgRt();
if (rt > maxRt) {
- throw new SystemBlockException(resourceWrapper.getName(), "rt");
+ throw new SystemBlockException(resourceWrapper.getName(), "rt", ruleMap.get("rt"));
}
// load. BBR algorithm.
if (highestSystemLoadIsSet && getCurrentSystemAvgLoad() > highestSystemLoad) {
if (!checkBbr(currentThread)) {
- throw new SystemBlockException(resourceWrapper.getName(), "load");
+ throw new SystemBlockException(resourceWrapper.getName(), "load", ruleMap.get("load"));
}
}
// cpu usage
if (highestCpuUsageIsSet && getCurrentCpuUsage() > highestCpuUsage) {
- throw new SystemBlockException(resourceWrapper.getName(), "cpu");
+ throw new SystemBlockException(resourceWrapper.getName(), "cpu", ruleMap.get("cpu"));
}
}