Documentation
¶
Overview ¶
听云性能采集探针(sdk)
Index ¶
- Constants
- func AppInit(jsonFile string) error
- func AppStop()
- func ConfigRead(name string) (interface{}, bool)
- func Handle(pattern string, handler http.Handler)
- func HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func Log() *log.Logger
- func Running() bool
- func WrapHandle(pattern string, handler http.Handler) (string, http.Handler)
- func WrapHandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) (string, func(http.ResponseWriter, *http.Request))
- func WrapHandler(h http.Handler) http.Handler
- type Action
- func (a *Action) AddCustomParam(k string, v string)
- func (a *Action) AddRequestParam(k string, v string)
- func (a *Action) CreateComponent(method string) *Component
- func (a *Action) CreateDBComponent(dbType uint8, host string, dbname string, table string, op string, ...) *Component
- func (a *Action) CreateExternalComponent(url string, method string) *Component
- func (a *Action) Finish()
- func (a *Action) GetName() string
- func (a *Action) GetTxData() string
- func (a *Action) GetUrl() string
- func (a *Action) HasError() bool
- func (a *Action) Ignore()
- func (a *Action) SetError(e interface{})
- func (a *Action) SetName(instance string, method string)
- func (a *Action) SetStatusCode(code uint16) int
- func (a *Action) SetTrackId(id string)
- func (a *Action) SetUrl(name string)
- func (a *Action) Slow() bool
- type Component
Examples ¶
Constants ¶
const ( ComponentDefault = 0 ComponentDefaultDB = 32 ComponentMysql = 33 ComponentPostgreSql = 34 ComponentMongo = 48 ComponentMemCache = 49 ComponentRedis = 50 ComponentExternal = 64 )
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 )
const TINGYUN_GO_AGENT_VERSION = "0.6.0"
Variables ¶
This section is empty.
Functions ¶
func AppInit ¶
初始化听云探针 参数:
jsonFile: 听云配置文件路径,文件格式为json格式
Example ¶
tingyun.AppInit("tingyun.json") tingyun.AppStop()
Output:
func ConfigRead ¶
func Handle ¶
封装http.Handle 例如: 初始代码为 http.Handle("/login", http.HandlerFunc(loginHandler)) 应该替换为 tingyun.Handle("/login", http.HandlerFunc(loginHandler))
func HandleFunc ¶
func HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
封装http.HandleFunc函数 例如: 初始代码为 http.HandleFunc("/login", loginHandler) 应该替换为 tingyun.HandleFunc("/login", loginHandler)
func WrapHandleFunc ¶
func WrapHandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) (string, func(http.ResponseWriter, *http.Request))
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
func CreateAction ¶
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() action, _ := tingyun.CreateAction("/login", "main.ExampleCreateAction") time.Sleep(time.Millisecond * 100) action.Finish()
Output:
func GetAction ¶
func GetAction(w http.ResponseWriter) *Action
从封装的http.ResponseWriter中获取tingyun上下文 参数:
http.ResponseWriter: 被tingyun.wrapper封装的http.ResponseWriter
例如
func loginHandler(w http.ResponseWriter, r *http.Request) { action := tingyun.GetAction(w) action.SetName("bee", "login") }
func (*Action) AddCustomParam ¶
func (*Action) AddRequestParam ¶
func (*Action) CreateComponent ¶
创建性能分解组件,作用为将一个HTTP请求拆分为多个可以度量的组件 参数
method : 类名.方法名, 例如 main.user.login
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() action, _ := tingyun.CreateAction("/login", "main.ExampleCreateAction") component := action.CreateComponent("normalExample") 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
创建数据库或NOSQL性能分解组件 参数:
dbType : 组件类型 (ComponentMysql, ComponentPostgreSql, ComponentMongo, ComponentMemCache, ComponentRedis) host : 主机地址,可空 dbname : 数据库名称,可空 table : 数据库表名 op : 操作类型, 关系型数据库("SELECT", "INSERT", "UPDATE", "DELETE" ...), NOSQL("GET", "SET" ...) method : 发起这个数据库调用的类名.方法名, 例如 db.query redis.get
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() action, _ := tingyun.CreateAction("/login", "main.ExampleCreateAction") dbComponent := action.CreateDBComponent(tingyun.ComponentMysql, "", "mydatabase", "mytable", "select", "ExampleCreateDBComponent") time.Sleep(time.Millisecond * 100) dbComponent.Finish() action.Finish()
Output:
func (*Action) CreateExternalComponent ¶
创建Web Service性能分解组件 参数:
url : 调用Web Service的url,格式: http(s)://host/uri, 例如 http://www.baidu.com/ method : 发起这个Web Service调用的类名.方法名, 例如 http.Get
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() action, _ := tingyun.CreateAction("/login", "main.ExampleCreateAction") externalComponent := action.CreateExternalComponent("/external", "main.ExampleCreateExternalComponent") time.Sleep(time.Millisecond * 100) externalComponent.Finish() action.Finish()
Output:
func (*Action) Finish ¶
func (a *Action) Finish()
停止HTTP请求的性能计时 HTTP请求时长 = Finish时刻 - CreateAction时刻
func (*Action) GetTxData ¶
跨应用追踪接口,用于被调用端,获取当前事务的执行性能信息,通过http头或者自定义协议传回调用端
返回值: 事务的性能数据
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() tingyun_beego.Handler("/extern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if track_id := r.Header.Get("X-Tingyun-Id"); len(track_id) > 0 { tingyun_beego.GetAction(w).SetTrackId(track_id) } url := "http://192.168.100.1/x.php" c := tingyun_beego.GetAction(w).CreateExternalComponent(url, "main.Extern") result, response, err := HttpGet(url, map[string]string{"X-Tingyun-Id": c.CreateTrackId()}) if response != nil { if tx_data := response.Header.Get("X-Tingyun-Tx-Data"); len(tx_data) > 0 { c.SetTxData(tx_data) } //从被调用端action获取事务性能数据 if tx_data := tingyun_beego.GetAction(w).GetTxData(); len(tx_data) > 0 { w.Header().Set("X-Tingyun-Tx-Data", tx_data) } w.Header().Set("Content-Type", response.Header.Get("Content-Type")) w.WriteHeader(response.StatusCode) w.Write(result) } else { fmt.Fprintf(w, "%q", "/extern error:"+err.Error()) } c.Finish() })) tingyun_beego.Run()
Output:
func (*Action) SetStatusCode ¶
正常返回0 无效的Action 返回1 如果状态码是被忽略的错误,返回2 错误的状态码,返回3
func (*Action) SetTrackId ¶
跨应用追踪接口,用于被调用端,保存调用端传递过来的跨应用追踪id
参数: 跨应用追踪id
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() tingyun_beego.Handler("/extern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if track_id := r.Header.Get("X-Tingyun-Id"); len(track_id) > 0 { tingyun_beego.GetAction(w).SetTrackId(track_id) //将调用端传递来的追踪id保存到action } url := "http://192.168.100.1/x.php" c := tingyun_beego.GetAction(w).CreateExternalComponent(url, "main.Extern") result, response, err := HttpGet(url, map[string]string{"X-Tingyun-Id": c.CreateTrackId()}) if response != nil { if tx_data := response.Header.Get("X-Tingyun-Tx-Data"); len(tx_data) > 0 { c.SetTxData(tx_data) } if tx_data := action.GetTxData(); len(tx_data) > 0 { w.Header().Set("X-Tingyun-Tx-Data", tx_data) } w.Header().Set("Content-Type", response.Header.Get("Content-Type")) w.WriteHeader(response.StatusCode) w.Write(result) } else { fmt.Fprintf(w, "%q", "/extern error:"+err.Error()) } c.Finish() })) tingyun_beego.Run()
Output:
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
func (*Component) AppendSQL ¶
用于数据库组件,通过此接口将sql查询语句保存到数据库组件,在报表慢事务追踪列表展示
参数: sql语句
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() action, _ := tingyun.CreateAction("/login", "main.ExampleCreateAction") dbComponent := action.CreateDBComponent(tingyun.ComponentPostgreSql, "postgredb.local:5432", "testdb", "testtable", "SELECT", "main") dbComponent.AppendSQL("SELECT id, name FROM testtable") time.Sleep(time.Millisecond * 100) dbComponent.Finish() action.Finish()
Output:
func (*Component) CreateComponent ¶
func (*Component) CreateTrackId ¶
跨应用追踪接口,用于调用端,生成一个跨应用追踪id,通过http头或者私有协议发送到被调用端
返回值: 字符串,一个包含授权id,应用id,实例id,事务id等信息的追踪id
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() tingyun_beego.Handler("/extern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if track_id := r.Header.Get("X-Tingyun-Id"); len(track_id) > 0 { tingyun_beego.GetAction(w).SetTrackId(track_id) } url := "http://192.168.100.1/x.php" c := tingyun_beego.GetAction(w).CreateExternalComponent(url, "main.Extern") result, response, err := HttpGet(url, map[string]string{"X-Tingyun-Id": c.CreateTrackId()}) //由外部调用组件生成追踪id if response != nil { if tx_data := response.Header.Get("X-Tingyun-Tx-Data"); len(tx_data) > 0 { c.SetTxData(tx_data) } if tx_data := action.GetTxData(); len(tx_data) > 0 { w.Header().Set("X-Tingyun-Tx-Data", tx_data) } w.Header().Set("Content-Type", response.Header.Get("Content-Type")) w.WriteHeader(response.StatusCode) w.Write(result) } else { fmt.Fprintf(w, "%q", "/extern error:"+err.Error()) } c.Finish() })) tingyun_beego.Run()
Output:
func (*Component) Finish ¶
func (c *Component) Finish()
停止性能分解组件计时 性能分解组件时长 = Finish时刻 - CreateComponent时刻 当时长超出堆栈阈值时,记录当前组件的代码堆栈
func (*Component) SetTxData ¶
跨应用追踪接口,用于调用端,将被调用端返回的事务性能数据保存到外部调用组件
参数: 被调用端返回的事务的性能数据
Example ¶
tingyun.AppInit("tingyun.json") defer tingyun.AppStop() tingyun_beego.Handler("/extern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if track_id := r.Header.Get("X-Tingyun-Id"); len(track_id) > 0 { tingyun_beego.GetAction(w).SetTrackId(track_id) } url := "http://192.168.100.1/x.php" c := tingyun_beego.GetAction(w).CreateExternalComponent(url, "main.Extern") result, response, err := HttpGet(url, map[string]string{"X-Tingyun-Id": c.CreateTrackId()}) if response != nil { if tx_data := response.Header.Get("X-Tingyun-Tx-Data"); len(tx_data) > 0 { c.SetTxData(tx_data) //将被调用端返回的事务数据保存到外部调用组件 } if tx_data := action.GetTxData(); len(tx_data) > 0 { w.Header().Set("X-Tingyun-Tx-Data", tx_data) } w.Header().Set("Content-Type", response.Header.Get("Content-Type")) w.WriteHeader(response.StatusCode) w.Write(result) } else { fmt.Fprintf(w, "%q", "/extern error:"+err.Error()) } c.Finish() })) tingyun_beego.Run()
Output:
Source Files
¶
- api-action.go
- api-application.go
- api-component.go
- config.go
- control-application.go
- private-action.go
- private-application.go
- private-component.go
- runtimeinfo.go
- service-dc_interface.go
- service-dc_private.go
- struct-action.go
- struct-actionperf.go
- struct-actiontrace.go
- struct-actiontrace_set.go
- struct-apdex.go
- struct-appdata.go
- struct-errorinfo.go
- struct-errortrace_set.go
- struct-performance.go
- struct-performance_map.go
- struct-quartileP2.go
- struct-sqlperf.go
- struct-sqlperf_map.go
- struct-sqltrace.go
- struct-sqltrace_map.go
- sysinfo.go
- tingyun.go
- util.go
- wrapper.go
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
framework
|
|
beego
beego's Wrapper
|
beego's Wrapper |
gin
gin's wrapper
|
gin's wrapper |
utils
|
|
cache_config
配置信息缓存的性能优化版本,无锁访问, array存储
|
配置信息缓存的性能优化版本,无锁访问, array存储 |
config
无锁模式的配置信息读写
|
无锁模式的配置信息读写 |
httprequest
Post请求异步封装
|
Post请求异步封装 |
list
A better List then native
|
A better List then native |
logger
日志功能模块。
|
日志功能模块。 |
pool
无锁消息池,多读多写, 用于goroutine 间收发消息
|
无锁消息池,多读多写, 用于goroutine 间收发消息 |
service
类线程封装
|
类线程封装 |
zip
zip封装
|
zip封装 |