# sentinel-dashboard-dynamic **Repository Path**: FibonacciCode/sentinel-dashboard-dynamic ## Basic Information - **Project Name**: sentinel-dashboard-dynamic - **Description**: sentinel-dashboard 动态数据源 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2022-01-12 - **Last Updated**: 2022-01-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 1.简介 原始的Sentinel-Dashboard的配置默认放在内存中的,并通过openapi通知应用。当Sentinel-Dashboard或者应用重启时,总是会丢失一部分数据,这是不友好的。 给Sentinel-Dashboard添加动态数据源,就可以解决这部分问题,详情请参考[官方文档](https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9)。 ![](https://user-images.githubusercontent.com/9434884/53381986-a0b73f00-39ad-11e9-90cf-b49158ae4b6f.png) ### 2.主要功能 - Nacos作为Sentinel-Dashboard的数据源 - Apollo作为Sentinel-Dashboard的数据源 #### 2.1 Nacos-Sentinel-Dashboard - 启动服务端 ```bash java -Dserver.port=8080 \ -Dproject.name=sentinel-dashboard \ -Dcsp.sentinel.dashboard.server=localhost:8080 \ -Dsentinel.datasource.mode=nacos \ -Dsentinel.dashboard.datasource.nacos.serverAddr=127.0.0.1:8848 \ -Dsentinel.dashboard.datasource.nacos.namespace=namespace \ -Dsentinel.dashboard.datasource.nacos.username=nacos \ -Dsentinel.dashboard.datasource.nacos.password=nacos \ -jar sentinel-dashboard.jar ``` - 创建Nacos配置文件 在Nacos指定命名空间中按需创建sentinel-dashboard的配置文件 - 1. ${application}-sentinel-flow - 2. ${application}-sentinel-param-flow - 3. ${application}-sentinel-system - 4. ${application}-sentinel-degrade - 5. ${application}-sentinel-authority - 6. ${application}-sentinel-gateway-flow - 7. ${application}-sentinel-gateway-api - 客户端配置Nacos监听 在sentinel-dashboard中修改配置以后,会同步到Nacos中,再由Nacos实时通知到应用端,应用端收到数据后,更新规则。 #### 2.2 Nacos-Sentinel-Dashboard - 启动服务端 ```bash java -Dserver.port=8080 \ -Dproject.name=sentinel-dashboard \ -Dcsp.sentinel.dashboard.server=localhost:8080 \ -Dsentinel.datasource.mode=apollo \ -Dsentinel.dashboard.datasource.apollo.portalUrl=http://dev.apollo.kancy.com \ -Dsentinel.dashboard.datasource.apollo.token=423670ef5234331eaebae5a1ed9c379c00f3cef6 \ -Dsentinel.dashboard.datasource.apollo.appId=sentinel-dashboard \ -Dsentinel.dashboard.datasource.apollo.env=dev \ -Dsentinel.dashboard.datasource.apollo.clusterName=default \ -jar sentinel-dashboard.jar ``` - 初始化Apollo - 创建一个项目,默认appId为sentinel-dashboard - 根据应用名创建命名空间:${application}.properties (应用引用) - 客户端配置Apollo监听 在sentinel-dashboard中修改配置以后,会同步到Apollo中,再由Apollo实时通知到应用端,应用端收到数据后,更新规则。 ### 3.修改记录 > 当前版本: v1.7.2 #### 3.1 修改类 - `com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController` - `com.alibaba.csp.sentinel.dashboard.controller.DegradeController` - `com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1` - `com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController` - `com.alibaba.csp.sentinel.dashboard.controller.SystemController` - `com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController` - `com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController` - `com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2` #### 3.2 修改资源 - resources/app/scripts/directives/sidebar/sidebar.html - pom.xml #### 3.3 新增类 ```text └─com └─alibaba └─csp └─sentinel └─dashboard └─rule │ AbstractDynamicRuleService.java │ DynamicRuleService.java │ ├─apollo │ │ AuthorityRuleApolloService.java │ │ DegradeRuleApolloService.java │ │ DynamicRuleApolloService.java │ │ FlowRuleApolloService.java │ │ GatewayApiRuleApolloService.java │ │ GatewayFlowRuleApolloService.java │ │ ParamFlowRuleApolloService.java │ │ SystemRuleApolloService.java │ │ │ └─config │ ApolloConfiguration.java │ ApolloProperties.java │ └─nacos │ AuthorityRuleNacosService.java │ DegradeRuleNacosService.java │ DynamicRuleNacosService.java │ FlowRuleNacosService.java │ GatewayApiRuleNacosService.java │ GatewayFlowRuleNacosService.java │ ParamFlowRuleNacosService.java │ SystemRuleNacosService.java │ └─config NacosConfiguration.java NacosProperties.java ```