sentinel即哨兵,相比hystrix斷路器而言,它的功能更豐富。hystrix僅支持熔斷,當服務消費方調用提供方發現異常後,進入熔斷;sentinel不只支持異常熔斷,也支持響應超時熔斷,另外還支持限流,以及針對網關的熔斷和限流。此外,它還有過載處理、監控控制檯(Sentinel Dashboard)等。hystrix做爲組件集成到微服務中,sentinel也是如此,但它的控制檯須要獨立部署。html
先下載Sentinel Dashboard(下載地址https://github.com/alibaba/Sentinel/releases),目前最新版本是1.6.3,下載到本地(個人是E盤download目錄下)後啓動jar包:java
C:\Users\wulf>e: E:\>cd download E:\download>java -jar sentinel-dashboard-1.6.3.jar INFO: log base dir is: C:\Users\wulf\logs\csp\ INFO: log name use pid is: false . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.5.RELEASE) 2019-08-23 09:08:38.125 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : Starting DashboardApplication on wulf00 with PID 42064 (E:\download\sentinel-dashboard-1.6.3.jar started by wulf in E:\download) 2019-08-23 09:08:38.137 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : No active profile set, falling back to default profiles: default 2019-08-23 09:08:38.263 INFO 42064 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Fri Aug 23 09:08:38 CST 2019]; root of context hierarchy 2019-08-23 09:08:41.446 ERROR 42064 --- [ main] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14] 2019-08-23 09:08:41.787 INFO 42064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2019-08-23 09:08:41.817 ERROR 42064 --- [ main] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14] 2019-08-23 09:08:41.859 INFO 42064 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2019-08-23 09:08:41.861 INFO 42064 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34 2019-08-23 09:08:41.887 ERROR 42064 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14] 2019-08-23 09:08:42.037 INFO 42064 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2019-08-23 09:08:42.039 INFO 42064 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3777 ms 2019-08-23 09:08:42.163 INFO 42064 --- [ost-startStop-1] c.a.c.s.dashboard.config.WebConfig : Sentinel servlet CommonFilter registered 2019-08-23 09:08:42.288 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2019-08-23 09:08:42.291 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2019-08-23 09:08:42.292 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2019-08-23 09:08:42.293 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2019-08-23 09:08:42.295 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'authenticationFilter' to urls: [/*] 2019-08-23 09:08:42.296 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'sentinelFilter' to urls: [/*] 2019-08-23 09:08:42.296 INFO 42064 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2019-08-23 09:08:43.660 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-08-23 09:08:43.930 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c629d6e: startup date [Fri Aug 23 09:08:38 CST 2019]; root of context hierarchy 2019-08-23 09:08:44.060 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/registry/machine],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MachineRegistryController.receiveHeartBeat(java.lang.String,java.lang.Integer,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.067 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/auth/logout],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result com.alibaba.csp.sentinel.dashboard.controller.AuthController.logout(javax.servlet.http.HttpServletRequest) 2019-08-23 09:08:44.068 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/auth/login],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result com.alibaba.csp.sentinel.dashboard.controller.AuthController.login(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String) 2019-08-23 09:08:44.083 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/delete.json],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.delete(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.084 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.085 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.apiAddFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity) 2019-08-23 09:08:44.088 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v1/flow/save.json],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.FlowControllerV1.updateIfNotNull(javax.servlet.http.HttpServletRequest,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-08-23 09:08:44.094 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String) 2019-08-23 09:08:44.095 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiUpdateFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity) 2019-08-23 09:08:44.097 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiAddFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity) 2019-08-23 09:08:44.099 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/flow/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.106 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/{app}/machine/remove.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.String> com.alibaba.csp.sentinel.dashboard.controller.AppController.removeMachineById(java.lang.String,java.lang.String,int) 2019-08-23 09:08:44.108 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/{app}/machines.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.vo.MachineInfoVo>> com.alibaba.csp.sentinel.dashboard.controller.AppController.getMachinesByApp(java.lang.String) 2019-08-23 09:08:44.109 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/names.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<java.lang.String>> com.alibaba.csp.sentinel.dashboard.controller.AppController.queryApps(javax.servlet.http.HttpServletRequest) 2019-08-23 09:08:44.110 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/app/briefinfos.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.discovery.AppInfo>> com.alibaba.csp.sentinel.dashboard.controller.AppController.queryAppInfos(javax.servlet.http.HttpServletRequest) 2019-08-23 09:08:44.114 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/loop],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.loop(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException 2019-08-23 09:08:44.115 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/link],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.link() throws com.alibaba.csp.sentinel.slots.block.BlockException 2019-08-23 09:08:44.118 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/greeting],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.greeting() 2019-08-23 09:08:44.122 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/demo/slow],produces=[application/json]}" onto public java.lang.String com.alibaba.csp.sentinel.dashboard.controller.DemoController.slow(java.lang.String,int) throws com.alibaba.csp.sentinel.slots.block.BlockException 2019-08-23 09:08:44.124 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/resource/machineResource.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.vo.ResourceVo>> com.alibaba.csp.sentinel.dashboard.controller.ResourceController.fetchResourceChainListOfMachine(java.lang.String,java.lang.Integer,java.lang.String,java.lang.String) 2019-08-23 09:08:44.128 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/all_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiAssignAllClusterServersOfApp(java.lang.String,com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppFullAssignRequest) 2019-08-23 09:08:44.129 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/unbind_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiUnbindClusterServersOfApp(java.lang.String,java.util.Set<java.lang.String>) 2019-08-23 09:08:44.131 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/assign/single_server/{app}],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppAssignResultVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterAssignController.apiAssignSingleClusterServersOfApp(java.lang.String,com.alibaba.csp.sentinel.dashboard.domain.cluster.ClusterAppSingleServerAssignRequest) 2019-08-23 09:08:44.136 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/delete.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.deleteApi(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.137 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/list.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity>> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.queryApis(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.140 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/new.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.addApi(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.api.AddApiReqVo) 2019-08-23 09:08:44.142 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/api/save.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.ApiDefinitionEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayApiController.updateApi(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.api.UpdateApiReqVo) 2019-08-23 09:08:44.147 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiQueryAllRulesForMachine(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.149 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiAddParamFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) 2019-08-23 09:08:44.151 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiUpdateParamFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity) 2019-08-23 09:08:44.153 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/paramFlow/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.ParamFlowRuleController.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.157 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rules],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiQueryAllRulesForMachine(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.159 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiAddAuthorityRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity) 2019-08-23 09:08:44.164 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule/{id}],methods=[PUT]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiUpdateParamFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long,com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.AuthorityRuleEntity) 2019-08-23 09:08:44.168 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/authority/rule/{id}],methods=[DELETE]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.AuthorityRuleController.apiDeleteRule(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.171 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/new.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.addFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.rule.AddFlowRuleReqVo) 2019-08-23 09:08:44.172 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/list.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.queryFlowRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.173 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/delete.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.deleteFlowRule(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.174 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/gateway/flow/save.json],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.gateway.GatewayFlowRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.gateway.GatewayFlowRuleController.updateFlowRule(javax.servlet.http.HttpServletRequest,com.alibaba.csp.sentinel.dashboard.domain.vo.gateway.rule.UpdateFlowRuleReqVo) 2019-08-23 09:08:44.178 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/server_state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterServerStateWrapVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterServerStateOfApp(java.lang.String) 2019-08-23 09:08:44.180 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/config/modify_single],methods=[POST]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Boolean> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiModifyClusterConfig(java.lang.String) 2019-08-23 09:08:44.181 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStatePairVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterStateOfApp(java.lang.String) 2019-08-23 09:08:44.185 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/client_state/{app}],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.AppClusterClientStateWrapVO>> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterClientStateOfApp(java.lang.String) 2019-08-23 09:08:44.188 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/cluster/state_single],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.domain.cluster.state.ClusterUniversalStateVO> com.alibaba.csp.sentinel.dashboard.controller.cluster.ClusterConfigController.apiGetClusterState(java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.191 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/metric/queryByAppAndResource.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MetricController.queryByAppAndResource(java.lang.String,java.lang.String,java.lang.Long,java.lang.Long) 2019-08-23 09:08:44.192 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/metric/queryTopResourceMetric.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.MetricController.queryTopResourceMetric(java.lang.String,java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Long,java.lang.Long,java.lang.String) 2019-08-23 09:08:44.194 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/new.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.add(javax.servlet.http.HttpServletRequest,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-08-23 09:08:44.198 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/delete.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.lang.Long> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.delete(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.199 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/rules.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.queryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.200 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/degrade/save.json],produces=[application/json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.DegradeController.updateIfNotNull(javax.servlet.http.HttpServletRequest,java.lang.Long,java.lang.String,java.lang.String,java.lang.String,java.lang.Double,java.lang.Integer,java.lang.Integer) 2019-08-23 09:08:44.209 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/delete.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<?> com.alibaba.csp.sentinel.dashboard.controller.SystemController.delete(javax.servlet.http.HttpServletRequest,java.lang.Long) 2019-08-23 09:08:44.210 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/rules.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<java.util.List<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity>> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiQueryMachineRules(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer) 2019-08-23 09:08:44.212 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/new.json]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiAdd(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.Integer,java.lang.Double,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double) 2019-08-23 09:08:44.214 INFO 42064 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/system/save.json],methods=[GET]}" onto public com.alibaba.csp.sentinel.dashboard.domain.Result<com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity> com.alibaba.csp.sentinel.dashboard.controller.SystemController.apiUpdateIfNotNull(javax.servlet.http.HttpServletRequest,java.lang.Long,java.lang.String,java.lang.Double,java.lang.Double,java.lang.Long,java.lang.Long,java.lang.Double) 2019-08-23 09:08:44.219 INFO 42064 --- [ main] 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-08-23 09:08:44.221 INFO 42064 --- [ main] 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-08-23 09:08:44.236 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController] 2019-08-23 09:08:44.276 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-08-23 09:08:44.277 INFO 42064 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2019-08-23 09:08:44.546 INFO 42064 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2019-08-23 09:08:44.590 INFO 42064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2019-08-23 09:08:44.599 INFO 42064 --- [ main] c.a.c.s.dashboard.DashboardApplication : Started DashboardApplication in 7.26 seconds (JVM running for 9.45) 2019-08-23 09:08:45.767 ERROR 42064 --- [nio-8080-exec-2] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.12] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14] 2019-08-23 09:08:45.783 INFO 42064 --- [nio-8080-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2019-08-23 09:08:45.783 INFO 42064 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2019-08-23 09:08:45.812 INFO 42064 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 28 ms
默認端口號是8080,咱們在瀏覽器輸入localhost:8080便可打開監控面板,默認用戶名密碼都是sentinel:git
接下來咱們讓服務提供方lxytrans-provider這個應用(原三板斧參見0.9.0.RELEASE版本的spring cloud alibaba nacos實例)接入到哨兵,加上sentinel相關內容:github
一、pom引入sentinel依賴:web
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
二、application引入sentinel dashboard地址:spring
#哨兵 spring.cloud.sentinel.transport.dashboard=localhost:8080
三、controller加上註解@SentinelResource標識資源:apache
@Slf4j @RestController static class TestController { @GetMapping("/hello") @SentinelResource("hello") public String hello() { return "hello"; } @GetMapping("/hey") @SentinelResource("hey") public String hey() throws InterruptedException { Thread.sleep(2000); return "hey"; }
打完收工。啓動應用後,再訪問localhost:8080,發現微服務已經接入,可是sentinel dashboard頁面已然啥都木有。咱們須要先訪問一次接口,才能在sentinel dashboard上看到。那就先跑一把/hello和/hey,再去sentinel bashboard刷新下實時監控,接口出來了:json
咱們點下「簇點鏈路」,在對應的資源右邊點擊流控進行流控規則設置,點擊降級則是設置降級規則。先試下流控。上面能夠看到hello有3級資源,點擊咱們在@SentinelResource中指定的「hello」右邊對應的流控按鈕:api
這裏咱們配置流控規則是每秒併發請求數爲3,超過了就直接拒絕。點擊新增按鈕後跳到流控規則頁面:瀏覽器
流控規則頁面的右上角也能夠直接添加規則的。如今咱們經過jmeter來跑一個,jmeter設置線程數爲4(具體設置參見jmeter使用經歷):
咱們看到併發調用了4次hello接口,其中一次失敗了,日誌打印以下:
2019-08-22 13:02:14.651 |-ERROR [http-nio-8282-exec-10] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] [175] -| Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause com.alibaba.csp.sentinel.slots.block.flow.FlowException: null
接下來咱們經過另外一個/hey接口試降低級,在「簇點鏈路」點擊「hey」資源右邊的降級按鈕設置降級規則:
這裏咱們配置/hey接口若是時延超過100毫秒(5個一批,兩批均超時,進入降級),那麼接下來的10秒內,咱們將拒絕請求。10秒後容許繼續請求,若是仍是超時,那麼繼續拒絕10秒。循環往復,生生不息。點擊「新增」按鈕後跳往降級規則頁面:
一樣的,在這個頁面右上角也能夠直接新增降級規則。咱們在jmeter中新增一個/hey接口,禁用原來的/hello,再將線程數改成5,循環次數改成4,跑一把:
/hey接口的時延是2秒,仔細看下這20個接口的請求時間,分4批請求,每批間隔2秒。能夠發現第一批5個是正常經過的,接下第2批前4個也是正常經過的,後面11個全被拒絕了。日誌打印:
2019-08-22 13:12:03.245 |-ERROR [http-nio-8282-exec-2] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] [175] -| Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.UndeclaredThrowableException] with root cause com.alibaba.csp.sentinel.slots.block.degrade.DegradeException: null
打完收工。注意若是應用重啓後,sentinel dashboard的限流、降級配置就沒了,須要從新請求一次,刷出資源後再從新配置。更多信息參考https://github.com/alibaba/Sentinel/wiki/介紹。關於服務提供方的限流、降級定製處理,參見0.9.0.RELEASE版本的spring cloud alibaba sentinel限流、降級處理實例。