Skip to content

Commit

Permalink
fixed: issues/5 and issues/6
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyindaxiaojie committed Sep 25, 2023
1 parent 4464058 commit 8ef192e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ sentinel.rule.type=nacos
sentinel.rule.nacos.server-addr=localhost:8848
sentinel.rule.nacos.namespace=demo
sentinel.rule.nacos.group-id=sentinel
sentinel.rule.nacos.username=nacos
sentinel.rule.nacos.password=nacos
# Apollo 存储规则,如果您设置了 sentinel.metrics.type=apollo,需要调整相关配置
sentinel.rule.apollo.portal-url=http://localhost:10034
sentinel.rule.apollo.token=
Expand Down
15 changes: 15 additions & 0 deletions sentinel-dashboard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<!-- 存储流控规则 -->
<apollo.version>1.2.0</apollo.version>
<curator.version>4.0.1</curator.version>
<nacos.version>2.2.3</nacos.version>

<!-- 存储监控数据 -->
<spring-kafka.version>2.9.1</spring-kafka.version>
Expand Down Expand Up @@ -96,6 +97,12 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -193,6 +200,10 @@
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down Expand Up @@ -360,6 +371,10 @@
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>commons-codec</artifactId>
<groupId>commons-codec</groupId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.*;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.*;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down Expand Up @@ -50,8 +52,13 @@ public NacosRuleAutoConfiguration(NacosRuleProperties nacosRuleProperties) {
@Bean
public ConfigService nacosConfigService() throws Exception {
Properties properties = new Properties();
properties.put("serverAddr", nacosRuleProperties.getServerAddr());
properties.put("namespace", nacosRuleProperties.getNamespace());
properties.put(PropertyKeyConst.SERVER_ADDR, nacosRuleProperties.getServerAddr());
properties.put(PropertyKeyConst.NAMESPACE, nacosRuleProperties.getNamespace());
if (StringUtils.isNotBlank(nacosRuleProperties.getUsername()) &&
StringUtils.isNotBlank(nacosRuleProperties.getPassword())) {
properties.put(PropertyKeyConst.USERNAME, nacosRuleProperties.getUsername());
properties.put(PropertyKeyConst.PASSWORD, nacosRuleProperties.getPassword());
}
return ConfigFactory.createConfigService(properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public class NacosRuleProperties {
*/
private String groupId = "SENTINEL_GROUP";

/**
* Nacos 用户名
*/
private String username = "nacos";

/**
* Nacos 密码
*/
private String password = "nacos";

/**
* Nacos DataId 后缀
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.alibaba.csp.sentinel.dashboard.repository.metric.MetricsRepository;
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.StringUtil;
import com.google.common.collect.Lists;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.query.FluxRecord;
Expand Down Expand Up @@ -85,7 +84,7 @@ public void saveAll(Iterable<MetricEntity> metrics) {
*/
@Override
public List<MetricEntity> queryByAppAndResourceBetween(String app, String resource, long startTime, long endTime) {
List<MetricEntity> results = Lists.newArrayList();
List<MetricEntity> results = new ArrayList<>();
if (StringUtil.isBlank(app)) {
return results;
}
Expand Down Expand Up @@ -125,7 +124,7 @@ private String toDurationStr(long selected, Instant now) {
*/
@Override
public List<String> listResourcesOfApp(String app) {
List<String> results = Lists.newArrayList();
List<String> results = new ArrayList<>();
if (StringUtil.isBlank(app)) {
return results;
}
Expand Down
8 changes: 5 additions & 3 deletions sentinel-dashboard/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ sentinel.dashboard.unhealthy-machine-millis=30000
sentinel.dashboard.auto-remove-machine-millis=60000

# \u89C4\u5219\u5B58\u50A8\u7C7B\u578B\uFF0C\u53EF\u9009\u9879\uFF1Amemory\uFF08\u9ED8\u8BA4\uFF09\u3001nacos\uFF08\u63A8\u8350\uFF09\u3001apollo\u3001zookeeper
sentinel.rule.type=zookeeper
sentinel.rule.type=nacos
# Nacos \u5B58\u50A8\u89C4\u5219\uFF0C\u5982\u679C\u60A8\u8BBE\u7F6E\u4E86 sentinel.metrics.type=nacos\uFF0C\u9700\u8981\u8C03\u6574\u76F8\u5173\u914D\u7F6E
sentinel.rule.nacos.server-addr=localhost:8848
sentinel.rule.nacos.namespace=demo
sentinel.rule.nacos.group-id=sentinel
sentinel.rule.nacos.username=nacos
sentinel.rule.nacos.password=nacos
# Apollo \u5B58\u50A8\u89C4\u5219\uFF0C\u5982\u679C\u60A8\u8BBE\u7F6E\u4E86 sentinel.metrics.type=apollo\uFF0C\u9700\u8981\u8C03\u6574\u76F8\u5173\u914D\u7F6E
sentinel.rule.apollo.portal-url=http://localhost:10034
sentinel.rule.apollo.token=
Expand All @@ -56,9 +58,9 @@ sentinel.rule.zookeeper.connect-string=localhost:2181
sentinel.rule.zookeeper.root-path=/sentinel

# \u76D1\u63A7\u5B58\u50A8\u7C7B\u578B\uFF0C\u53EF\u9009\u9879\uFF1Amemory\uFF08\u9ED8\u8BA4\uFF09\u3001influxdb\uFF08\u63A8\u8350\uFF09\u3001elasticsearch
sentinel.metrics.type=influxdb
sentinel.metrics.type=memory
# InfluxDB \u5B58\u50A8\u76D1\u63A7\u6570\u636E\uFF0C\u5982\u679C\u60A8\u8BBE\u7F6E\u4E86 sentinel.metrics.type=influxdb\uFF0C\u9700\u8981\u8C03\u6574\u76F8\u5173\u914D\u7F6E
influx.url=http://10.2.2.44:8086/
influx.url=http://lcoalhost:8086/
influx.token=UfgaW37A93PkncmJum25G7M2QkBg6xqqjGthh-o-UIVIynC_-Q7RFWlTtEpMqhGLCuAsX64k3Isc2uN33YgElw==
influx.org=sentinel
influx.bucket=sentinel
Expand Down

0 comments on commit 8ef192e

Please sign in to comment.