赞
踩
链路追踪是在微服务中,一个请求经过的节点服务,每个服务的耗时,执行状态的完美展现。
其中使用micrometer
通过traceid标记整个请求的唯一性;通过spanid标记本节点要发送的内容,通过parentid记录上一个节点。
zipkin是一种分布式链路跟踪系统图形化工具。开发人员能够从zipkin中分析出调用链路中的性能瓶颈,识别出存在问题的应用程序,进而定位问题和解决问题。
1.程序包
2.服务启动:java -jar zipkin-server-2.23.4-exec.jar
3.页面查看:http://localhost:9411/zipkin/
- <micrometer-tracing.version>1.2.0</micrometer-tracing.version>
- <micrometer-observation.version>1.12.0</micrometer-observation.version>
- <feign-micrometer.version>12.5</feign-micrometer.version>
- <zipkin-reporter-brave.version>2.17.0</zipkin-reporter-brave.version>
-
-
-
- <!--micrometer-tracing-bom导入链路追踪版本中心 1-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing-bom</artifactId>
- <version>${micrometer-tracing.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- <!--micrometer-tracing指标追踪 2-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing</artifactId>
- <version>${micrometer-tracing.version}</version>
- </dependency>
- <!--micrometer-tracing-bridge-brave适配zipkin的桥接包 3-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing-bridge-brave</artifactId>
- <version>${micrometer-tracing.version}</version>
- </dependency>
- <!--micrometer-observation 4-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-observation</artifactId>
- <version>${micrometer-observation.version}</version>
- </dependency>
- <!--feign-micrometer 5-->
- <dependency>
- <groupId>io.github.openfeign</groupId>
- <artifactId>feign-micrometer</artifactId>
- <version>${feign-micrometer.version}</version>
- </dependency>
- <!--zipkin-reporter-brave 6-->
- <dependency>
- <groupId>io.zipkin.reporter2</groupId>
- <artifactId>zipkin-reporter-brave</artifactId>
- <version>${zipkin-reporter-brave.version}</version>
- </dependency>
- <!--micrometer-tracing指标追踪 1-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing</artifactId>
- </dependency>
- <!--micrometer-tracing-bridge-brave适配zipkin的桥接包 2-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing-bridge-brave</artifactId>
- </dependency>
- <!--micrometer-observation 3-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-observation</artifactId>
- </dependency>
- <!--feign-micrometer 4-->
- <dependency>
- <groupId>io.github.openfeign</groupId>
- <artifactId>feign-micrometer</artifactId>
- </dependency>
- <!--zipkin-reporter-brave 5-->
- <dependency>
- <groupId>io.zipkin.reporter2</groupId>
- <artifactId>zipkin-reporter-brave</artifactId>
- </dependency>
1.配置图
2.配置内容
- # ========================zipkin===================
- management:
- zipkin:
- tracing:
- endpoint: http://localhost:9411/api/v2/spans
- tracing:
- sampling:
- probability: 1.0 #采样率默认为0.1(0.1就是10次只能有一次被记录下来),值越大收集越及时。
- package com.jurf.ms.provider9091.controller;
-
- import cn.hutool.core.util.IdUtil;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RestController;
-
- /**
- * @auther zzyy
- * @create 2023-12-28 16:08
- */
- @RestController
- public class PayMicrometerController
- {
- /**
- * Micrometer(Sleuth)进行链路监控的例子
- * @param id
- * @return
- */
- @GetMapping(value = "/pay/micrometer/{id}")
- public String myMicrometer(@PathVariable("id") Integer id)
- {
- return "Hello, 欢迎到来myMicrometer inputId: "+id+" \t 服务返回:" + IdUtil.simpleUUID();
- }
- }
- <dependencies>
- <!--micrometer-tracing指标追踪 1-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing</artifactId>
- </dependency>
- <!--micrometer-tracing-bridge-brave适配zipkin的桥接包 2-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-tracing-bridge-brave</artifactId>
- </dependency>
- <!--micrometer-observation 3-->
- <dependency>
- <groupId>io.micrometer</groupId>
- <artifactId>micrometer-observation</artifactId>
- </dependency>
- <!--feign-micrometer 4-->
- <dependency>
- <groupId>io.github.openfeign</groupId>
- <artifactId>feign-micrometer</artifactId>
- </dependency>
- <!--zipkin-reporter-brave 5-->
- <dependency>
- <groupId>io.zipkin.reporter2</groupId>
- <artifactId>zipkin-reporter-brave</artifactId>
- </dependency>
- # zipkin图形展现地址和采样率设置
- management:
- zipkin:
- tracing:
- endpoint: http://localhost:9411/api/v2/spans
- tracing:
- sampling:
- probability: 1.0 #采样率默认为0.1(0.1就是10次只能有一次被记录下来),值越大收集越及时。
-
- package com.jurf.ms.fegin.controller;
-
-
- import com.jurf.ms.api.sb.PayFeginApi;
- import jakarta.annotation.Resource;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RestController;
-
- /**
- * @auther zzyy
- * @create 2023-12-28 16:11
- */
- @RestController
- @Slf4j
- public class OrderMicrometerController
- {
- @Resource
- private PayFeginApi payFeginApi;
-
- @GetMapping(value = "/feign/micrometer/{id}")
- public String myMicrometer(@PathVariable("id") Integer id)
- {
- return payFeginApi.myMicrometer(id);
- }
- }
服务启动:java -jar zipkin-server-2.23.4-exec.jar
http://localhost:8081/feign/micrometer/666
查看zipkin
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。