spring cloud 学习(8) - sleuth & zipkin 调用链跟踪
业务复杂的微服务架构中,往往服务之间的调用关系比较难梳理,一次http请求中,可能涉及到多个服务的调用(eg: service A -> service B -> service C...),如果想分析各服务间的调用关系,以及各服务的响应耗时,找出有性能瓶颈的服务,这时zipkin就派上用场,它是Twitter公司开源的一个tracing系统,官网地址为: http://zipkin.io/ , spring cloud可以跟它无缝集成。
使用步骤:
一、微服务方
1.1 添加依赖jar包
compile 'org.springframework.cloud:spring-cloud-starter-bus-kafka'
compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
compile 'org.springframework.cloud:spring-cloud-sleuth-stream'
注:为了实现tracing数据埋点与采集的解耦,spring cloud引入了message bus(消息总线)的概念,微服务无需关心tracing系统在哪,长什么样,只要向bus总线上扔消息就行,所以引入了bus-kafka以及sleuth-stream。
1.2 application.yml配置
spring:
...
cloud:
bus:
enabled: true
stream:
default-binder: kafka
kafka:
binder:
brokers: 10.0.1.2,10.0.1.3,10.0.1.4 //kafaka的服务器集群列表
zkNodes: 10.0.1.5,10.0.1.6,10.0.1.7 //zk的服务器集群列表
defaultZkPort: 2181 //zk的端口
defaultBrokerPort: 9092 //kafka的broker端口
...
sleuth:
sampler:
percentage: 0.2 //采样率 0.2为20%
上面2项配置好就行了,代码不用任何修改,真正的代码零侵入
二、zipkin-server
zipkin从kafka上接收过来数据后,有4种保存方式:in-memory(保存在内存中)、mysql、cassandra、elasticsearch
个人开发调试的话,推荐用in-memory模式,其它环境不要使用!(注:因为随着收集的数据越来越多,都放在内存中 很容易造成OOM)
2.1 mysql 存储
2.1.1 主要jar包依赖
dependencies {
... 关键是下面几个
compile 'org.springframework.cloud:spring-cloud-starter-sleuth'
compile 'org.springframework.cloud:spring-cloud-sleuth-zipkin-stream'
compile 'org.springframework.cloud:spring-cloud-starter-bus-kafka'
compile 'io.zipkin.java:zipkin-server'
compile 'io.zipkin.java:zipkin-autoconfigure-ui'
compile 'io.zipkin.java:zipkin-autoconfigure-storage-mysql' #mysql的存储
... 下面几个是spring-boot/cloud的常规项
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'log4j:log4j:1.2.17' //zipkin的storage jar包,依赖低版本的log4j
compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.8.2'
compile 'mysql:mysql-connector-java:6.0.5'
}
2.1.2 application.yml配置
spring:
application:
name: zipkin-server
datasource: //指定mysql数据源
schema: classpath:/mysql.sql
url: jdbc:mysql://192.168.1.2:3306/zipkin?autoReconnect=true&useSSL=false
username: root
password: ***
driver-class-name: com.mysql.cj.jdbc.Driver
initialize: true
continue-on-error: true
sleuth:
enabled: false
cloud:
bus:
enabled: true
...
stream:
default-binder: kafka
kafka:
binder:
brokers: ${kafka.brokers}
zkNodes: ${kafka.zkNodes}
defaultZkPort: ${kafka.zkPort}
defaultBrokerPort: ${kafka.brokerPort} zipkin:
storage:
type: mysql //配置成mysql存储
2.1.3 main入口代码
@SpringBootApplication(exclude = {
MybatisAutoConfiguration.class,
RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class})
@EnableZipkinStreamServer
public class ZipkinServer {
public static void main(String[] args) {
SpringApplication.run(ZipkinServer.class, args);
}
}
注:如果你的项目中依赖了redis,mybatis等其它包,可以参考上面的写法,排除掉这些自动配置,否则的话,不用加那一堆exclude。
2.2 cassandra
2.2.1 依赖jar包
注:cassandra和elasticsearch下,可能会遇到zipkin中的dependencies面板无数据,详情见github上的讨论:https://github.com/openzipkin/zipkin-dependencies/issues/22
compile 'org.springframework.boot:spring-boot-starter-data-cassandra'
compile('io.zipkin.java:zipkin-autoconfigure-storage-cassandra3:1.29.3') {
exclude group: "com.datastax.cassandra", module: "cassandra-driver-core"
}
compile 'com.datastax.cassandra:cassandra-driver-core:3.1.1'
compile 'com.datastax.cassandra:cassandra-driver-mapping:3.1.1'
2.2.2 application.yml
spring:
data:
cassandra:
contact-points: localhost
port: 9042
keyspace-name: zipkin3
... zipkin:
storage:
type: cassandra3
2.3 elasticsearch
2.3.1 依赖jar包
compile 'io.zipkin.dependencies:zipkin-dependencies-elasticsearch:1.7.2'
compile 'io.zipkin.java:zipkin-autoconfigure-storage-elasticsearch-http:1.29.2'
2.3.2 application.yml
zipkin:
storage:
type: elasticsearch
elasticsearch:
cluster: elasticsearch
hosts: http://localhost:9200
index: zipkin
index-shards: 5
index-replicas: 1
spring cloud 学习(8) - sleuth & zipkin 调用链跟踪的更多相关文章
- Spring Cloud 微服务六:调用链跟踪Spring cloud sleuth +zipkin
前言:随着微服务系统的增加,服务之间的调用关系变得会非常复杂,这给运维以及排查问题带来了很大的麻烦,这时服务调用监控就显得非常重要了.spring cloud sleuth实现了对分布式服务的监控解决 ...
- Spring Cloud Alibaba(15)---Sleuth+Zipkin
SpringCloudAlibaba整合Sleuth+Zipkin 有关Sleuth之前有写过两篇文章 Spring Cloud Alibaba(13)---Sleuth概述 Spring Cloud ...
- SpringCloud学习之sleuth&zipkin
一.调用链跟踪的必要性 首先我们简单来看一下下单到支付的过程,别的不多说,在业务复杂的时候往往服务会一层接一层的调用,当某一服务环节出现响应缓慢时会影响整个服务的响应速度,由于业务调用层次很“深”,那 ...
- Spring Cloud Alibaba(13)---Sleuth概述
Sleuth概述 前言 在微服务架构中,众多的微服务之间互相调用,如何清晰地记录服务的调用链路是一个需要解决的问题.同时,由于各种原因,跨进程的服务调用失败时,运维人员希望能够通过 查看日志和查看服务 ...
- Spring Cloud 系列之 Sleuth 链路追踪(二)
本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Sleuth 链路追踪(一) 本篇文章讲解 Sleuth 基于 Zipkin 存储链路追踪数据至 MySQL,Elas ...
- dubbo+zipkin调用链监控
分布式环境下,对于线上出现问题往往比单体应用要复杂的多,原因是前端的一个请求可能对应后端多个系统的多个请求,错综复杂. 对于快速问题定位,我们一般希望是这样的: 从下到下关键节点的日志,入参,出差,异 ...
- spring cloud 学习之服务消费者(rest+ribbon)
学习自 http://blog.csdn.net/forezp/article/details/81040946 方志朋的博客 在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于h ...
- Spring Cloud学习(一):Eureka服务注册与发现
1.Eureka是什么 Eureka是Netflix开发的服务发现框架,本身是一个基于REST的服务,主要用于定位运行在AWS域中的中间层服务,以达到负载均衡和中间层服务故障转移的目的. Eureka ...
- Spring Cloud 系列之 Sleuth 链路追踪(三)
本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Sleuth 链路追踪(一) Spring Cloud 系列之 Sleuth 链路追踪(二) 本篇文章讲解 Sleu ...
随机推荐
- ASP.NET实现二维码(QRCode)的创建和读取
一.项目引用QRCode的DLL文件(ThoughtWorks.QRCode.dll) 二.ASPX页面(两个jquery的js文件请自行去官网下载): [html] <html xm ...
- Anaconda+django写出第一个web app(六)
今天学习如何写一个注册用户的界面. 上一节的导航栏中我们修改了导航栏右侧的文字为register并将路径设置为/register,内容如下: <li><a href="/r ...
- 关于caffe的安装问题
在caffe的安装过程中,出现 /usr/bin/ld: cannot find -lcblas /usr/bin/ld: cannot find -latlas的问题 这时解决方案为http://s ...
- RabbitMQ消费端消息的获取方式(.Net Core)
1[短链接]:BasicGet(String queue, Boolean autoAck) 通过request的方式独自去获取消息,断开式,一次次获取,如果返回null,则说明队列中没有消息. 隐患 ...
- 【ARTS】01_04_左耳听风-20181203~1209
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Socket心跳包机制【转】
转自:https://blog.csdn.net/xuyuefei1988/article/details/8279812 心跳包的发送,通常有两种技术 方法1:应用层自己实现的心跳包 由应用程序自己 ...
- innobackupex不停库的数据备份并恢复到别的服务器上【转】
1.innobackupex原理: 备份原理 1).首先会开启一个后台检测进程,实时检测myql redo的变化,一旦发现redo中有新日志写入,立即将日志记入后台日志文件xtrabackup_log ...
- 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+kibanaV5.4.2+x-packV5.4.2安装
相关博文: 搜索引擎ElasticSearchV5.4.2系列一之ES介绍 搜索引擎ElasticSearchV5.4.2系列二之ElasticSearchV5.4.2+klanaV5.4.2+x-p ...
- linux终端自定义设置
2014年1月4日 19:21:16 1. ls命令显示文件列表时不再花花绿绿 vi ~/.bashrc alias ls='ls -a --color=never' alias ll='ls -lh ...
- How to return plain text from AWS Lambda & API Gateway
With limited experience in AWS Lambda & API Gateway, it's struggling to find the correct way to ...