SpringCloud--Sleuth链路监控

修改cloud-provider-payment8001模块

添加依赖:

        
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-zipkinartifactId>
        dependency>

application.yml添加配置:

spring:
  application:
    name: cloud-payment-service
  zipkin:
      base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1 #采样率介于0到1之间,1表示全部采集

Controller添加方法:

//链路监控
    @GetMapping("/payment/zipkin")
    public String paymentZipkin() {
        return "监控链路..........";
    }

修改cloud-consumer-order80模块

添加依赖:

        
        <dependency>
            <groupId>org.springframework.cloudgroupId>
            <artifactId>spring-cloud-starter-zipkinartifactId>
        dependency>

application.yml添加配置:

spring:
  application:
    name: cloud-order-service
  zipkin:
      base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1 #采样率介于0到1之间,1表示全部采集

Controller添加方法:

//zipkin+sleuth
    @GetMapping("/consumer/payment/zipkin")
    public String paymentZipkin() {
        String result = restTemplate.getForObject(PAYMENT_URL + "/payment/zipkin/", String.class);
        return result;
    }

测试

启动zipkiin server,启动eureka,启动80和8001端口微服务:
SpringCloud--Sleuth链路监控_第1张图片

访问:localhost/consumer/payment/zipkin
SpringCloud--Sleuth链路监控_第2张图片

访问9411控制台:
SpringCloud--Sleuth链路监控_第3张图片
SpringCloud--Sleuth链路监控_第4张图片

你可能感兴趣的:(SpringCloud)