分布式跟踪工具
| 公司 | 选项 | 是否开源 | 优缺点 |
|---|---|---|---|
| 淘宝 | EagleEye | 否 | 主要基于内部HSF实现,HSF没有开源,故鹰眼也没有开源 |
| Zipkin | 是 | 基于Http实现,支持语言较多 | |
| 点评 | CAT | 是 | 自定义改造难度大,代码比较复杂,侵入代码,需要埋点 |
| 京东 | Hydra | 是 | 主要基于Dubbo实现,不适合Http请求 |
| 开源 | Pinpoint | 是 | 方便且容易上手,Http请求 |
| 开源 | skywalking | 是 | HTTP 或 gRPC |
例子
微服务示例应用程序是使用客户端服务发现的应用程序的示例。它是用Scala编写的,使用Spring Boot和Spring Cloud作为微服务机箱。它们提供各种功能,包括Spring Cloud Sleuth,它为分布式跟踪提供支持。它可以检测Spring组件以收集跟踪信息,并将其传送到Zipkin服务器,Zipkin服务器收集并显示跟踪信息。 以下Spring Cloud Sleuth依赖项配置build.gradle如下:
dependencies {
compile "org.springframework.cloud:spring-cloud-sleuth-stream"
compile "org.springframework.cloud:spring-cloud-starter-sleuth"
compile "org.springframework.cloud:spring-cloud-stream-binder-rabbit"
RabbitMQ用于向Zipkin提供痕迹。
使用以下各种设置的各种Spring Cloud Sleuth相关环境变量部署服务docker-compose.yml:
environment:
SPRING_RABBITMQ_HOST: rabbitmq
SPRING_SLEUTH_ENABLED: "true"
SPRING_SLEUTH_SAMPLER_PERCENTAGE: 1
SPRING_SLEUTH_WEB_SKIPPATTERN: "/api-docs.*|/autoconfig|/configprops|/dump|/health|/info|/metrics.*|/mappings|/trace|/swagger.*|.*\\.png|.*\\.css|.*\\.js|/favicon.ico|/hystrix.stream"
此属性启用Spring Cloud Sleuth并将其配置为对所有请求进行采样。它还告诉Spring Cloud Sleuth通过在主机上运行的RabbitMQ向Zipkin提供跟踪rabbitmq。
Zipkin服务器是一个简单的Spring Boot应用程序:
@SpringBootApplication
@EnableZipkinStreamServer
public class ZipkinServer {
public static void main(String[] args) {
SpringApplication.run(ZipkinServer.class, args);
}
}
它使用Docker部署:
zipkin:
image: java:openjdk-8u91-jdk
working_dir: /app
volumes:
- ./zipkin-server/build/libs:/app
command: java -jar /app/zipkin-server.jar --server.port=9411
links:
- rabbitmq
ports:
- "9411:9411"
environment:
RABBIT_HOST: rabbitmq