分布式服务链路追踪系统Zipkin学习记录

匿名 (未验证) 提交于 2019-12-03 00:20:01

Zipkin是一个分布式追踪系统。它有助于收集解决微服务架构中延迟问题所需的时序数据。它管理这些数据的收集和查找。Zipkin的设计基于Google Dapper论文。

应用程序用于向Zipkin报告时间数据。Zipkin用户界面还提供了一个依赖关系图,显示每个应用程序有多少跟踪请求。如果您正在解决延迟问题或错误问题,则可以根据应用程序,跟踪长度,注释或时间戳过滤或排序所有跟踪。一旦选择了一个跟踪,您可以看到每个跨度所花费的总跟踪时间的百分比,从而可以确定问题应用程序。


官网地址:https://zipkin.io/

github 地址 :https://github.com/openzipkin/zipkin

为什么使用Zipkin

随着业务越来越复杂,系统也随之进行各种拆分,特别是随着微服务架构和容器技术的兴起,看似简单的一个应用,后台可能有几十个甚至几百个服务在支撑;一个前端的请求可能需要多次的服务调用最后才能完成;当请求变慢或者不可用时,我们无法得知是哪个后台服务引起的,这时就需要解决如何快速定位服务故障点,Zipkin分布式跟踪系统就能很好的解决这样的问题。


三种启动方式

docker 启动

docker run -d -p 9411:9411 openzipkin/zipkin


curl -sSL https://zipkin.io/quickstart.sh | bash -s java -jar zipkin.jar

依赖

<dependency>    <groupId>io.zipkin.java</groupId>    <artifactId>zipkin-server</artifactId> </dependency> <dependency>    <groupId>io.zipkin.java</groupId>    <artifactId>zipkin-autoconfigure-ui</artifactId> </dependency>

默认内存存储

添加mysql 存储

<dependency>    <groupId>io.zipkin.java</groupId>    <artifactId>zipkin-autoconfigure-storage-mysql</artifactId> </dependency> <dependency>    <groupId>mysql</groupId>    <artifactId>mysql-connector-java</artifactId> </dependency> <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency>    <groupId>com.zaxxer</groupId>    <artifactId>HikariCP</artifactId> </dependency>
配置 数据库

CREATE TABLE IF NOT EXISTS zipkin_spans (   `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',   `trace_id` BIGINT NOT NULL,   `id` BIGINT NOT NULL,   `name` VARCHAR(255) NOT NULL,   `parent_id` BIGINT,   `debug` BIT(1),   `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL',   `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query' ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;  ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate'; ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations'; ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds'; ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames'; ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range';  CREATE TABLE IF NOT EXISTS zipkin_annotations (   `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit',   `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id',   `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id',   `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1',   `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB',   `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation',   `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp',   `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null',   `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address',   `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null',   `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null' ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;  ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate'; ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans'; ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds'; ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames'; ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces'; ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces'; ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job';  CREATE TABLE IF NOT EXISTS zipkin_dependencies (   `day` DATE NOT NULL,   `parent` VARCHAR(255) NOT NULL,   `child` VARCHAR(255) NOT NULL,   `call_count` BIGINT,   `error_count` BIGINT ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;  ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

client 端的配置

<dependency>    <groupId>org.springframework.cloud</groupId>    <artifactId>spring-cloud-starter-sleuth</artifactId> </dependency> <dependency>    <groupId>org.springframework.cloud</groupId>    <artifactId>spring-cloud-sleuth-zipkin</artifactId> </dependency>

启动运行的结果图

服务之间依赖调用关系图


CassandraElasticsearch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!