SpringCloud之dashboard监控
2019-04-25 本文已影响0人
TZX_0710
Hystrix Dashboard 是 Hystrix 的仪表盘组件,提供了数据监控,可以实时监控 Hystrix 的各个指标,然后通过图形化界面展示出来。
hystrixDashboard作为一个独立的服务
新建项目histry_service
pom依赖
添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
启动类增加 注解
package com.example.histry_service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@EnableHystrixDashboard//开启监控
@SpringBootApplication
public class HistryServiceApplication {
public static void main(String[] args) {
SpringApplication.run( HistryServiceApplication.class, args );
}
}
properties文件
spring.application.name=histry_service
server.port=9999
在对需要被监控的服务引入依赖j监控的jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
启动类上增加注解
package com.tg.rabbin_customer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableEurekaClient //启动一个eureka的客户端
@EnableHystrix //1.激活断路器
@EnableCircuitBreaker //2
public class RabbinCustomerApplication {
public static void main(String[] args) {
SpringApplication.run( RabbinCustomerApplication.class, args );
}
//开启负载均衡功能
@Bean
@LoadBalanced
RestTemplate restTemplate() {
return new RestTemplate();
}
}
spring:
application:
name: eureka-ribbon
server:
port: 8764
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/eureka
#这边可以不关闭自动注册因为也可以把ribbon的当成一个服务注册过去
2.0之后需要手动开启端点
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: ALWAYS #展示细节
启动eureka-server、启动eureka-client、启动ribbon服务、启动histry_service
浏览器输入http://localhost://9999/hystrix进入dashboard的监控页面
地址栏填写需要查看的服务
填写规范:Cluster via Turbine (default cluster): http://turbine-hostname:port/turbine.stream
Cluster via Turbine (custom cluster): http://turbine-hostname:port/turbine.stream?cluster=[clusterName]
Single Hystrix App: http://hystrix-app:port/hystrix.stream
前面2个是针对集群
作者目前配置的是一个
所以地址兰输入
http://localhost:8764/actuator/hystrix.stream
成功搭建
image.png