安装Golang Agent
卸载Golang Agent
兼容性说明
Golang Agent支持的Golang版本如下:
| Golang版本 | 框架 | 框架版本 | 
| V1.10 | Gim | Golang版本自带版本 | 
| Martini | Golang版本自带版本 | |
| V1.11 | Gim | Golang版本自带版本 | 
| Martini | Golang版本自带版本 | |
| V1.12 | Gim | Golang版本自带版本 | 
| Martini | Golang版本自带版本 | |
| V1.13 | Gim | Golang版本自带版本 | 
| Martini | Golang版本自带版本 | 
Golang Agent支持的数据库类型及相应驱动版本如下:
| 数据库类型 | 驱动版本 | 
| MySQL | mysql-5.6.36 | 
| PostgreSQL | pgsql-9.3,pgsql-9.6 | 
| Redis | redis 2.8.3 | 
Golang Agent支持的操作系统及版本如下:
| 操作系统 | 版本 | 
| Centos | V6.6 | 
| V7.6 | |
| Ubuntu | V14.04 | 
安装Golang Agent
安装Golang Agent:
1、配置系统环境变量
2、解压缩安装包
3、配置
4、安装Golang Agent
5.     重新编译应用
6. 开启/关闭debug
获取授权编号
授权编号是透视宝用户身份识别的License Key,每个用户对应一个唯一的授权编号,在后续配置中需要使用。
下载Golang Agent
点击<下载Golang Agent(版本)>按钮或复制Wget链接,下载最新版本的安装包。
安装Golang Agent
1. 配置系统环境变量。
n 如果系统设置了$GOPATH环境变量go env | grep GOPATH,不需要再配置。
n 如果$GOPATH环境变量不存在,则设置为export GOPATH=/yourGOPATH
2. 解压缩安装包到$GOPATH/src目录。
unzip GoAgent_Linux_2.1.0.zip -d $GOPATH/src
3. 进入$GOPATH/src/cloudwise/conf目录下的agent.ini文件,配置License Key,app name等内容。
basic.app_name=golang_gin basic.license_key= J45Engw88Nc/fR1k7e53nphkNSQbbc8JEfXHo5cek8NKBcPok1f56Q!!!! server.setting_url=http://data.toushibao.com #实际按具体数据发送地址配置 server.data_url=http://data.toushibao.com
4. 安装Golang Agent。
注意:安装前用如下命令备份源码,供恢复使用。
cp -r youproject youproject_bak
1)复制配置文件夹到程序目录。
cp -r $GOPATH/src/cloudwise/conf youproject/
2) 注入Golang Agent。
a)修改用户应用import包位置。
- 用户原组件(martini/gin/mysql/pgsql/redis/http)
// brfore: import ( /* gin */ "github.com/gin-gonic/gin" /* martini */ "github.com/go-martini/martini" /* mysql */ _ "github.com/go-sql-driver/mysql" /* pgsql */ _ "github.com/lib/pq" /* redis(redigo) */ "github.com/gomodule/redigo/redis" /* http */ "net/http" "database/sql" ) // after: import ( "cloudwise" /* gin */ "cloudwise/_integrations/cloudwise_gin/v1" "github.com/gin-gonic/gin" /* martini */ "cloudwise/_integrations/cloudwise_martini/v1" /* mysql */ _ "cloudwise/_integrations/mysql" /* pgsql */ _ "cloudwise/_integrations/pq" /* redis */ "cloudwise/_integrations/redis/redigo/v1" /* http */ "cloudwise/http" "database/sql" "context" )
3) 在用户main函数中初始化gin。
import (
    // before
    "github.com/gin-gonic/gin"
 
    // after
    "cloudwise/_integrations/cloudwise_gin/v1"
    "github.com/gin-gonic/gin"
)
 
func main() {
    // before
    router := gin.New() // gin.New()
 
    // after
    cloudwise.Init()
    router := cloudwise_gin.New() // cloudwise_gin.Default()
}在用户main函数中初始化martini。
import (
    // before
    "github.com/go-martini/martini"
 
    // after
    "cloudwise/_integrations/cloudwise_martini/v1"
)
 
func main() {
    // before
    m := martini.Classic()
 
    // after
    cloudwise.Init()
    m := cloudwise_martini.Classic()
}MySQL的使用
import (
    // before
    ...
    _ "github.com/go-sql-driver/mysql"
 
    // after
    ...
    "cloudwise"
    _ "cloudwise/_integrations/pq"
)
func mysql(c *gin.Context) {
    // before
    db, err := sql.Open("mysql", mysqlCon)
    ......
    db.Query( "SELECT count(*) from user_zhx2018")
 
 
    // after
    db, err := sql.Open("cwmysql", mysqlCon)
    ......
    ctx := cloudwise.NewContext(context.Background(), cloudwise.CwTxn)
    db.QueryContext(ctx, "SELECT count(*) from user_zhx2018")
}PostgreSQL的使用
import (
    // before
    ...
    _ "github.com/lib/pq"
 
    // after
    ...
    "cloudwise"
    _ "cloudwise/_integrations/mysql"
)
func mysql(c *gin.Context) {
    // before
    db, err := sql.Open("postgres", pgsqlCon)
    ......
    db.QueryRow( "SELECT count(*) FROM student")
 
    // after
    db, err := sql.Open("cwpostgres", pgsqlCon)
    ......
    ctx := cloudwise.NewContext(context.Background(), cloudwise.CwTxn)
    db.QueryRowContext(ctx, "SELECT count(*) FROM student")
}Redis应用(redigo库)
import ( // before ... "github.com/gomodule/redigo/redis" // after ... "cloudwise/_integrations/redis/redigo/v1" )
端到端HTTP
import ( // before ... "net/http" // after ... "cloudwise/http" )
5. 重新编译应用。
执行如下命令:
go build main.go
6. 开启/关闭debug。
# 开启export AGENT_RUNMODE=dev # 关闭export AGENT_RUNMODE=prod
大致两分钟后您就可以在Server模块中查看数据。
注意:无人访问过的应用不会出现在应用清单中。
卸载Golang Agent
将备份的源码恢复。
mv youproject_bak youproject
