本文将讲述pinpoint的安装,使用及与java logback 日志的集成。
介绍
是什么
- 是一款 APM监控工具(Application Performance Management/应用性能管理)
- 基于java编写
- 用于 大规模分布式系统 的监控,是 分析 大规模分布式系统 的平台
- 基于google Dapper开发,目标就是为n(n>=1)层架构开发新的跟踪平台,为n层架构的系统 提供 处理大量跟踪数据 的 解决方案
- 能够对 基于java的 大规模分布式系统和应用 做调用链的跟踪
- 提供了一个web页面 展示 分布式系统的拓扑图 以及 系统这各个组件之间关系
特点
- 分布式事务追踪,跟踪跨分布式应用的消息
- 自动检测应用拓扑,帮助你搞清楚应用的架构
- 水平扩展,以便支持大规模服务器集群
- 提供代码级别的可见性,以便轻松定位失败点和瓶颈
- 提供字节码增强技术,添加新功能无需修改代码
- 安装探针不需要修改哪怕一行代码及trace server端部署简单,支持hdfs存储
- 具有简单的阀值触发报警功能
- 移植性比较强的,会比较讨人喜欢(相比cat)
- 自定义插件功能(参考https://github.com/naver/pinpoint/wiki/Pinpoint-Plugin-Developer-Guide)
具体请参考:
Pinpoint–基础–01–介绍
网友专栏: https://blog.csdn.net/zhou920786312/category_12110038.html
环境搭建
这里推荐一篇网友的安装步骤,照着步骤基本没什么问题。
性能测试利器 — 全链路监控工具Pinpoint安装教程
其中这个hbase的初始化脚本特别说明下:
https://github.com/pinpoint-apm/pinpoint/tree/v2.3.3/hbase/scripts 在这个目录里面下载。
这里提供一个百度网盘的下载地址(包含了所有的安装包及文件):
链接:https://pan.baidu.com/s/19wdQ0rdlA4jcC1GujNKRMg?pwd=c4ko
提取码:c4ko
iccboy@DESKTOP-JAG3NND:~/pinpoint$ ll
total 331652
drwxr-xr-x 5 iccboy iccboy 4096 Nov 26 23:38 ./
drwxr-xr-x 6 iccboy iccboy 4096 Nov 27 22:58 ../
-rwxr--r-- 1 iccboy iccboy 170 Nov 26 23:32 collector.sh*
drwxr-xr-x 8 iccboy iccboy 4096 Nov 26 23:14 hbase-1.2.6/
-rwxr-xr-x 1 iccboy iccboy 104659474 Nov 26 22:59 hbase-1.2.6-bin.tar.gz*
-rw-r--r-- 1 iccboy iccboy 15763 Nov 26 23:28 hbase-create.hbase
drwxr-xr-x 2 iccboy iccboy 4096 Nov 27 00:01 logs/
drwxr-xr-x 9 iccboy iccboy 4096 Nov 27 22:37 pinpoint-agent-2.3.3/
-rwxr-xr-x 1 iccboy iccboy 28031866 Nov 26 23:00 pinpoint-agent-2.3.3.tar.gz*
-rw-r--r-- 1 iccboy iccboy 91303343 Nov 26 23:23 pinpoint-collector-boot-2.3.3.jar
-rw-r--r-- 1 iccboy iccboy 115567241 Nov 26 23:23 pinpoint-web-boot-2.3.3.jar
-rwxr--r-- 1 iccboy iccboy 158 Nov 26 23:35 pinpoint-web.sh*
iccboy@DESKTOP-JAG3NND:~/pinpoint$ jps
11585 HMaster
18053 Jps
13609 pinpoint-web-boot-2.3.3.jar
14093 pinpoint-collector-boot-2.3.3.jar
iccboy@DESKTOP-JAG3NND:~/pinpoint$ netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 27462/./wslconnect
tcp6 0 0 127.0.1.1:42881 :::* LISTEN 11585/java
tcp6 0 0 127.0.1.1:37571 :::* LISTEN 11585/java
tcp6 0 0 :::46533 :::* LISTEN 11585/java
tcp6 0 0 :::2181 :::* LISTEN 11585/java
tcp6 0 0 :::9991 :::* LISTEN 14093/java
tcp6 0 0 :::9992 :::* LISTEN 14093/java
tcp6 0 0 :::9993 :::* LISTEN 14093/java
tcp6 0 0 :::9994 :::* LISTEN 14093/java
tcp6 0 0 :::16010 :::* LISTEN 11585/java
tcp6 0 0 127.0.1.1:9997 :::* LISTEN 13609/java
tcp6 0 0 :::8080 :::* LISTEN 13609/java
tcp6 0 0 :::8081 :::* LISTEN 14093/java
pinpoint与logback日志MDC集成
- 修改代理模块的
pinpoint-agent-2.3.3/profiles/release/pinpoint.conf
配置
将profiler.logback.logging.transactioninfo 改为true,大概在1002行
###########################################################
# logback (guide url : https://github.com/naver/pinpoint/blob/master/doc/per-request_feature_guide.md)
###########################################################
profiler.logback.logging.transactioninfo=`true`
- 在项目的logback.xml中增加
[%X{PtxId}]
变量,则是pinpoint的traceId。
如:
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] [%X{PtxId}] [%level] %logger{36}-%L %.-2048msg%n"/>
- 启动项目
记得带上参数
-javaagent:D:\sdk\pinpoint\pinpoint-agent-2.3.3\pinpoint-bootstrap-2.3.3.jar -Dpinpoint.agentId=iccboy-member -Dpinpoint.applicationName=iccboy-member
日志打印如下:
2023-11-27 23:56:35.482 [DubboServerHandler-10.10.125.42:20880-thread-10] [iccboy-member^1701100523841^2] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-176 [econfig-0]方法【queryCustomerList(客户列表查询)】调用开始,参数为:{"req":{"data":{"cusCertNo":"C9F4FYW4P","cusType":2,"pageIndex":1,"pageSize":10},"invokeId":"HHYLE377493204464ED3808AAB1C2FF03C29"}}
2023-11-27 23:56:35.597 [DubboServerHandler-10.10.125.42:20880-thread-10] [iccboy-member^1701100523841^2] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-214 [econfig-0]方法【queryCustomerList(客户列表查询)】调用正常,耗时:117ms,返回值为:{"invokeId":"HHYLE377493204464ED3808AAB1C2FF03C29","resultCode":"0000","resultMessage":"成功","data":{"list":[{"cusId":10179140,"cusName":"ADDTEST","cusType":2,"cusCertType":"2","cusCertNo":"C9F4FYW4P","cusSource":"hhyl-permission","cusOpenTime":"2023-11-24 11:38:50"}],"pagination":{"pageIndex":1,"pageSize":10,"totalRecord":1,"totalPage":1},"success":false}}
2023-11-27 23:57:00.540 [DubboServerHandler-10.10.125.42:20880-thread-11] [iccboy-member^1701100523841^3] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-176 [econfig-0]方法【queryCustomersRelation()】调用开始,参数为:{"req":{"data":{"cusIdFrom":"10171684","relationType":"01"},"invokeId":"HHYL120134CBDF904974B0D01855A6DBDEA2"}}
2023-11-27 23:57:00.597 [DubboServerHandler-10.10.125.42:20880-thread-11] [iccboy-member^1701100523841^3] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-214 [econfig-0]方法【queryCustomersRelation()】调用正常,耗时:57ms,返回值为:{"invokeId":"HHYL120134CBDF904974B0D01855A6DBDEA2","resultCode":"0000","resultMessage":"成功","data":[{"id":56068,"cusIdFrom":"10171684","cusIdTo":"10171686","relationType":"01"}]}
2023-11-27 23:57:00.606 [DubboServerHandler-10.10.125.42:20880-thread-12] [iccboy-member^1701100523841^4] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-176 [econfig-0]方法【queryRelationV2(用户客户关系查询接口2.0)】调用开始,参数为:{"req":{"data":{"cusIdList":["10171686"],"relation":"3"},"invokeId":"HHYLB3B6EC3D566B4FE2A0A0AA98F88F27F8"}}
2023-11-27 23:57:00.612 [DubboServerHandler-10.10.125.42:20880-thread-12] [iccboy-member^1701100523841^4] [INFO] c.h.h.m.b.s.impl.UserBizServiceImpl-976 用户客户关系查询2.0入参:QueryRelationV2Req(userId=null, cusIdList=[10171686], relation=3, userIdList=null)
2023-11-27 23:57:00.656 [DubboServerHandler-10.10.125.42:20880-thread-12] [iccboy-member^1701100523841^4] [INFO] c.h.h.f.c.e.a.ExceptionLogInterceptor-214 [econfig-0]方法【queryRelationV2(用户客户关系查询接口2.0)】调用正常,耗时:49ms,返回值为:{"invokeId":"HHYLB3B6EC3D566B4FE2A0A0AA98F88F27F8","resultCode":"0000","resultMessage":"成功","data":[{"userId":"40008483","cusId":"10171686","relation":"3","position":""}]}
上面的iccboy-member^1701100523841^2
就是pinpoint的TransactionId(TxId)