Spring Cloud Alibaba combat (xiii) - Sleuth call chain monitoring

This article outlines: vernacular call chain analysis monitoring principle and then learn Sleuth, Zipkin, then Sleuth integrate Zipkin, finally learning Zipkin data persistence (Elasticsearch) and Zipkin dependency graph

  • Combat Thus, the basic functions have all been achieved

1 call chain analysis monitoring principle

If our project is abnormal, and how to do it?

1.1 locate the problem needs

API ◆ Cross-micro services call abnormal, rapid positioning requirements (such as five minutes or less) the problem went wrong, how to do?
API call occurs ◆ performance bottlenecks across micro services, requires rapid location (for example, 5 minutes or less) out system bottlenecks, how to do?

In both cases, the traditional way is difficult to solve, call chain monitoring tools to troubleshoot (somewhat similar to the call stack logs Linux kernel oh)

Call chain monitoring tools can be described as an indispensable tool for distributed project maintenance!

The basic principles of monitoring 1.2

  • Instance, for this item, a request to monitor the following
  • It is defined as four times the node
  • Maintains a trace data from relational tables in the DB: API that uniquely identifies the parent spanid, service name, call, four nodes of stage time, timestamp data happened

    this way, under normal circumstances, the first call, DB generates four pieces of data, you can know what stage the problem!

2 is elegantly Sleuth

2.1 What is Sleuth

  • Official Positioning: Sleuth is a Spring Cloud Distributed tracking solution
    speak words that people call chain monitoring tools Client

2.2 The term entry

Span (SPAN)

Sleuth basic working unit, which with the id uniquely identifies a 64-bit.
In addition to the ID, span also contain additional data, such as described, event timestamp, annotations value pairs (label), span ID, span the parent ID and the like.

In front of a piece of data in our DB is a span

trace (trace)

Span tree structure consisting of a group called trace

That is in complete four data DB

Annotation (annotation)

● CS ( Client Sent客户端发送)
客户端发起一一个请求,该annotation描述了span的开始。
●SR ( Server Received服务器端接收)
服务器端获得请求并准备处理它。
●SS( Server Sent服务器端发送)
该annotation表明完成请求处理(当响应发回客户端时)。
●CR( Client Received客户端接收)
span结束的标识。客户端成功接收到服务器端的响应。

2.3 为用户中心整合Sleuth

  • 添加依赖


    然后直接启动服务即可

    3 Zipkin搭建与整合

    3.1 何为Zipkin

    Zipkin是Twitter开源的分布式跟踪系统,主要用来收集系统的时序数据,从而追踪系统的调用问题

3.2 搭建 Zipkin Server

Zipkin Server的 API兼容性(微服务通过集成reporter模块,从而Zipkin Server通信) 非常好,对于Spring Cloud Greenwich,Zipkin Server只需安装2.x即可。

  • 下载 : Zipkin官方的Shell下载最新版本
curl -sSL https://zipkin.io/quickstart.sh | bash -s
之后 java -jar启动

可看到也是一个SpringBoot应用

  • 查看9411端口
http://localhost:9411/zipkin/

  • 添加依赖,由于zipkin已经包含sleuth,所以移除那个依赖



    抽样是为了减少性能损失,默认是只上报0.1的trace数据
    调用请求后,zipkin:


  • 由于该请求客户端是浏览器,而其没有集成sleuth,不上报zipkin,所以不显示

    4 整合Zipkin之后Nacos报错解决

  • 推荐阅读
    解决Spring Cloud Alibaba/Spring Cloud整合Zipkin之后的报错问题

    5 为所有微服务整合Zipkin

    对内容中心和网关都按照前面用户中心的步骤整合即可

6 Zipkin数据持久化(Elasticsearch)

STORAGE_TYPE=elasticsearch ES_HOSTS=localhost:9200 
java -jar zipkin.jar

7 依赖关系图

  • 一般情况下,是不会显示依赖图的
  • 对此,官方有给出说明
  • 使用了ES就需要使用zipkin-dependencies
  • Zipkin Dependencies使用Elasticsearch的环境变量
  • 开始下载
curl -sSL https://zipkin.io/quickstart.sh 
| bash -s io.zipkin.dependencies:zipkin-dependencies:LATEST zipkin-dependencies.jar
  • 启动
STORAGE_TYPE=elasticsearch ES_HOSTS=localhost:9200 java -jar zipkin-dependencies.jar

  • 现在就展示依赖图了!实际可以配置定时任务

    Zipkin Dependencies指定分析日期

#分析昨天的数据 (OS/X下的命令)
STORAGE_ TYPE=elasticsearch java -jar zipkin-dependencies.jar
`date -uv-ld +%F`

#分析昨天的数据 (Linux下的命令)
STORAGE_ TYPE=elasticsearch java -jar zipkin-dependencies.jar
`date -u -d '1 day ago' +%F`

#分析指定日期的数据
STORAGE TYPE=elasticsearch java -jar zipkin-dependencies.jar 2019-12-25

参考

Guess you like

Origin www.cnblogs.com/JavaEdge/p/12052244.html