Pinpoint 数据结构解析-UDP

Pinpoint 数据结构解析-UDP

Wed Nov 28, 2018

1400 Words|Read in about 3 Min
Tags: 监控   apm   trace  

本文基于pinpoint 1.8版本探索

pinpoint udp主要上报JVM状态信息、全链路调用信息。(其中有些字段字面意义很明确就没有说明,有几个字段源码里面看不出来是做什么到,所以咨询了作者,等回复吧😂)

TSpan

type TSpan struct {
	AgentId         string `thrift:"agentId,1" db:"agentId" json:"agentId"`
	ApplicationName string `thrift:"applicationName,2" db:"applicationName" json:"applicationName"`
	AgentStartTime  int64  `thrift:"agentStartTime,3" db:"agentStartTime" json:"agentStartTime"`
	TransactionId   []byte `thrift:"transactionId,4" db:"transactionId" json:"transactionId"`
	// unused fields # 5 to 6
	SpanId                int64          `thrift:"spanId,7" db:"spanId" json:"spanId"`
	ParentSpanId          int64          `thrift:"parentSpanId,8" db:"parentSpanId" json:"parentSpanId,omitempty"`
	StartTime             int64          `thrift:"startTime,9" db:"startTime" json:"startTime"`
	Elapsed               int32          `thrift:"elapsed,10" db:"elapsed" json:"elapsed,omitempty"`
	RPC                   *string        `thrift:"rpc,11" db:"rpc" json:"rpc,omitempty"`
	ServiceType           int16          `thrift:"serviceType,12" db:"serviceType" json:"serviceType"`
	EndPoint              *string        `thrift:"endPoint,13" db:"endPoint" json:"endPoint,omitempty"`
	RemoteAddr            *string        `thrift:"remoteAddr,14" db:"remoteAddr" json:"remoteAddr,omitempty"`
	Annotations           []*TAnnotation `thrift:"annotations,15" db:"annotations" json:"annotations,omitempty"`
	Flag                  int16          `thrift:"flag,16" db:"flag" json:"flag,omitempty"`
	Err                   *int32         `thrift:"err,17" db:"err" json:"err,omitempty"`
	SpanEventList         []*TSpanEvent  `thrift:"spanEventList,18" db:"spanEventList" json:"spanEventList,omitempty"`
	ParentApplicationName *string        `thrift:"parentApplicationName,19" db:"parentApplicationName" json:"parentApplicationName,omitempty"`
	ParentApplicationType *int16         `thrift:"parentApplicationType,20" db:"parentApplicationType" json:"parentApplicationType,omitempty"`
	AcceptorHost          *string        `thrift:"acceptorHost,21" db:"acceptorHost" json:"acceptorHost,omitempty"`
	// unused fields # 22 to 24
	ApiId         *int32           `thrift:"apiId,25" db:"apiId" json:"apiId,omitempty"`
	ExceptionInfo *TIntStringValue `thrift:"exceptionInfo,26" db:"exceptionInfo" json:"exceptionInfo,omitempty"`
	// unused fields # 27 to 29
	ApplicationServiceType *int16 `thrift:"applicationServiceType,30" db:"applicationServiceType" json:"applicationServiceType,omitempty"`
	LoggingTransactionInfo *int8  `thrift:"loggingTransactionInfo,31" db:"loggingTransactionInfo" json:"loggingTransactionInfo,omitempty"`
	Version                int8   `thrift:"version,32" db:"version" json:"version,omitempty"`
}

TSpan: RPC远程调用跟踪的基本单元,为了确保代码级别的可见性,在span中加入SpanEventList(TSpanEvent)作为数据结构

* TransactionId 分布式系统间单个事物发送/接收的消息ID,全局唯一
* SpanId 收到RPC消息时处理的工作ID,在RPC请求到达节点时生成
* ParentSpanId 发起RPC调用的span的spanID,如果*不存在默认-1*
* StartTime 到达span生产者的时间
* ServiceType pinpoint提供的插件服务类型(如:1010代表 "TOMCAT")
* Elapsed 处理本次请求耗时(整个span生成的时间)
* RPC 生产者span提供的API(如URL)
* EndPoint  span生产者提供地址
* RemoteAddr 访问span提供者的地址
* Annotations 一种标签(如:46代表http.status.code, value可能是int型200,具体可以在pinpoint中搜索关键字来查看具体code代表的含义)
* AcceptorHost 客户端使用的服务器地址
* ApiId apiID,这里一定不能被pinpoint的命名给欺骗了,这里的api是method
* ExceptionInfo 异常信息
* SpanEventList 封装着span记录着重要的方法调用以及相关的参数返回等,每个SpanEvent都是一次方法调用
* Flag (没搞清楚)
type TSpanEvent struct {
	// unused fields # 1 to 6
	SpanId       *int64         `thrift:"spanId,7" db:"spanId" json:"spanId,omitempty"`
	Sequence     int16          `thrift:"sequence,8" db:"sequence" json:"sequence"`
	StartElapsed int32          `thrift:"startElapsed,9" db:"startElapsed" json:"startElapsed"`
	EndElapsed   int32          `thrift:"endElapsed,10" db:"endElapsed" json:"endElapsed,omitempty"`
	RPC          *string        `thrift:"rpc,11" db:"rpc" json:"rpc,omitempty"`
	ServiceType  int16          `thrift:"serviceType,12" db:"serviceType" json:"serviceType"`
	EndPoint     *string        `thrift:"endPoint,13" db:"endPoint" json:"endPoint,omitempty"`
	Annotations  []*TAnnotation `thrift:"annotations,14" db:"annotations" json:"annotations,omitempty"`
	Depth        int32          `thrift:"depth,15" db:"depth" json:"depth,omitempty"`
	NextSpanId   int64          `thrift:"nextSpanId,16" db:"nextSpanId" json:"nextSpanId,omitempty"`
	// unused fields # 17 to 19
	DestinationId *string `thrift:"destinationId,20" db:"destinationId" json:"destinationId,omitempty"`
	// unused fields # 21 to 24
	ApiId         *int32           `thrift:"apiId,25" db:"apiId" json:"apiId,omitempty"`
	ExceptionInfo *TIntStringValue `thrift:"exceptionInfo,26" db:"exceptionInfo" json:"exceptionInfo,omitempty"`
	// unused fields # 27 to 29
	AsyncId       *int32 `thrift:"asyncId,30" db:"asyncId" json:"asyncId,omitempty"`
	NextAsyncId   *int32 `thrift:"nextAsyncId,31" db:"nextAsyncId" json:"nextAsyncId,omitempty"`
	AsyncSequence *int16 `thrift:"asyncSequence,32" db:"asyncSequence" json:"asyncSequence,omitempty"`
}

AsyncId、NextAsyncId主要用来做链路排序的。

* AsyncId 异步ID
* NextAsyncId 下一个异步ID
* AsyncSequence 异步序列(已经咨询作者了,等待回复)
* Annotations 注解,放一些请求参数,返回值等,非常重要等字段
* DestinationId 目标描述(http时可能时ip, mysql时可能时数据库名,可以根据event.ServiceType来做具体展示)
type TSpanChunk struct {
	AgentId         string `thrift:"agentId,1" db:"agentId" json:"agentId"`
	ApplicationName string `thrift:"applicationName,2" db:"applicationName" json:"applicationName"`
	AgentStartTime  int64  `thrift:"agentStartTime,3" db:"agentStartTime" json:"agentStartTime"`
	ServiceType     int16  `thrift:"serviceType,4" db:"serviceType" json:"serviceType"`
	TransactionId   []byte `thrift:"transactionId,5" db:"transactionId" json:"transactionId"`
	// unused fields # 6 to 7
	SpanId                 int64         `thrift:"spanId,8" db:"spanId" json:"spanId"`
	EndPoint               *string       `thrift:"endPoint,9" db:"endPoint" json:"endPoint,omitempty"`
	SpanEventList          []*TSpanEvent `thrift:"spanEventList,10" db:"spanEventList" json:"spanEventList"`
	ApplicationServiceType *int16        `thrift:"applicationServiceType,11" db:"applicationServiceType" json:"applicationServiceType,omitempty"`
	KeyTime                *int64        `thrift:"keyTime,12" db:"keyTime" json:"keyTime,omitempty"`
	Version                int8          `thrift:"version,13" db:"version" json:"version,omitempty"`
}
一个Span由几个Span事件组成。如果Span发现了太多Span事件,它会将它们划分为SpanChunk,并将数据传递给收集器。
type TAgentStat struct {
	AgentId         *string `thrift:"agentId,1" db:"agentId" json:"agentId,omitempty"`
	StartTimestamp  *int64  `thrift:"startTimestamp,2" db:"startTimestamp" json:"startTimestamp,omitempty"`
	Timestamp       *int64  `thrift:"timestamp,3" db:"timestamp" json:"timestamp,omitempty"`
	CollectInterval *int64  `thrift:"collectInterval,4" db:"collectInterval" json:"collectInterval,omitempty"`
	// unused fields # 5 to 9
	Gc *TJvmGc `thrift:"gc,10" db:"gc" json:"gc,omitempty"`
	// unused fields # 11 to 19
	CpuLoad *TCpuLoad `thrift:"cpuLoad,20" db:"cpuLoad" json:"cpuLoad,omitempty"`
	// unused fields # 21 to 29
	Transaction *TTransaction `thrift:"transaction,30" db:"transaction" json:"transaction,omitempty"`
	// unused fields # 31 to 39
	ActiveTrace *TActiveTrace `thrift:"activeTrace,40" db:"activeTrace" json:"activeTrace,omitempty"`
	// unused fields # 41 to 49
	DataSourceList *TDataSourceList `thrift:"dataSourceList,50" db:"dataSourceList" json:"dataSourceList,omitempty"`
	// unused fields # 51 to 59
	ResponseTime *TResponseTime `thrift:"responseTime,60" db:"responseTime" json:"responseTime,omitempty"`
	// unused fields # 61 to 69
	Deadlock *TDeadlock `thrift:"deadlock,70" db:"deadlock" json:"deadlock,omitempty"`
	// unused fields # 71 to 79
	FileDescriptor *TFileDescriptor `thrift:"fileDescriptor,80" db:"fileDescriptor" json:"fileDescriptor,omitempty"`
	// unused fields # 81 to 89
	DirectBuffer *TDirectBuffer `thrift:"directBuffer,90" db:"directBuffer" json:"directBuffer,omitempty"`
	// unused fields # 91 to 199
	Metadata *string `thrift:"metadata,200" db:"metadata" json:"metadata,omitempty"`
}
TAgentStat主要是一下jvm信息已经程序运行时的一些信息,都比较好理解,这里就不过多去解析了。

See Also

Wed Nov 28, 2018

1400 Words|Read in about 3 Min
Tags: 监控   apm   trace