我是靠谱客的博主 敏感含羞草,最近开发中收集的这篇文章主要介绍用hystrix-turbine-dashboard基于consul做集群监控用hystrix-turbine-dashboard基于consul做集群监控,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

文章目录

  • 用hystrix-turbine-dashboard基于consul做集群监控
    • 一、现有工程
    • 二、配置启动hystrix-turbine-dashboard

用hystrix-turbine-dashboard基于consul做集群监控

Hystrix-dashboard是一款针对Hystrix进行实时监控的工具,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间,请求成功率等数据。但是只使用Hystrix Dashboard的话,你只能看到单个应用内的服务信息,这明显不够;我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上,这个工具就是Turbine

一、现有工程

现有vis-basic-report工程,内部调用了vis-basic-city、vis-basic-weather两个服务,并且实现了熔断,以下为vis-basic-report服务的相关配置和验证:

  1. application.yml
server: 
  #服务端口号
  port: 8080
spring: 
  application:
    #服务名称--调用的时候根据名称来调用该服务的方法
    name: vis-basic-report
  thymeleaf: 
    cache: false
  cloud:
    consul: 
      host: 192.168.12.125
      port: 8500
      discovery: 
        #是否需要注册到consul中
        register: true
        #服务地址直接为IP地址
        hostname: 192.168.12.1
#开启hystrix
feign: 
  hystrix: 
   enabled: true
        
management:
  endpoints:
    web:
      exposure:
        include: '*'
        
  1. 修改启动类,增加getServlet()方法
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

@SpringBootApplication
@EnableFeignClients
@EnableHystrix
public class ReportServerApplication {
	
	public static void main(String[] args) {
		SpringApplication.run(ReportServerApplication.class, args);
	}
	
	@Bean
	public ServletRegistrationBean<HystrixMetricsStreamServlet> getServlet() {
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
		ServletRegistrationBean<HystrixMetricsStreamServlet> registrationBean = new ServletRegistrationBean<HystrixMetricsStreamServlet>(streamServlet);
		registrationBean.setLoadOnStartup(1);
		registrationBean.addUrlMappings("/actuator/hystrix.stream");
		registrationBean.setName("HystrixMetricsStreamServlet");
		return registrationBean;
	}
	
}
  1. 启动相关服务,测试访问vis-basic-report工程的/actuator/hystrix.stream
    http://192.168.12.1:8080/actuator/hystrix.stream
    在这里插入图片描述
    没有任何输出

  2. 需要先访问下接口服务
    在这里插入图片描述

  3. 再查看/actuator/hystrix.stream
    在这里插入图片描述
    已经有内容输出了

二、配置启动hystrix-turbine-dashboard

新建SpringBoot项目vis-hystrix-turbine-dashboard,主要配置内容如下

  1. pom.xml依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.wzl.springcloud</groupId>
	<artifactId>vis-hystrix-turbine-dashboard</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>vis-hystrix-turbine-dashboard</name>
	<description>Demo project for Spring Boot</description>

	<packaging>jar</packaging>

	<properties>
		<!-- 版本管理 -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<junit.version>4.12</junit.version>
		<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.7.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-consul-discovery</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
		</dependency>
		<!-- turbine -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.cloud</groupId>
					<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-netflix-turbine</artifactId>
		</dependency>
		<!-- spring boot test -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>${junit.version}</version>
				<scope>test</scope>
			</dependency>

			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

  1. application.yml
server: 
  #服务端口号 
  port: 7272
spring: 
  application: 
    #服务名称
    name: vis-hystrix-turbine-dashboard
  cloud: 
    consul: 
      host: 192.168.12.125
      port: 8500
      discovery: 
        #是否需要注册到consul中
        register: true
        #服务地址直接为IP地址
        hostname: 192.168.12.1
        service-name: ${spring.application.name}
        healthCheckPath: /actuator/health
        healthCheckInterval: 10s
        
management:
  endpoints:
    web:
      exposure:
        include: '*'
        
turbine: 
  aggregator: 
    cluster-config: default
  # 配置注册中心中的serviceId列表,表明监控哪些服务
  app-config: vis-server-config,vis-basic-zuul,vis-basic-weather,vis-basic-city,vis-basic-report
  cluster-name-expression: new String("default")
  
  1. 启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;

@SpringBootApplication
@EnableHystrixDashboard
@EnableTurbine
public class VisHystrixTurbineDashboardApplication {

	public static void main(String[] args) {
		SpringApplication.run(VisHystrixTurbineDashboardApplication.class, args);
	}

}

  1. 启动访问hystrix-turbine-dashboard,测试
    http://192.168.12.1:7272/hystrix
    在这里插入图片描述

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

如果查看默认集群使用第一个url;
http://192.168.12.1:7272/turbine.stream
查看指定集群使用第二个ur;
http://192.168.12.1:7272/turbine.stream?cluster=default
单个应用的监控使用最后一个;
http://192.168.12.1:8080/actuator/hystrix.stream

我们暂时只演示单个应用的,所以在输入框中输入:http://192.168.12.1:8080/actuator/hystrix.stream,输入之后点击Monitor Stream,进入页面。在请求服务vis-basic-report,就可以看到监控的效果了:
在这里插入图片描述
如果没有请求会先显示Loading …,访问http://192.168.12.1:8080/actuator/hystrix.stream也会不断的显示ping

其实就是http://192.168.12.1:8080/actuator/hystrix.stream返回结果的图形化显示,Hystrix Dashboard Wiki上详细说明了图上每个指标的含义,如下图:
在这里插入图片描述

最后

以上就是敏感含羞草为你收集整理的用hystrix-turbine-dashboard基于consul做集群监控用hystrix-turbine-dashboard基于consul做集群监控的全部内容,希望文章能够帮你解决用hystrix-turbine-dashboard基于consul做集群监控用hystrix-turbine-dashboard基于consul做集群监控所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(86)

评论列表共有 0 条评论

立即
投稿
返回
顶部