springboot+zipkin+docker实例

zipkin-server

  • pom


            io.zipkin
            zipkin-ui
            1.39.3
        
        
            org.springframework.boot
            spring-boot-starter-jdbc
        
        
            org.springframework.cloud
            spring-cloud-sleuth-zipkin-stream
            1.0.0.RELEASE
        
        
            org.springframework.cloud
            spring-cloud-starter-stream-rabbit
            1.0.0.RELEASE
        
        
            
            
        
        
            com.h2database
            h2
        
  • application.yaml

spring:
  rabbitmq:
    addresses: rabbitmq
#  datasource:
#      #脚本位置:依赖spanstore-jdbc-0.9.3.jar内
##    schema: classpath:/mysql.sql
#    url: jdbc:mysql://zipkin_mysql:3306/zipkin
#    username: zipkin
#    password: zipkin
#      # Switch this on to create the schema on startup:
#    initialize: true
#    continueOnError: true


  sleuth:
   # not use sleuth stream to trace zipkin server itself
    enabled: false
    #refer to org.springframework.cloud.sleuth.instrument.hystrix.SleuthHystrixAutoConfiguration.java
    hystrix:
      strategy:
        enabled: false

zipkin:
  storage:
    type: mem #mysql #mem
  • application

@EnableZipkinStreamServer
@SpringBootApplication
public class ZipkinServerApplication {

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

zipkin-client

  • pom


        
            org.springframework.boot
            spring-boot-starter-aop
        
        
            org.springframework.cloud
            spring-cloud-sleuth-stream
            1.0.0.RELEASE
        
        
            org.springframework.cloud
            spring-cloud-starter-stream-rabbit
            1.0.0.RELEASE
        
        
            org.springframework.cloud
            spring-cloud-starter-ribbon
            1.0.6.RELEASE
            
                
                    io.reactivex
                    rxjava
                
            
        
        
            io.reactivex
            rxjava
            1.1.5
        
  • application.yml

spring:
# mq stream format to send trace data
  rabbitmq:
    addresses: rabbitmq
  #zipkin config
  zipkin:
      #defult is true,to use zipkin,false:not use
    enabled: true
    baseUrl: http://zipkin:9411/

    sleuth:
      sampler:
        # 采样率,默认0.1即10%,如需测试时每次都看到trace则修改为1.0,但对性能有影响,注意上线时修改为合理值
        percentage: 1.0
      hystrix:
        strategy:
          enabled: true
      #https://github.com/ReactiveX/RxJava/issues/2297
      rxjava:
        schedulers:
          hook:
            enabled: false
      # stream format  to send trace msg: enable sleuth.stream to use stream
      # default is true,refer to SleuthStreamAutoConfiguration.java
      stream:
        enabled: true
      # skip tracing urls' pattern,refer to org.springframework.cloud.sleuth.instrument.web.TraceWebAutoConfiguration
      #web:
        #skipPattern: /eureka.*

# zipkin properties for ServiceApplication.java to debug when there is no zipkin server
sample:
  zipkin:
    # When enabled=false, traces log to the console. Comment to send to zipkin
    enabled: true
  • application

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrix
@EnableHystrixDashboard
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
public class TraceDemoApplication {

    @Bean
    Sampler sampler() {
        return new AlwaysSampler();
    }

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

docker-compose

rabbitmq:
  image: rabbitmq:management
  expose:
    - 5672
    - 15672
  ports:
    - 5672:5672
    - 15672:15672
zipkin:
  image: zipkin-server
  restart: always
  ports:
   # Listen port for the Scribe transport
      - "9410:9410"
        # Historical port used for the Zipkin HTTP Api
      - "9411:9411"
      - "9901:9901"
  links:
    - rabbitmq

trace_demo:
  image: trace-demo
  restart: always
  ports:
    - "9998:9998"
  links:
    - discovery
    - config
    - rabbitmq
    - zipkin    

运行

http://192.168.99.100:9411/

springboot+zipkin+docker实例_第1张图片

查询

springboot+zipkin+docker实例_第2张图片

参考

  • opentracing规范

  • Diving Deeper into ‘Getting Started with Spring Cloud’

  • Distributed Tracing with Spring Cloud Sleuth and Spring Cloud Zipkin(推荐)

  • docs-spring-cloud-sleuth(推荐)

  • Dapper:谷歌的大规模分布式跟踪系统

  • 分布式服务的Trace——Google Dapper & Twitter Zipkin

  • Make RxJavaPlugins.reset() public

  • docker-zipkin

你可能感兴趣的:(docker,zipkin,springboot)