监控成功示例
integration-eureka-700eureka注册中心integration-zuul-952zuul网关路由integration-dashboard-799dashboard监控面板integration-provider-camp-800业务接口————————————————————————————————————————————7999负责收集监控信息并展示,9527和8004是被监控模块
注解
package com.integration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
/**
* @author hupg
* @date 2022/3/2 11:11
*/
@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableCircuitBreaker
@EnableTurbine
public class IntegrationDashboard7999 {
public static void main(String[] args) {
SpringApplication.run(IntegrationDashboard7999.class, args);
}
}
输入监控地址后,出现如下红字提示,说明未监控到指定服务,此时需要排查问题。排查地址是否正确。排查服务是否正常启动。如果2都没问题,刷新监控页面,排查后台是否有报错。如果1-3都没问题,排查各种配置,如注册中心是否正确、是否配置接口Hystrix熔断等等。
微服务组成
特殊pom、yml、注解与9527一样,不再重复。————————————————————————————————————————————需要注意的是,被监控的接口方法需要加@HystrixCommand注解,不加该注解的接口是监控不到的,个人猜测是因为dashboard监控的原理就是用的Hystrix熔断机制,所以不使用Hystrix做熔断限制的接口是监控不到的。
服务配置
被监控服务启动成功示例
以8004为例:直接访问http://localhost:8004/actuator/hystrix.stream,会一直输出如下监控信息。如果只出现ping:....ping:....ping:....而没有json信息的话,说明没有调用任何被监控的接口,手动调用一次即可;如果调用了还是没有信息,说明没有监控到,需要再检查监控配置是否正确,尤其是@HystrixCommand注解比较容易忘。
总结
监控页面
和平常使用没区别,不多比比,不会的百度一下eureka配置吧~~
以上服务准备好后,先启动700最后启动799
个人感觉,这个监控以下几点有点鸡肋:监控的接口必须加@HystrixCommand注解。被监控接口必须至少被调用一次后,才能有监控信息。集群监控或监控接口较多时,页面会显得很杂乱。
yml配置
server:
port: 7999
spring:
application:
name: hystrix-dashboard-7999
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka
instance:
preferIpAddress: true
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 4000
dashboard:
proxy-stream-allow-list: '*'
#config:
#stream:
#maxConcurrentConnections: 50
# 下方为集群配置,不需要集群可以不配
turbine:
combine-host-port: true #同一主机多个服务使用hostname+port进行区分,此项默认为false,即同一主机多服务会合并成一个服务展示
aggregator:
clusterConfig: default # 指定聚合哪些集群,多个使用','分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问
appConfig: springcloud-zuul,springcloud-camp-8004 # 配置Eureka中的serviceId列表,表明监控哪些服务
cluster-name-expression: new String('default')
监控失败示例
控制台日志:因为turbinappConfig:springcloud-zuul,springcloud-camp-8004配置了两个监控实例,所有启动时会自动检测监控服务。
2022-03-02 13:33:34.780 INFO 18356 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_HYSTRIX-DASHBOARD-7999/DESKTOP-8I2SJKS:hystrix-dashboard-7999:7999: registering service...
2022-03-02 13:33:34.785 INFO 18356 --- [ Timer-0] o.s.c.n.turbine.EurekaInstanceDiscovery : Fetching instances for app: springcloud-camp-8004
2022-03-02 13:33:34.785 INFO 18356 --- [ Timer-0] o.s.c.n.turbine.EurekaInstanceDiscovery : Received instance list for app: springcloud-camp-8004, size=1
2022-03-02 13:33:34.786 INFO 18356 --- [ Timer-0] c.n.t.discovery.InstanceObservable : Retrieved hosts from InstanceDiscovery: 2
2022-03-02 13:33:34.786 INFO 18356 --- [ Timer-0] c.n.t.discovery.InstanceObservable : Found hosts that have been previously terminated: 0
2022-03-02 13:33:34.786 INFO 18356 --- [ Timer-0] c.n.t.discovery.InstanceObservable : Hosts up:2, hosts down: 0
2022-03-02 13:33:34.789 INFO 18356 --- [ Timer-0] c.n.t.monitor.instance.InstanceMonitor : Url for host: http://192.168.10.67:9527/actuator/hystrix.stream default
2022-03-02 13:33:34.789 INFO 18356 --- [ Timer-0] c.n.t.handler.TurbineDataDispatcher :
Just added and starting handler tuple: default_agg_aggClusterEventHandler
2022-03-02 13:33:34.790 INFO 18356 --- [ Timer-0] c.n.turbine.data.AggDataFromCluster : Per handler dispacher started for: default_agg_aggClusterEventHandler
2022-03-02 13:33:34.791 INFO 18356 --- [ Timer-0] c.n.t.monitor.instance.InstanceMonitor : Url for host: http://192.168.10.67:8004/actuator/hystrix.stream default
2022-03-02 13:33:34.809 INFO 18356 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 7999 (http) with context path ''
2022-03-02 13:33:34.810 INFO 18356 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 7999
2022-03-02 13:33:34.816 INFO 18356 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_HYSTRIX-DASHBOARD-7999/DESKTOP-8I2SJKS:hystrix-dashboard-7999:7999 - registration status: 204
99启动成功示例
特殊pom依赖
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
org.springframework.boot
spring-boot-starter-actuator
全部集群监控页面:下login接口对应CzryController是8004内的接口,另外两个是9527路由下的其他微服务名称,看起来可以监控普通接口和监控zuul路由模块。单个服务监控页面
特殊yml配置
management:
endpoints:
web:
exposure:
include: '*'
hystrix:
command:
default: # [serviceId] 即zuul中配置的serviceId
execution:
isolation:
thread:
timeoutInMilliseconds: 6000
# circuitBreaker:
# requestVolumeThreshold: 10 # 触发熔断超时次数 10次
# sleepWindowInMilliseconds: 60000 # 熔断多久后尝试放行一次请求【60s】 默认5s
# errorThresholdPercentage: 50 # 失败率达到多少后触发熔断
# metrics:
# rollingStats:
# timeInMilliseconds: 60000 # 熔断多长时间后,尝试放一次请求进来,默认5秒
页面示例:中第一个输入框需要输入被监控的地址,一共有三种写法,输入框下方也有示例,分别是:默认集群,指定集群,单个实例。注意http和https!!!
如果某个服务只有几个接口,用这个监控页面应该还可以,把所有接口全部监控到也不会很费劲;但如果是大型的服务,使用这个监控就有点不适用了,性能先不考虑,当接口较多时,这个页面看起来估计会很折磨。。。
特殊pom依赖
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
org.springframework.cloud
spring-cloud-starter-netflix-turbine
特殊注解
文章为作者独立观点,不代表股票交易接口观点