网关流量控制使用阿里流量哨兵神器sentinel控制台实践验证过程

作者: admin 分类: Tools 发布时间: 2019-04-28 23:10  阅读: 486 views

在网关或其他web层项目使用过程中,为了抵御流量攻击,或者降低高流量带来的系统压力,需要做一些技术措施来做处理。这里可以用阿里的哨兵神器 sentinel,简单方便,而且有控制台可以对限流规则做调整。对于流量做整体控制、并发控制或者是拒绝策略十分方便。查看官方网站:https://github.com/alibaba/Sentinel/wiki/介绍

 

sentinel使用操作步骤
1.项目添加依赖包
2.下载sentinel控制台jar并启动
3.启动项目,并添加控制台参数
4.看到效果

 

1.项目pom文件添加依赖配置

<!--流控核心jar -->
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-core</artifactId>
	<version>1.4.1</version>
</dependency>
<!--流控控制台核心jar -->
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-transport-simple-http</artifactId>
	<version>1.4.1</version>
</dependency>
<!--流控控制台核心jar相关依赖 -->
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-transport-common</artifactId>
	<version>1.4.1</version>
</dependency>
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>fastjson</artifactId>
	<!-- <version>1.2.54</version> -->
</dependency>
<dependency>
	<groupId>com.alibaba.csp</groupId>
	<artifactId>sentinel-datasource-extension</artifactId>
	<version>1.4.1</version>
</dependency>

下载包的时候没有注意依赖包,导致一直无法成功。后来添加依赖jar包解决了客户端不显示问题

2.下载sentinel控制台的jar包,和项目使用的版本要保持一致

a. 启动控制台
java 
-Dserver.port=8080
-Dcsp.sentinel.dashboard.server=localhost:8080 
-Dproject.name=xxb 
-Dcsp.sentinel.api.port=8719 
-jar sentinel-dashboard-1.4.1.jar

-Dserver.port为控制台端口;
-Dcsp.sentinel.dashboard.server为指定控制台IP、端口(端口和前面的要保持一致);
-Dproject.name为接入名称;
-Dcsp.sentinel.api.port为监听端口(默认为8719,可以不写);

启动日志如下:

chenhailongdeMacBook-Pro:Downloads chenhailong$ java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=xxb -jar sentinel-dashboard-1.4.1.jar
INFO: log base dir is: /Users/chenhailong/logs/csp/
INFO: log name use pid is: false
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::        (v2.0.5.RELEASE)

2019-01-31 16:41:01 [main] INFO  c.t.c.s.d.DashboardApplication - Starting DashboardApplication on chenhailongdeMacBook-Pro.local with PID 49750 (/Users/chenhailong/Downloads/sentinel-dashboard-1.4.1.jar started by chenhailong in /Users/chenhailong/Downloads)
2019-01-31 16:41:01 [main] INFO  c.t.c.s.d.DashboardApplication - No active profile set, falling back to default profiles: default
2019-01-31 16:41:01 [main] INFO  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Thu Jan 31 16:41:01 CST 2019]; root of context hierarchy
2019-01-31 16:41:03 [main] INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
2019-01-31 16:41:03 [main] INFO  o.a.catalina.core.StandardService - Starting service [Tomcat]
2019-01-31 16:41:03 [main] INFO  o.a.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/8.5.34
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.a.c.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/chenhailong/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1889 ms
2019-01-31 16:41:03 [localhost-startStop-1] INFO  c.t.c.s.dashboard.config.WebConfig - Sentinel servlet CommonFilter registered
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.FilterRegistrationBean - Mapping filter: 'sentinelFilter' to urls: [/*]
2019-01-31 16:41:03 [localhost-startStop-1] INFO  o.s.b.w.s.ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]
2019-01-31 16:41:04 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Thu Jan 31 16:41:01 CST 2019]; root of context hierarchy
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/config/modify_single],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Boolean> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterConfigController.apiModifyClusterConfig(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/state_single],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterConfigController.apiGetClusterState(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/server_state/{app}],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO>> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterConfigController.apiGetClusterServerStateOfApp(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/client_state/{app}],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO>> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterConfigController.apiGetClusterClientStateOfApp(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/state/{app}],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO>> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterConfigController.apiGetClusterStateOfApp(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/paramFlow/rules],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity>> com.taobao.csp.sentinel.dashboard.view.ParamFlowRuleController.apiQueryAllRulesForMachine(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/paramFlow/rule],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.ParamFlowRuleController.apiAddParamFlowRule(com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/paramFlow/rule/{id}],methods=[PUT]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.ParamFlowRuleController.apiUpdateParamFlowRule(java.lang.Long,com.taobao.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/paramFlow/rule/{id}],methods=[DELETE]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Long> com.taobao.csp.sentinel.dashboard.view.ParamFlowRuleController.apiDeleteRule(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/authority/rules],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity>> com.taobao.csp.sentinel.dashboard.view.AuthorityRuleController.apiQueryAllRulesForMachine(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/authority/rule/{id}],methods=[PUT]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.taobao.csp.sentinel.dashboard.view.AuthorityRuleController.apiUpdateParamFlowRule(java.lang.Long,com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/authority/rule/{id}],methods=[DELETE]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Long> com.taobao.csp.sentinel.dashboard.view.AuthorityRuleController.apiDeleteRule(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/authority/rule],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.taobao.csp.sentinel.dashboard.view.AuthorityRuleController.apiAddAuthorityRule(com.taobao.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/demo/link],produces=[application/json]}" onto public java.lang.String com.taobao.csp.sentinel.dashboard.view.DemoController.link() throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/demo/loop],produces=[application/json]}" onto public java.lang.String com.taobao.csp.sentinel.dashboard.view.DemoController.loop(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/demo/greeting],produces=[application/json]}" onto public java.lang.String com.taobao.csp.sentinel.dashboard.view.DemoController.greeting()
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/demo/slow],produces=[application/json]}" onto public java.lang.String com.taobao.csp.sentinel.dashboard.view.DemoController.slow(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v1/flow/delete.json],methods=[DELETE]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Long> com.taobao.csp.sentinel.dashboard.view.FlowControllerV1.delete(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v1/flow/rules],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.taobao.csp.sentinel.dashboard.view.FlowControllerV1.apiQueryMachineRules(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v1/flow/rule],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.FlowControllerV1.apiAddFlowRule(com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v1/flow/save.json],methods=[PUT]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.FlowControllerV1.updateIfNotNull(java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer,java.lang.Double,java.lang.Integer,java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/app/names.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<java.lang.String>> com.taobao.csp.sentinel.dashboard.view.AppController.queryApps(javax.servlet.http.HttpServletRequest)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/app/briefinfos.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.discovery.AppInfo>> com.taobao.csp.sentinel.dashboard.view.AppController.queryAppInfos(javax.servlet.http.HttpServletRequest)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/app/{app}/machines.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.view.vo.MachineInfoVo>> com.taobao.csp.sentinel.dashboard.view.AppController.getMachinesByApp(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v2/flow/rule/{id}],methods=[DELETE]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Long> com.taobao.csp.sentinel.dashboard.view.FlowControllerV2.apiDeleteRule(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v2/flow/rules],methods=[GET]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.taobao.csp.sentinel.dashboard.view.FlowControllerV2.apiQueryMachineRules(java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v2/flow/rule],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.FlowControllerV2.apiAddFlowRule(com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v2/flow/rule/{id}],methods=[PUT]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.taobao.csp.sentinel.dashboard.view.FlowControllerV2.apiUpdateFlowRule(java.lang.Long,com.taobao.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/metric/queryTopResourceMetric.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.MetricController.queryTopResourceMetric(java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Long,java.lang.Long,java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/metric/queryByAppAndResource.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.MetricController.queryByAppAndResource(java.lang.String,java.lang.String,java.lang.Long,java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/degrade/new.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.taobao.csp.sentinel.dashboard.view.DegradeController.add(java.lang.String,java.lang.String,java.lang.Integer,java.lang.String,java.lang.String,java.lang.Double,java.lang.Integer,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/degrade/delete.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.lang.Long> com.taobao.csp.sentinel.dashboard.view.DegradeController.delete(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/degrade/rules.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity>> com.taobao.csp.sentinel.dashboard.view.DegradeController.queryMachineRules(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/degrade/save.json],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.taobao.csp.sentinel.dashboard.view.DegradeController.updateIfNotNull(java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Double,java.lang.Integer,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/resource/machineResource.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.ResourceController.fetchIdentityOfMachine(java.lang.String,java.lang.Integer,java.lang.String,java.lang.String)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/system/new.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.SystemController.add(java.lang.String,java.lang.String,java.lang.Integer,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/system/delete.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.SystemController.delete(java.lang.Long)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/system/rules.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<java.util.List<com.taobao.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity>> com.taobao.csp.sentinel.dashboard.view.SystemController.queryMachineRules(java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/system/save.json],produces=[application/json]}" onto com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.SystemController.updateIfNotNull(java.lang.Long,java.lang.String,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/assign/all_server/{app}],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterAssignController.apiAssignAllClusterServersOfApp(java.lang.String,com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/assign/single_server/{app}],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterAssignController.apiAssignSingleClusterServersOfApp(java.lang.String,com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/cluster/assign/unbind_server/{app}],methods=[POST]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<com.taobao.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.taobao.csp.sentinel.dashboard.view.cluster.ClusterAssignController.apiUnbindClusterServersOfApp(java.lang.String,java.util.Set<java.lang.String>)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/health],methods=[GET]}" onto public java.lang.String com.taobao.csp.sentinel.dashboard.view.HealthCheck.checkPreload()
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/registry/machine],produces=[application/json]}" onto public com.taobao.csp.sentinel.dashboard.view.Result<?> com.taobao.csp.sentinel.dashboard.view.MachineRegistryController.receiveHeartBeat(java.lang.String,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-01-31 16:41:04 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2019-01-31 16:41:04 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-01-31 16:41:04 [main] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-01-31 16:41:04 [main] INFO  o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
2019-01-31 16:41:04 [main] INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''
2019-01-31 16:41:04 [main] INFO  c.t.c.s.d.DashboardApplication - Started DashboardApplication in 4.063 seconds (JVM running for 4.745)
2019-01-31 16:41:05 [http-nio-8080-exec-1] INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring FrameworkServlet 'dispatcherServlet'
2019-01-31 16:41:05 [http-nio-8080-exec-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization started
2019-01-31 16:41:05 [http-nio-8080-exec-1] INFO  o.s.web.servlet.DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization completed in 19 ms

启动之后可以查看控制台,xxb能够显示出来,是因为sentinel对控制台本身也做了流控监控。方便演示看效果。机器列表就是指当前监听到的客户端信息。

sentinel神器

还可以通过内置的API接口查看信息

a. 查看资源信息指定资源
http://localhost:8719/cnode?id=gateway id=<资源>
b. 查看资源信息模糊匹配
http://localhost:8719/cnode?id=1
idx id thread pass blocked success total aRt 1m-pass 1m-block 1m-all exception
4 /app/scripts/controllers/flow_v1.js 0 0 0 0 0 0 0 0 0 0
5 /v1/flow/rules 0 0 0 0 0 0 0 0 0 0
6 /app/views/flow_v1.html 0 0 0 0 0 0 0 0 0 0
c. 查看集群信息
http://localhost:8719/clusterNode
d. 根据类型查询规则
http://localhost:8719/getRules?type=flow type=<flow【限流规则】,degrade【降级规则】,system【系统规则】>
e. 修改已有规则
http://localhost:8719/setRules?type=<xxxx>&data=<data>

只要以上可以操作,说明控制台已经成功运行了。

 

3. 启动项目并添加vm参数
-Dproject.name=test -Dcsp.sentinel.dashboard.server=127.0.0.1:8080 -Dcsp.sentinel.api.port=8888

这里指定项目客户端的名称为test,连接控制台的地址为127.0.0.1:8080,监听端口为8888
启动过程中会看到类似日志

******
INFO: log base dir is: /Users/chenhailong/logs/csp/
INFO: log name use pid is: false
******

说明接入sentinel成功

 

4.查看控制台监控项目的流控规则
如果项目启动之后,没有访问流控相关代码逻辑,在控制台是看不到项目客户端的。(流控相关代码请查看官方网站的使用规则)
所以访问以下流控逻辑,过几秒刷新控制台,可以看到项目中的流控规则数据。如下。
sentinel神器

 

总结,整体配置还是比较简单的,好用方便。
数据在内存中,关闭项目后就无法读取。对于一些流控规则要求较高,需要持久化的,
可以参考 https://github.com/alibaba/Sentinel/wiki/动态规则扩展
sentinel原理、概念什么的,可以去官网中文版查看,解释的狠详细了。


   原创文章,转载请标明本文链接: 网关流量控制使用阿里流量哨兵神器sentinel控制台实践验证过程

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

更多阅读