tingyun3

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

README

goagent

TingYun APM3.0 - Go

Documentation

Overview

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

Index

Examples

Constants

View Source
const (
	ComponentDefault    = 0
	ComponentDefaultDB  = 32
	ComponentMysql      = 33
	ComponentPostgreSQL = 34
	ComponentMSSQL      = 35
	ComponentSQLite     = 36
	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 = "3.1.0"

Variables

This section is empty.

Functions

func ConfigRead

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

ConfigRead : 读配置项

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 is Return the goroutine id

func HttpClientDo

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

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 uintptr, pattern string, handler http.Handler)

func ServerServe

func ServerServe(srv *http.Server, l net.Listener) error

func SetAction

func SetAction(action *Action)

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

func SetComponent

func SetComponent(c *Component)

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

func WrapHttpClientDo

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

func WrapServerMuxHandle

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

func WrapServerServe

func WrapServerServe(srv *http.Server, l net.Listener) error

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的事务,

Example
action, _ := tingyun3.CreateAction("ROUTER", "main.ExampleCreateAction")
time.Sleep(time.Millisecond * 100)
action.Finish()
Output:

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
Example
action, _ := tingyun3.CreateAction("ROUTER", "main.ExampleAction_CreateComponent")
component := action.CreateComponent("ExampleAction_CreateComponent")
subComponent := component.CreateComponent("subcomponent")
time.Sleep(time.Millisecond * 100)
subComponent.Finish()
component.Finish()
action.Finish()
Output:

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

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) 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) 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 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) GetAction

func (c *Component) GetAction() *Action

GetAction : 取对应的事务对象

func (*Component) SetError

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

SetError : 组件错误捕获

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