-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
服务链路追踪zipkin
- 下载zipkin,并运行
java -jar zipkin-server-2.10.3-exec.jar
- 访问http://localhost:9411/ ,会看到zipkin控制台
- 新建zipkin-service-hi工程,加入zipkin起步依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zipkin</artifactId> </dependency>
- 设置application.properties
server.port=8448 spring.zipkin.base-url=http://localhost:9411 spring.application.name=service-hi
spring.zipkin.base-url设置zipkin地址 - 在启动类中声明接口
其中defaultSampler设置采样比率
@SpringBootApplication @RestController public class ZipkinServerHiApplication { public static void main(String[] args) { SpringApplication.run(ZipkinServerHiApplication.class, args); } @Autowired private RestTemplate restTemplate; @Bean public RestTemplate getRestTemplate() { return new RestTemplate(); } @RequestMapping("/hi") public String hi() { return restTemplate.getForObject("http://localhost:8446/miya", String.class); } @RequestMapping("/info") public String info() { return "zipkin-server-hi"; } @Bean public Sampler defaultSampler() { return Sampler.ALWAYS_SAMPLE; } }
- 同样的,新建zipkin-service-miya工程,加入zipkin起步依赖
配置application.propertiesserver.port=8446 spring.zipkin.base-url=http://localhost:9411 spring.application.name=service-miya
- 同样在启动类中暴露接口
@SpringBootApplication @RestController public class ZipkinServerMiyaApplication { public static void main(String[] args) { SpringApplication.run(ZipkinServerMiyaApplication.class, args); } @Autowired private RestTemplate restTemplate; @Bean public RestTemplate getRestTemplate() { return new RestTemplate(); } @RequestMapping("/hi") public String hi() { return "zipkin-server-miya"; } @RequestMapping("/miya") public String info() { return restTemplate.getForObject("http://localhost:8448/info",String.class); } @Bean public Sampler defaultSampler() { return Sampler.ALWAYS_SAMPLE; } }
- 访问http://localhost:8446/miya , 看到返回如下结果
zipkin-server-hi
- 访问http://localhost:9411/ ,选择依赖分析(Dependencies),可看到服务依赖关系
选择查找调用链(find a traces),点击find traces,可以看到调用日志
自建zipkin
在spring cloud f版本后,才有zipkin jar包,f以下版本需要自建
- 创建工程server-zipkin,加入以下依赖
<dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-server</artifactId> </dependency> <dependency> <groupId>io.zipkin.java</groupId> <artifactId>zipkin-autoconfigure-ui</artifactId> </dependency>
- 在application启动类,加入
@EnableZipkinServer - 在配置文件application.properties声明服务端口即可
server.port=9411
Reactions are currently unavailable