alibaba / alibaba/Sentinel

当添加流控规则后,控制台无法监控应用

Open
#3,518 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
23.1k
Forks
8.1k
PR merge metrics
No merged PRs in 30d

Description

### Bug 描述

在使用sentinel的组件时,碰到了控制台无法监控应用。

### 环境

环境:"java11,spring boot2.7"

sentinel的依赖是:

```xml


com.alibaba.cloud
spring-cloud-starter-alibaba-sentinel
2021.0.5.0

```

配置文件为:

```yaml
spring:
cloud:
sentinel:
transport:
dashboard: 127.0.0.1:8858
port: 8719 # Sentinel客户端暴露的监控端口,默认为8719
client-ip: 127.0.0.1
enabled: true
```

sentinel控制台与项目运行在本地电脑上。

### 问题详细:

在项目中编写了sentinel的流控规则后,控制台就无法监控应用,但是流控规则是生效的,就是控制台监控不了应用了,但是把流控规则去掉后就能监控应用了

![Image](https://github.com/user-attachments/assets/6716e234-1602-4c81-981e-2fd895d4fb81)

------

在代码中设置sentinel的流控与熔断规则:

```java
@Component
public class SentinelRulesManager {

@PostConstruct
public void initRules() {
initFlowRules(); // 当我注释这个流控规则后,控制台就能监控应用了
initDegradeRules();
}

// 限流规则
public void initFlowRules() {
FlowRule flowRule = new FlowRule();
flowRule.setResource("listQuestionVOByPage");
flowRule.setCount(2);
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
flowRule.setLimitApp("default");
flowRule.setStrategy(RuleConstant.STRATEGY_DIRECT);
FlowRuleManager.loadRules(Collections.singletonList(flowRule));

}

// 降级规则
public void initDegradeRules() {
// 单 IP 查看题目列表熔断规则
DegradeRule slowCallRule = new DegradeRule("listQuestionVOByPage")
.setGrade(CircuitBreakerStrategy.SLOW_REQUEST_RATIO.getType())
.setCount(0.2) // 慢调用比例大于 20%
.setTimeWindow(10) // 熔断持续时间 60 秒
.setStatIntervalMs(30 * 1000) // 统计时长 30 秒
.setMinRequestAmount(5) // 最小请求数
.setSlowRatioThreshold(3); // 响应时间超过 3 秒

DegradeRule errorRateRule = new DegradeRule("listQuestionVOByPage")
.setGrade(CircuitBreakerStrategy.ERROR_RATIO.getType())
.setCount(0.1) // 异常率大于 10%
.setTimeWindow(10) // 熔断持续时间 60 秒
.setStatIntervalMs(30 * 1000) // 统计时长 30 秒
.setMinRequestAmount(5); // 最小请求数

// 加载规则
DegradeRuleManager.loadRules(Arrays.asList(slowCallRule, errorRateRule));
}
}
```

### 错误信息:

然后控制台就报错如下:

```shell
2025-04-18 12:43:20.872 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:27.867 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:34.873 ERROR 51776 --- [pool-2-thread-1] c.a.c.s.dashboard.metric.MetricFetcher : Failed to fetch metric from (ConnectionException: Connection refused: no further information)
2025-04-18 12:43:37.613 ERROR 51776 --- [pool-1-thread-1] c.a.c.s.d.client.SentinelApiClient : HTTP request failed: http://127.0.0.1:8720/jsonTree?type=root
java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946) ~[na:na]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) ~[httpcore-nio-4.4.6.jar!/:4.4.6]
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) ~[httpasyncclient-4.1.3.jar!/:4.1.3]
at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) ~[httpasyncclient-4.1.3.jar!/:4.1.3]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2025-04-18 12:43:37.613 ERROR 51776 --- [nio-8858-exec-8] c.a.c.s.d.client.SentinelApiClient : Error when fetching items from api: jsonTree -> root

java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused: no further information
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396) ~[na:na]
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073) ~[na:na]
at com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient.fetchItems(SentinelApiClient.java:383) ~[classes!/:na]
at com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient.fetchResourceOfMachine(SentinelApiClient.java:450) ~[classes!/:na]
at com.alibaba.csp.sentinel.dashboard.controller.ResourceController.fetchResourceChainListOfMachine(ResourceController.java:70) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.