springCloud集成Dashboard

本次主要记录springCloud集成Dashboard搭建过程

Dashboard监控盘
    属于springCloud中熔断器监控,可以帮助我们得知在一定时间内单个服务接口被调用情况以及断路器目前处于什么状态。

搭建

消费服务方

导包:
<parent>
    <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>Finchley.SR4</version>
        <relativePath/>
  </parent>
  <dependencies>
			   <dependency>
			      <groupId>org.springframework.boot</groupId>
			      <artifactId>spring-boot-starter-web</artifactId>
		    </dependency>
		    
		  <!-- springcloud 导入包 -->
		  <!-- springcloud eureka包导入 -->
				<dependency>
				    <groupId>org.springframework.cloud</groupId>
				    <!-- eureka客户端导包 -->
				    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
				</dependency>
		  <!-- openFeign熔断 -->
		  
			<dependency>
				    <groupId>org.springframework.cloud</groupId>
				    <!-- openfeign客户端导包 -->
				    <artifactId> spring-cloud-starter-openfeign</artifactId>
			</dependency>
	 		<!-- hystrix-dashboard 仪表盘 -->
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</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-netflix-hystrix</artifactId>
			</dependency>
    	</dependencies>
			    <repositories>
			        <repository>
			            <id>spring-milestones</id>
			            <name>Spring Milestones</name>
			            <url>https://repo.spring.io/milestone</url>
			        </repository>
			    </repositories>
			    <build>
			    <plugins>
			      <plugin>
			        <groupId>org.springframework.boot</groupId>
			        <artifactId>spring-boot-maven-plugin</artifactId>
			        <configuration>
			          <fork>true</fork>
			        </configuration>
			      </plugin>
			    </plugins>
			  </build>
启动类:
@SpringBootApplication
//eureka发现客户端
@EnableDiscoveryClient
@EnableFeignClients
//监控盘
@EnableHystrixDashboard
@EnableCircuitBreaker
public class AssetApplication {
	    public static void main(String[] args) {
	    	SpringApplication.run(AssetApplication.class, args);
	    }
}
远程调用服务接口
这里可以得知,我们远程调用的是ti-gong-fu-wu这个服务中的htllo接口与hello2接口,回退接口实现是InterTextImpl类
@FeignClient(name= "ti-gong-fu-wu",fallback = InterTextImpl.class)
public interface InterText {
	@RequestMapping(value = "/hello")
	public String hello(@RequestParam(value = "name") String name);
	@RequestMapping(value = "/hello2")
	public String hello2(@RequestParam(value = "name") String name);
}
//回退实现类
@Component
public class InterTextImpl implements InterText{
	@Override
	public String hello(String name) {
		return "hello" +name+", 此消息发送失败 ";
	}
	@Override
	public String hello2(String name) {
		// TODO Auto-generated method stub
		return "这是" +name+",  hello2  此消息发送失败 ";
	}
}
配置文件:
#服务名称
spring:
  application:
    name: xiao-fei-fu-wu-dashboard
#服务端口
server:
  port: 9004
#熔断器,配置在调用方
feign:
  hystrix:
    enabled: true
#注册中心地址
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:9000/eureka/
management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream

消费提供方

导包:
<parent>
    <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-parent</artifactId>
        <version>Finchley.SR4</version>
        <relativePath/>
  </parent>
  <dependencies>
			  <dependency>
			      <groupId>org.springframework.boot</groupId>
			      <artifactId>spring-boot-starter-web</artifactId>
		    </dependency>
	  
	  <!-- springcloud 导入包 -->
		  <!-- springcloud eureka包导入 -->
				<dependency>
				    <groupId>org.springframework.cloud</groupId>
				    <!-- eureka客户端导包 -->
				    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
				</dependency>
		  <!-- hystrix熔断 -->
		  <dependency> 
			<groupId>org.springframework.cloud</groupId> 
			<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> 
		</dependency> 
	
    </dependencies>
		    <repositories>
		        <repository>
		            <id>spring-milestones</id>
		            <name>Spring Milestones</name>
		            <url>https://repo.spring.io/milestone</url>
		        </repository>
		    </repositories>
		    <build>
		    <plugins>
		      <plugin>
		        <groupId>org.springframework.boot</groupId>
		        <artifactId>spring-boot-maven-plugin</artifactId>
		        <configuration>
		          <fork>true</fork>
		        </configuration>
		      </plugin>
		    </plugins>
		  </build>
配置文件:
#服务名称
spring:
  application:
    name: ti-gong-fu-wu
#服务端口
server:
  port: 9002
#注册中心地址
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:9000/eureka/
   启动类:
@SpringBootApplication
@RestController
@EnableEurekaClient
public class AssetApplication {
	    public static void main(String[] args) {
	    	SpringApplication.run(AssetApplication.class, args);
	    }
}
提供的hello与hello2服务
@RestController
public class ControllerText {
	/**
	 * 提供服务
	 * @Descrption
	 * @author miaoYongChao
	 * @date 2020年6月9日下午5:42:11
	 * @param name
	 * @return
	 */
	@RequestMapping("/hello")
    public String index(@RequestParam String name) {
        return "hello "+name+",this is producer 2  send first messge";
    }
	/**
	 * 提供服务
	 * @Descrption
	 * @author miaoYongChao
	 * @date 2020年6月9日下午5:42:11
	 * @param name
	 * @return
	 */
	@RequestMapping("/hello2")
    public String index2(@RequestParam String name) {
        return "这是 "+name+",this is producer 2  send first messge";
    }
}

分别启动注册中心,提供服务端,消费服务端(这里默认你已经使用了注册中心)
访问:http://localhost:9004/actuator/hystrix.stream不断的出现ping,这是因为还没有请求,我们访问http://localhost:9004/hello/neo,这时候发现已经可以访问了,仪表盘监控如图二
图一在这里插入图片描述我们看到了监控界面,输入我们要访问的地址http://localhost:9004/actuator/hystrix.stream点击Monitor Stream就可以了
在这里插入图片描述我们将会看到上界面,证明我们搭建成功。
要点:监控盘可以帮助我们看见服务提供方单个接口被请求的情况,以及短路器当前状况,但如果在运维过程中,我们需要每个接口都这样访问,那当成千上百接口时,我们的运维状况可想而知,所以我们需要一个可以监控所有接口的工具Turbine应运而生,下篇文章我们来介绍它如何使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值