由于 hystrix 对流量的监控状态的监控是单应用的。有的时候我们需要全面查看整个系统的监控状态,那么我们可能需要引入turbine 的监控检查。在spring boot admin 已经有spring-boot-admin-server-ui-turbine 这个插件
turbine 是一个hystrix 的集合。里面展示所有的hystrix的效果。我们这里用的spring cloud的版本是
<spring-boot.version>1.5.3.RELEASE</spring-boot.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
<spring-boot-admin.version>1.5.0</spring-boot-admin.version>
1、配置turbine 的包依赖
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui-turbine</artifactId>
<version>${spring-boot-admin.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
</dependencies>
2、配置启动类
//www.1b23.com
@SpringBootApplication
@EnableAdminServer
@EnableDiscoveryClient
@EnableTurbine
open class YkbBootAdminServerApplication {
companion object {
@JvmStatic fun main(args: Array<String>) {
SpringApplication.run(YkbBootAdminServerApplication::class.java, *args)
}
}
}
启动类配置了@EnableTurbine
3、配置启动项:(application.properties)
spring.boot.admin.routes.endpoints= env,metrics,trace,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream,turbine.stream
spring.boot.admin.turbine.location=TGS-SPRING-BOOT-ADMIN
management.security.enabled=false
security.basic.enabled=false
turbine.clusterNameExpression=new String("default")
turbine.appConfig=YKB-ACCOUNT-MOBILE
turbine.combineHostPort=true
其中endpoints 配置hystrix.stream,turbine.stream
配置了spring.boot.admin.turbine.location=TGS-SPRING-BOOT-ADMIN
代表是由TGS-SRPING-BOOT-ADMIN实例来管理所有的监控
springcloud 项目案例 www.1b23.com
最后
turbine.appConfig=YKB-ACCOUNT-MOBILE
代表你可以监控的应用有哪些,可以用逗号隔开
4、配置hystrix
ykb-account-mobile 配置熔断机制 这里采用 @SpringCloudApplication里面包含了熔断机制
@SpringCloudApplication
@EnableZuulProxy
@EnableFeignClients
open class AccountMobileApplication {
//www.1b23.com
@LoadBalanced
@Bean
open fun restTemplate(): RestTemplate {
return RestTemplate()
}
companion object {
@JvmStatic fun main(args: Array<String>) {
SpringApplication.run(AccountMobileApplication::class.java, *args)
}
}
}
需要引入的jar包为
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
其中application的配置为
server.port=7180
management.port=7181
eureka.instance.prefer-ip-address = true
eureka.instance.lease-renewal-interval-in-seconds=10
eureka.instance.lease-expiration-duration-in-seconds=30
eureka.client.service-url.defaultZone= http://eureka.ejuda.net:8761/eureka/
eureka.client.fetch-registry=true
eureka.instance.metadata-map.management.port= ${management.port}
其中eureka.instance.metadata-map.management.port=${management.port}
是必须的。因为管理端口跟服务端口不一样