Kite的学习历程SpringCloud之Zipkin链路监控

Kite学习历程的第二十六天

1.Zilpin配置文件的下载以及运行

  1. 在官网就可以进行下载
    在这里插入图片描述
  2. 运行,在控制台输入 java -jar加文件名
    在这里插入图片描述
    表明Zipkin启动成功
  3. 访问: http://localhost:9411在这里插入图片描述

2. 在服务端8001,客户端80进行配置

2.1 cloud-provider-payment-8001配置

2.1.1 映入新的依赖文件
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>

2.1.3 修改application.yml配置文件

添加部分:设置了zipkin的访问端口

zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1


server:
  port: 8001

spring:
  application:
    name: cloud-payment-service

  datasource:
    type: com.alibaba.druid.pool.DruidDataSource   #当前数据源的操作类型
    driver-class-name: com.mysql.jdbc.Driver #mysql驱动包
    url: jdbc:mysql:///db2020?characterEncoding=utf8&serverTimezone=GMT%2B8
    username: root
    password: 25002500
  jpa:
    show-sql: true

  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: cn.kitey.springcloud.entities  #所有的Entity所在的包

eureka:
  client:
    register-with-eureka: true # 是否注册自己的信息到EurekaServer,默认是true
    fetch-registry: true # 是否拉取其它服务的信息,默认是true
    service-url: # EurekaServer的地址,现在是自己的地址,如果是集群,需要加上其它Server的地址。
#      defaultZone: http://localhost:7001/eureka
      #下面的为集群版
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
      # 单机模式
#      defaultZone: http://eureka7001.com:7001/eureka
  instance:
#    主机名的修改
    instance-id: payment8001
    #访问路径可以显示ip地址
    prefer-ip-address: true

#
#    #Eureka客户端向服务器发送的时间间隔,默认30秒
#    lease-renewal-interval-in-seconds: 1
#    #Eureke服务端在收到最后一次信息后等待的时间上线,默认90秒
#    lease-expiration-duration-in-seconds: 2

2.1.4 在controller中添加测试方法

成功访问则会返回:
hello Zipkin

   @GetMapping("/payment/zipkin")
    public String paymentZipkin(){
        return "hello Zipkin";
    }

2.2 配置cloud-consumer-order-80微服务

2.2.1 在pom.xml中引入依赖

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zipkin</artifactId>
        </dependency>
2.2.2 修改application配置文件

添加:
跟8001添加的一样

  zipkin:
    base-url: http://localhost:9411
  sleuth:
    sampler:
      probability: 1
2.2.3 在controller中添加测试方法

调用8001中的方法

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


3 进行测试

  1. 打开注册中心7001,服务端8001,客户端80
    在这里插入图片描述
  2. 访问:http://localhost:81/consumer/payment/zipkin
    访问成功,多点几次
    在这里插入图片描述
  3. 在Zipkin进行查看
    在这里插入图片描述
    在这里插入图片描述
    可以查看到链路监控
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值