Sleuth zipkin 鏈路監(jiān)控

一、本地安裝

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

二、在本地創(chuàng)建數(shù)據(jù)庫

  1. 在本地電腦創(chuàng)建 mysql 數(shù)據(jù)庫 zipkin
  2. 數(shù)據(jù)庫中創(chuàng)建存儲表
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
) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci;
ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`);

三、運行

執(zhí)行以下命令,運行zipkin,日志會保存至本地數(shù)據(jù)庫。

 STORAGE_TYPE=mysql MYSQL_DB=zipkin MYSQL_USER=root MYSQL_PASS=admin java -jar zipkin.jar

四、項目中集成 Sleuth 及 zipkin

在資源文件application.properties下指定 Sleuth 的zipkin.baseUrl,例如下面這樣配置。baseUrl指向安裝有zipkin的服務器上面去。這樣在該服務器上面瀏覽器訪問 http://your_host:9411 即可查看鏈路監(jiān)控狀態(tài)了。

eg.

spring.zipkin.baseUrl=http://your_host:9411 

參考鏈接:

  1. https://github.com/openzipkin/zipkin
  2. https://github.com/openzipkin/zipkin/tree/master/zipkin-storage/mysql
  3. https://github.com/openzipkin/zipkin/blob/master/zipkin-storage/mysql/src/main/resources/mysql.sql
  4. http://blog.csdn.net/liaokailin/article/details/52077620
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,569評論 19 139
  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,877評論 2 45
  • 不知道怎么,我忽然想念起家里需要插秧的日子。那時候全家都很忙啊,中午放學回家家里空空的,你得歇一會媽媽或者奶奶又或...
    onematchleft閱讀 294評論 0 0
  • 開篇: 這一整周學了JS的基礎部分,一開始懷著輕松加愉快的的想法,認為JS這么簡單的東西還不好學嗎,畢竟我是學過C...
    帥帥噠小白閱讀 604評論 4 1
  • 已經(jīng)堅持了那么久,應該能繼續(xù)堅持下去, 春天來了,告訴自己,又是新的開始 把思念揉成碎片,卻拋不出去, 枝頭綻放的...
    小金甲閱讀 190評論 0 0

友情鏈接更多精彩內(nèi)容