pom.xml代码:
4.0.0 com.joyce joyce-component-zipkin 1.0 jar org.springframework.boot spring-boot-starter-parent 1.5.20.RELEASE org.springframework.cloud spring-cloud-dependencies Edgware.SR5 pom import org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-netflix-hystrix org.springframework.cloud spring-cloud-starter-netflix-hystrix-dashboard org.springframework.cloud spring-cloud-starter-zipkin org.springframework.cloud spring-cloud-starter-netflix-ribbon org.springframework.boot spring-boot-starter-web io.zipkin.java zipkin-server io.zipkin.java zipkin-autoconfigure-ui io.zipkin.java zipkin-autoconfigure-storage-elasticsearch-http 2.8.4 true com.squareup.okhttp3 okhttp org.springframework.cloud spring-cloud-sleuth-zipkin junit junit test org.springframework.boot spring-boot-starter-test test
application.properties配置文件代码:
server.port=8740spring.application.name=joyce-component-zipkineureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka,http://localhost:8762/eureka,http://localhost:8763/eurekaeureka.client.registerWithEureka=trueeureka.client.fetchRegistry=trueeureka.instance.instance-id=${spring.application.name}:${server.port}eureka.instance.prefer-ip-address=true#接受zipkin追踪,追踪数据会传导给turbine实时监控(如果存在)spring.zipkin.enabled=truespring.sleuth.feign.enabled=truespring.sleuth.hystrix.strategy.enabled=truespring.sleuth.sampler.percentage=1.0spring.zipkin.base-url=http://joyce-component-zipkin############################## ES单点连接 #######################zipkin.storage.type=elasticsearch#zipkin.storage.elasticsearch.hosts=192.168.10.140:9200#zipkin.storage.elasticsearch.max-requests=100#zipkin.storage.elasticsearch.index=zipkin#zipkin.storage.elasticsearch.index-shards=0#zipkin.storage.elasticsearch.index-replicas=0############################## ES集群连接,使用用户名和密码 ######################zipkin.storage.type=elasticsearch //使用elasticsearch存储zipkin追踪数据zipkin.storage.elasticsearch.cluster=joyce-elasticsearch //集群的cluster namezipkin.storage.elasticsearch.hosts=192.168.10.110:9200,192.168.10.120:9200,192.168.10.130:9200zipkin.storage.elasticsearch.max-requests=100zipkin.storage.elasticsearch.timeout=1000 zipkin.storage.elasticsearch.index=zipkin //存储zipkin数据时,ES的数据索引以zipkin为前缀,示例:zipkin-2019-06-09zipkin.storage.elasticsearch.date-separator=- //ES索引数据的日期分隔符,默认为“-”zipkin.storage.elasticsearch.index-shards=6 //集群的分片个数zipkin.storage.elasticsearch.index-replicas=0 //集群的备(从)个数zipkin.storage.elasticsearch.username=elastic //用户名zipkin.storage.elasticsearch.password=1234567 //密码
zipkin.storage.type前缀注入到zipkin-autoconfigure-storage-elasticsearch-http-2.8.4.jar包里的TracingZipkinElasticsearchHttpStorageAutoConfiguration类。
@ConditionalOnBean(Tracing.class)@ConditionalOnProperty(name = "zipkin.storage.type", havingValue = "elasticsearch")@Configurationclass TracingZipkinElasticsearchHttpStorageAutoConfiguration {
zipkin.storage.elasticsearch前缀注入到zipkin-autoconfigure-storage-elasticsearch-http-2.8.4.jar包里的ZipkinElasticsearchHttpStorageProperties类。
@ConfigurationProperties("zipkin.storage.elasticsearch")class ZipkinElasticsearchHttpStorageProperties implements Serializable {
SpringCloud启动类代码:
package com.joyce.zipkin;import org.slf4j.LoggerFactory;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.cloud.netflix.hystrix.EnableHystrix;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;import zipkin.server.internal.EnableZipkinServer;@SpringBootApplication@EnableZipkinServer@EnableHystrix@EnableHystrixDashboard@EnableEurekaClientpublic class ComponentZipkinApplication { private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(ComponentZipkinApplication.class); public static void main(String[] args) { SpringApplication.run(ComponentZipkinApplication.class, args); }}