tingyun3

package module
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

README

听云 goagent

TingYun APM3.0 - GoAgent

简介

听云 goagent 能为您的 Go 语言应用程序提供运行时状态监控功能。

它能帮助您追踪事务请求,外部调用,数据调用,nosql调用(redis, mongodb等) 以及自定义过程的性能数据和错误等运行状态信息。

为方便理解,下面这部分简单介绍Go语言的特点,如果您熟悉Go语言,请转到 听云 goagent 嵌码 开始阅读。

Go 语言简介

与c和c++语言类似, Go 语言是编译类型的语言。

Go语言程序如何运行?

Go语言源程序经过Go编译器编译,生成独立的二进制ELF(linux)/EXE(windows) 格式的可执行文件,运行时不再需要Go源程序参与。

Go语言如何使用第三方模块?

Go语言通过import语句引入第三方模块 示例代码:

package main
import (
	tingyun "github.com/TingYunGo/goagent"
)
func RoutineID() int64 {
	return tingyun.GetGID()
}

其中: tingyun 为引入模块的别名。

如果只是引入模块,并不直接使用模块的方法,那么引入模块的别名使用下划线 _ 代替, 否则Go编译器提示错误:

package main
import (
	_ "github.com/TingYunGo/goagent"
)
Go语言第三方模块如何下载安装到本地?

Go语言的所有第三方模块都是源码形式发布到git服务器上的。 第三方模块的下载安装分为 GOPATH 模式和 GOMOD 模式两种情况:

  • GOPATH模式 : Go语言版本低于1.11,或者禁用了GOMOD (设置环境变量GO111MODULE=off)模式时,处于GOPATH模式。
    这种模式下, Go编译器检测GOPATH环境变量,在GOPATH环境变量指定的每个路径下根据名字查找第三方库。GOPATH未设置时, 缺省值是当前用户的跟路径下的 go 文件夹。
    GOPATH模式第三方模块安装有两种方法:

    • 自动安装:
      使用命令 go get <第三方库路径>, 举例, 安装 tingyun goagent:

      $ go get github.com/TingYunGo/goagent
      

      命令执行后,会自动下载模块到GOPATH下的src/github.com/TingYunGo/goagent 下, 并且,递归下载该模块依赖的模块到相应目录。

    • 手动安装:
      在GOPATH下手动创建路径src/github.com/TingYunGo/goagent , 并将代码复制到该文件夹下。

  • GOMOD模式 : Go语言版本大于等于1.11, 并且设置环境变量GO111MODULE=on时, 处于GOMOD模式。
    GOMOD 模式下,在Go应用的根路径下需要go.mod文件,主要内容为应用名,Go语言版本和依赖包及版本。
    范例:

    module http_example
    go 1.12
    require (
    	github.com/TingYunGo/goagent v0.7.8
        github.com/golang/protobuf v1.5.2 // indirect
    )
    

    其中:

    • http_example 是应用的名字。
    • go 1.12 : 是要求go版本不低于 v1.12 。
    • require: 这部分指定依赖的第三方模块及对应的版本。

    GOMOD模式下依赖包的下载:

    • 使用命令:
      go mod tidy
      
      这个命令将自动检查当前应用的依赖并下载所有依赖包,并且校验依赖包的hash值,写入到go.sum文件。
Go语言应用如何编译?

进入应用源码路径,执行 go build 命令,即生成应用的可执行文件。

听云 goagent 嵌码

听云 goagent 是什么?
  • 听云 goagent是一个Go语言第三方模块, 发布根路径是: github.com/TingYunGo/goagent
  • 听云 goagent 支持 amd64架构处理器 的linux环境, go1.9 到 最新的 go1.17.x Go语言版本。
  • 听云 goagent 提供自动嵌码和自定义嵌码(Go API)两种嵌码机制。
  • 自动嵌码支持列表参考 框架支持列表组件支持列表
听云 goagent 如何安装?


与所有第三方模块的安装方式相同。

  • GOPATH模式下安装:
    $ go get github.com/TingYunGo/goagent
    
  • GOMOD模式下安装:
    在应用文件夹下执行:
    $ go mod tidy
    
听云 goagent如何使用(嵌码)?

根据应用使用http框架的不同, 需要import 不同的路径。

我们以一个使用内置http框架举的简单例子说明如何嵌码:
源文件: main.go 代码如下:

package main
import (
	"encoding/json"
	"net/http"
)
func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		header := w.Header()
		header.Set("Cache-Control", "no-cache")
		header.Set("Content-Type", "application/json; charset=utf-8")
		w.WriteHeader(http.StatusOK)
		b, _ := json.Marshal(map[string]interface{}{
			"status": "success",
			"URI":    r.URL.RawQuery,
		})
		w.Write(b)
	})
	http.ListenAndServe(":3000", nil)
}

要对如上这个应用嵌码, 在源文件同级目录下,创建tingyun.go文件,内容如下:

package main
import (
	_ "github.com/TingYunGo/goagent"
)

全部嵌码工作即完成。

嵌码说明:
此例应用使用了内置http框架, 对于内置http框架, 需要 引入 github.com/TingYunGo/goagent 。

如何确定嵌码要使用哪个/哪些 import 模块路径?

下边整理了 goagent 支持的 框架/组件支持列表, 通过查表获得引用依赖。

获取当前应用的依赖模块:
  • GOMOD 方式: 查看go.mod文件,或者使用命令:
	$ go mod graph
  • GOPATH 方式: 编译时使用 -a -v 参数:
	$ go build -a -v
听云探针框架支持列表:
框架 听云探针嵌码 import 模块路径 支持版本
net/http
内置http框架
github.com/TingYunGo/goagent go1.9 ~ go1.17.x
github.com/gin-gonic/gin
gin框架
github.com/TingYunGo/goagent/frameworks/gin gin v1.3.0 ~ gin v1.7.4
github.com/astaxie/beego
beego框架: GOPATH模式
github.com/TingYunGo/goagent/frameworks/beego/path/astaxie beego v1.12.0 ~ beego v2.0.0-beta
github.com/beego/beego
beego框架: GOPATH模式
github.com/TingYunGo/goagent/frameworks/beego/path beego v1.12.0 ~ beego v2.0.1
github.com/beego/beego
beego框架v1: GOMOD模式
github.com/TingYunGo/goagent/frameworks/beego beego v1.12.0 ~ beego v1.12.3
github.com/beego/beego/v2
beego框架v2: GOMOD模式
github.com/TingYunGo/goagent/frameworks/beego/v2 beego v2.0.0 ~ beego v2.0.1
github.com/labstack/echo
echo 框架 GOPATH模式
github.com/TingYunGo/goagent/frameworks/echo echo v3.3.10 ~ echo v4.6.1
github.com/labstack/echo/v4
echo 框架 V4 GOMOD模式
github.com/TingYunGo/goagent/frameworks/echo/v4 echo v4.0.0 ~ echo v4.6.1
github.com/kataras/iris/v12
iris 框架 v12.1.x
github.com/TingYunGo/goagent/frameworks/iris/v12 iris v12.1.0 ~ iris v12.1.8
github.com/kataras/iris/v12
iris 框架 v12.2
github.com/TingYunGo/goagent/frameworks/iris/v12/2 iris v12.2.0-alpha ~ iris v12.2.0-alpha3
听云探针组件支持列表
组件 听云探针嵌码 import 模块路径 支持版本
database/sql
数据库
github.com/TingYunGo/goagent/database go1.9 ~ go1.17.x
驱动列表:
mssql: github.com/denisenkom/go-mssqldb v0.9.0 ~ v0.11.0
mysql: github.com/go-sql-driver/mysql v1.0.0 ~ v1.6.0
postgresql: github.com/lib/pq v1.0.0 ~ v1.10.3
sqlite: github.com/mattn/go-sqlite3 v1.0.0 ~ v1.14.8
github.com/gomodule/redigo
redis: redigo
github.com/TingYunGo/goagent/nosql/redigo v1.7.0 ~ v1.8.5
github.com/go-redis/redis
redis: go-redis, GOPATH模式
github.com/TingYunGo/goagent/nosql/go-redis v6.10.0 ~ v8.11.4
github.com/go-redis/redis
redis: go-redis default, GOMOD模式
github.com/TingYunGo/goagent/nosql/go-redis v6.10.0 ~ v8.11.4
github.com/go-redis/redis/v7
redis: go-redis v7, GOMOD模式
github.com/TingYunGo/goagent/nosql/go-redis/v7 v7.0.0 ~ v7.4.1
github.com/go-redis/redis/v8
redis: go-redis v8, GOMOD模式
github.com/TingYunGo/goagent/nosql/go-redis/v8 v8.0.0 ~ v8.11.4
Go.mongodb.org/mongo-driver/mongo
mongodb
github.com/TingYunGo/goagent/nosql/mongodb v1.1.0 ~ v1.7.3
嵌码实例演示

以开源项目 photoprism 为例 : 项目地址 https://github.com/photoprism/photoprism

  • 步骤1. 首先克隆项目:

    $ git clone https://github.com/photoprism/photoprism.git
    
  • 步骤2. 确定项目使用哪些框架和库:

    进入项目文件夹,查看 go.mod文件:

    $ cd photoprism
    $ cat go.mod
    

    我们会看到,此项目使用了gin框架, 数据库支持:

    postgresql:(github.com/lib/pq)
    mysql:(github.com/go-sql-driver/mysql)
    sqlite:(github.com/mattn/go-sqlite3)
    
  • 步骤3: 查表确定引用路径,添加源码:

    查看框架支持列表, 我们的嵌码操作需要引用两个路径:

    github.com/TingYunGo/goagent/frameworks/gin
    github.com/TingYunGo/goagent/database
    

    在代码目录 internal/photoprism下创建 tingyun.go文件,内容如下:

    package photoprism
    import (
    	_ "github.com/TingYunGo/goagent/database"
    	_ "github.com/TingYunGo/goagent/frameworks/gin"
    )
    
  • 步骤4. 执行 go mod tidy, 编译:

    在项目的go.mod文件所在的文件夹下,执行:

    $ go mod tidy
    $ make
    

    以上4个步骤完成后,项目编译和探针嵌码工作就全部完成。

常用Go语言第三方组件支持的数据库版本列表
组件 支持版本
mssql: github.com/denisenkom/go-mssqldb SQL Server 2008 SP3 +
mysql: github.com/go-sql-driver/mysql mysql 5.5+
postgresql: github.com/lib/pq postgresql 9.6+
sqlite: github.com/mattn/go-sqlite3 sqlite 3.8.5 ~ 3.36.0
redis: redigo github.com/gomodule/redigo redis 4.0.0+
redis: go-redis github.com/go-redis/redis redis 4.0.0+
mongodb: go.mongodb.org/mongo-driver/mongo mongodb 2.6.1+

配置&运行

已经嵌码的应用, 听云agent 部分如何配置?

为保证应用程序的最大限度的安全,缺省不配置的情况下, 嵌码逻辑是处于禁用状态。

指定配置文件:

要启用agent监控,需要设置环境变量: TINGYUN_GO_APP_CONFIG 指定配置文件路径。

$ export TINGYUN_GO_APP_CONFIG=/[configfilepath]/tingyun.conf
$ /your app path/appname [your app args]

注意!!! 必须在应用程序启动前设置环境变量,在应用程序里设置环境变量是无效的。

听云agent 配置项:

参考配置 tingyun.conf:


######## 应用配置项 ########

# 设置应用名字符串类型, 可选项, 缺省取进程名做应用名 
# app_name = "My Go App"

# Agent启用标志, bool 类型, 可选项, 缺省为 true
# agent_enabled = true


######## 授权 / 服务器配置项 #########

# 授权序列码, 字符串类型, 必选项, 不能为空 
#license_key = "999-999-999"

# collector服务器地址, 多个地址用逗号分隔, 必选项, 不能为空
#collector.address = "collector_ip:port"

# 向collector服务器发送请求是否启用ssl(https), 缺省值 false
# ssl = false


######## 日志配置项 ########

# 日志文件路径, 必选项. 置空或不配置此项时, 无日志输出
agent_log_file = agent.log

# 日志输出级别设置, 可设置级别: debug, info, error, off
# debug: 输出最多日志
#  info: 输出 info级别和 error级别日志
# error: 仅输出 error级别日志
#   off: 关闭日志输出
# 缺省值: info
agent_log_level = info

# 审计模式, bool类型, 缺省值 false; 配合日志级别, 控制日志的输出
# 设置为 false 时, 部分审计模式日志不输出
audit_mode = true

# 日志文件大小, 整数, 单位 MB, 缺省值10
# 日志文件大小超过此阈值时, 将创建新的日志文件, 旧的日志将依次更新日志文件名
agent_log_file_size = 10

# 保留日志文件个数, 整数, 缺省值3
# 日志文件个数超过此阈值将从最早的文件开始删除
agent_log_file_count = 3


######## 内存控制阈值 ########

# 事务数据采集对象在内存缓冲队列中存放的最大数量, 缺省值10000
# 超过此阈值意味着当前并发数过高, 后台工作协程的处理能力不足以消费完采集到的数据
# 为防止数据积压导致的应用内存无限制增长, 当事务缓冲队列超过此阈值时, 不再采集事务性能数据 
action_cache_max = 10000

# 每次向collector发送数据包含的最大事务数量, 缺省值5000 
action_report_max = 5000

# 向collector发送的数据缓冲队列长度, 缺省值10 
# 发送队列长度超过此阈值意味网络缓慢或者collector处理能力不足 
# 为防止数据积压导致的内存无限制增长, 当发送队列长度超过此阈值时, 新的发送请求将被丢弃 
report_queue_count = 5

# 每个事务可采集的最大组件调用次数, 缺省值3000
# 事务采集的组件次数超过此阈值后,此事务的采集过程将不再采集新的组件调用数据
agent_component_max = 3000

# sql语句的最大字节长度,缺省值5000
# 超过此阈值,采集的sql将被截断为阈值设定长度
agent_sql_size_max = 5000
环境变量支持

某些特殊场合,有可能需要通过环境变量灵活控制配置项。作为配置文件的补充,听云agent也提供了相应支持。 听云agent支持的环境变量:

agent_enabled  # 启用探针选项, 取值: true/false; 缺省值: true
audit_mode  # 审计模式, 审计模式日志开启选项, 取值: true/false; 缺省值: false
agent_log_level  # 日志级别设置, 取值: debug/info/error/off; 缺省值: info
agent_log_file  # 日志文件路径
license_key  # 授权序列码
collectors  # collector服务器地址,多个地址以逗号分隔
agent_init_delay  # 探针延时初始化时间,整数,单位秒, 缺省值1.  说明: 如果探针初始化过早,可能在应用开始listen之前初始化, 这种情况下探针抓不到应用listen的端口. 增加初始化延时以解决此问题.
TINGYUN_GO_APP_NAME  # 应用名称

自动嵌码演示范例

使用听云 goagent嵌码,请参考部分范例程序 听云 goagent演示

自定义嵌码(听云 goagent API)

自定义嵌码部分请参考阅读 听云 goagent API

Code License

听云 goagent 使用 Apache 2.0 协议发布.

交叉编译

OSX 系统

引入听云探针后,MAC系统环境下的交叉编译(linux,amd64), 需要安装交叉编译工具(C编译器及LIBC库),如果未安装相关工具,可参考使用如下包(使用MUSL C):

$ brew install FiloSottile/musl-cross/musl-cross

Go语言项目 MUSL C的交叉编译命令请参考:

# CC: C语言交叉编译器
# GOARCH: 编译后的可执行文件运行的CPU架构
# GOOS: 编译后的可执行文件运行的操作系统
# "-extldflags -static" : 静态链接
$ CC=x86_64-linux-musl-gcc GOARCH=amd64 GOOS=linux CGO_ENABLED=1 go build -ldflags "-linkmode external -extldflags -static"

Documentation

Overview

Package tingyun3 听云性能采集探针(sdk)

Copyright 2021 冯立强 fenglq@tingyun.com. All rights reserved.

Copyright 2021 冯立强 fenglq@tingyun.com. All rights reserved.

Index

Constants

View Source
const (
	ComponentDefault    = 0
	ComponentDefaultDB  = 32
	ComponentMysql      = 33
	ComponentPostgreSQL = 34
	ComponentMSSQL      = 35
	ComponentSQLite     = 36
	ComponentOracle     = 37
	ComponentMongo      = 48
	ComponentMemCache   = 49
	ComponentRedis      = 50
	ComponentMQC        = 56
	ComponentMQP        = 57
	ComponentExternal   = 64
)

* 组件类型定义

View Source
const (
	LevelOff      = log.LevelOff
	LevelCritical = log.LevelCritical
	LevelError    = log.LevelError
	LevelWarning  = log.LevelWarning
	LevelInfo     = log.LevelInfo
	LevelVerbos   = log.LevelVerbos
	LevelDebug    = log.LevelDebug
	LevelMask     = log.LevelMask
	Audit         = log.Audit
)

* 日志级别/审计模式控制

View Source
const TINGYUN_GO_AGENT_VERSION = "v1.0.0"

Variables

This section is empty.

Functions

func ConfigRead

func ConfigRead(name string) (interface{}, bool)

ConfigRead : 读配置项

func Enabled added in v0.8.5

func Enabled() bool

func GetCallerName

func GetCallerName(layer int) string

GetCallerName : 取layer层调用栈函数名

func GetCallerPC

func GetCallerPC(layer int) (l int, pc uintptr)

GetCallerPC return caller pc

func GetGID

func GetGID() int64

GetGID return goroutine id

func HttpClientDo

func HttpClientDo(ptr *http.Client, req *http.Request) (*http.Response, error)

func LocalClear added in v0.6.0

func LocalClear()

Clear Routine Local Storage

func LocalDelete

func LocalDelete(id int) interface{}

LocalDelete : 从协程局部存储器中删除key为 id的对象,并返回这个对象

func LocalGet

func LocalGet(id int) interface{}

LocalGet : 从协程局部存储器中取出key为 id的对象,没有则返回nil

func LocalSet

func LocalSet(id int, object interface{})

LocalSet : 以id为key, 将对象object写入协程局部存储器

func Log

func Log() *log.Logger

Log : 返回日志对象接口

func Register

func Register(p uintptr)

Register : native method

func ServerMuxHandle

func ServerMuxHandle(ptr *http.ServeMux, pattern string, handler http.Handler)

func ServerMuxHandler added in v0.8.5

func ServerMuxHandler(ptr *http.ServeMux, r *http.Request) (h http.Handler, pattern string)

func SetAction

func SetAction(action *Action)

SetAction : 辅助功能函数: 将事务存到协程局部存储器

func SetComponent

func SetComponent(c *Component)

SetComponent : 辅助功能函数: 将组件存到协程局部存储器

func WrapHttpClientDo

func WrapHttpClientDo(ptr *http.Client, req *http.Request) (*http.Response, error)

func WrapServerMuxHandle

func WrapServerMuxHandle(ptr *http.ServeMux, pattern string, handler http.Handler)

func WrapServerMuxHandler added in v0.8.5

func WrapServerMuxHandler(ptr *http.ServeMux, r *http.Request) (h http.Handler, pattern string)

func WraphttpNotFound added in v0.2.0

func WraphttpNotFound(w http.ResponseWriter, r *http.Request)

Types

type Action

type Action struct {
	// contains filtered or unexported fields
}

Action : 事务对象

func CreateAction

func CreateAction(name string, method string) (*Action, error)

CreateAction : 在方法method中调用并 创建一个名为 name的事务,

func CreateTask added in v0.8.5

func CreateTask(method string) (*Action, error)

func GetAction

func GetAction() *Action

GetAction : 辅助功能函数: 将存储到协程局部存储器的Action对象取出

func (*Action) AddCustomParam

func (a *Action) AddCustomParam(k string, v string)

AddCustomParam : 添加自定义参数

func (*Action) AddRequestParam

func (a *Action) AddRequestParam(k string, v string)

AddRequestParam : 添加请求参数

func (*Action) AddResponseParam

func (a *Action) AddResponseParam(k string, v string)

AddResponseParam : 添加应答参数

func (*Action) CreateComponent

func (a *Action) CreateComponent(method string) *Component

CreateComponent : 创建函数/方法类型的组件 参数

method : 类名.方法名, 例如 main.user.login

func (*Action) CreateDBComponent

func (a *Action) CreateDBComponent(dbType uint8, host string, dbname string, table string, op string, method string) *Component

CreateDBComponent 创建数据库或NOSQL性能分解组件 参数:

dbType : 组件类型 (ComponentMysql, ComponentPostgreSQL, ComponentMongo, ComponentMemCache, ComponentRedis)
host   : 主机地址,可空
dbname : 数据库名称,可空
table  : 数据库表名
op     : 操作类型, 关系型数据库("SELECT", "INSERT", "UPDATE", "DELETE" ...), NOSQL("GET", "SET" ...)
method : 发起这个数据库调用的类名.方法名, 例如 db.query redis.get

func (*Action) CreateExternalComponent

func (a *Action) CreateExternalComponent(url string, method string) *Component

CreateExternalComponent : 创建Web Service性能分解组件 参数:

url    : 调用Web Service的url,格式: http(s)://host/uri, 例如 http://www.baidu.com/
method : 发起这个Web Service调用的类名.方法名, 例如 http.Get

func (*Action) CreateMQComponent

func (a *Action) CreateMQComponent(vender string, isConsumer bool, host, queue string) *Component

CreateMQComponent : 创建一个消息队列组件

vender : mq类型: kafka/rabbit MQ/ActiveMQ

func (*Action) CreateMongoComponent

func (a *Action) CreateMongoComponent(host, database, collection, op, method string) *Component

CreateMongoComponent 创建 Mongo 组件

func (*Action) CreateRedisComponent

func (a *Action) CreateRedisComponent(host, cmd, key, method string) *Component

CreateRedisComponent : 创建一个Redis数据库访问组件

func (*Action) CreateSQLComponent

func (a *Action) CreateSQLComponent(dbType uint8, host string, dbname string, sql string, method string) *Component

CreateSQLComponent : 以 SQL语句创建一个数据库组件

func (*Action) Finish

func (a *Action) Finish()

Finish : 事务结束时调用 HTTP请求时长 = Finish时刻 - CreateAction时刻

func (*Action) FixBegin added in v0.8.7

func (a *Action) FixBegin(begin time.Time)

FixBegin : 内部使用, 重置事务开始时间

func (*Action) GetMethod added in v0.3.0

func (a *Action) GetMethod() string

func (*Action) GetName

func (a *Action) GetName() string

GetName : 取事务名字

func (*Action) GetTxData

func (a *Action) GetTxData() string

GetTxData : 跨应用追踪接口,用于被调用端,获取当前事务的执行性能信息,通过http头或者自定义协议传回调用端

返回值: 事务的性能数据

func (*Action) GetURL

func (a *Action) GetURL() string

GetURL : 取事务的 URL

func (*Action) HasError

func (a *Action) HasError() bool

HasError : 是否发生过错误或异常

func (*Action) Ignore

func (a *Action) Ignore()

Ignore : 忽略本次事务的性能数据

func (*Action) OnEnd

func (a *Action) OnEnd(cb func())

OnEnd : 注册一个在事务结束时执行的回调函数

func (*Action) SetError

func (a *Action) SetError(e interface{})

SetError : 事务发生错误或异常时调用,记录事务的运行时错误信息

func (*Action) SetException added in v0.8.0

func (a *Action) SetException(e interface{})

SetException : 事务发生错误或异常时调用,记录事务的运行时错误信息

func (*Action) SetHTTPMethod

func (a *Action) SetHTTPMethod(httpMethod string)

SetHTTPMethod : 设置 HTTP请求方法名

func (*Action) SetHTTPStatus

func (a *Action) SetHTTPStatus(code uint16, skip int) int

SetHTTPStatus : 内部使用: 添加 http状态, skip为跳过的调用栈

func (*Action) SetName

func (a *Action) SetName(name string, method string)

SetName : 设置HTTP请求的友好名称 参数:

instance   : 分类, 例如 loginController
method : 方法, 例如 POST

func (*Action) SetStatusCode

func (a *Action) SetStatusCode(code uint16) int

SetStatusCode : 正常返回0 无效的Action 返回1 如果状态码是被忽略的错误,返回2 错误的状态码,返回3

func (*Action) SetTrackID

func (a *Action) SetTrackID(id string)

SetTrackID : 跨应用追踪接口,用于被调用端,保存调用端传递过来的跨应用追踪id

参数: 跨应用追踪id

func (*Action) SetURL

func (a *Action) SetURL(name string)

SetURL : 设置事务的url

func (*Action) Slow

func (a *Action) Slow() bool

Slow : 检测本次事务是否为慢请求 返回值: 当HTTP请求性能超出阈值时为true, 否则为false

type ClientDoFunc added in v0.7.0

type ClientDoFunc func(*http.Client, *http.Request) (*http.Response, error)

type Component

type Component struct {
	// contains filtered or unexported fields
}

Component : 构成事务的组件过程

func GetComponent

func GetComponent() *Component

GetComponent : 辅助功能函数: 将存储到协程局部存储器的组件对象取出

func (*Component) AppendSQL

func (c *Component) AppendSQL(sql string)

AppendSQL : 用于数据库组件,通过此接口将sql查询语句保存到数据库组件,在报表慢事务追踪列表展示

参数: sql语句

func (*Component) CreateComponent

func (c *Component) CreateComponent(method string) *Component

CreateComponent : 在函数/方法中调用其他函数/方法时,如果认为有必要,调用此方法测量子过程性能

func (*Component) CreateTrackID

func (c *Component) CreateTrackID() string

CreateTrackID : 跨应用追踪接口,用于调用端,生成一个跨应用追踪id,通过http头或者私有协议发送到被调用端

返回值: 字符串,一个包含授权id,应用id,实例id,事务id等信息的追踪id

func (*Component) End

func (c *Component) End(skip int)

End : 内部使用, skip为跳过的调用栈数

func (*Component) Finish

func (c *Component) Finish()

Finish : 停止组件计时 性能分解组件时长 = Finish时刻 - CreateComponent时刻 当时长超出堆栈阈值时,记录当前组件的代码堆栈

func (*Component) FixBegin

func (c *Component) FixBegin(begin time.Time)

FixBegin : 校正事务开始时间

func (*Component) FixStackEnd added in v0.6.12

func (c *Component) FixStackEnd(skip int, checkRemovedFunction func(string) bool)

End : 内部使用, skip为跳过的调用栈数

func (*Component) GetAction

func (c *Component) GetAction() *Action

GetAction : 取对应的事务对象

func (*Component) SetError

func (c *Component) SetError(e interface{}, errType string, skipStack int)

SetError : 组件错误捕获

func (*Component) SetException added in v0.8.0

func (c *Component) SetException(e interface{}, errType string, skipStack int)

SetException : 组件异常捕获

func (*Component) SetMethod added in v0.6.7

func (c *Component) SetMethod(method string)

func (*Component) SetTxData

func (c *Component) SetTxData(txData string)

SetTxData : 跨应用追踪接口,用于调用端,将被调用端返回的事务性能数据保存到外部调用组件

参数: 被调用端返回的事务的性能数据

type RoutineLocal

type RoutineLocal struct {
	// contains filtered or unexported fields
}

RoutineLocal : 事务线程局部存储对象

type Unit

type Unit struct {
	// contains filtered or unexported fields
}

Unit is The GoRoutine LocalStorage Unit

Directories

Path Synopsis
frameworks
gin
libs
list
Package list : a list
Package list : a list
map
pool
Package pool 无锁消息池,多读多写, 用于goroutine 间收发消息
Package pool 无锁消息池,多读多写, 用于goroutine 间收发消息
nosql
utils
cache_config
配置信息缓存的性能优化版本,无锁访问, array存储
配置信息缓存的性能优化版本,无锁访问, array存储
config
无锁模式的配置信息读写
无锁模式的配置信息读写
httprequest
Post请求异步封装
Post请求异步封装
logger
日志功能模块。
日志功能模块。
service
类线程封装
类线程封装
zip
zip封装
zip封装

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL