API接口

Bifrost 提供相应的监控接口,用于第三方监控服务器对Bifrost进行监控

数据源列表

URL: /db/list?format=json

METHOD: GET

返回数据结构:

  1. map[string]DbListStruct
  2. type DbListStruct struct {
  3. Name string // DbName
  4. ConnectUri string // 连接地址
  5. ConnStatus string // close,stop,starting,running
  6. ConnErr string // 连接错误
  7. ChannelCount int // 通道数量
  8. LastChannelID int // 最大的通道ID
  9. TableCount int // 设置了同步的表的数量
  10. BinlogDumpFileName string // 位点文件
  11. BinlogDumpPosition uint32 // 位点
  12. MaxBinlogDumpFileName string // 到哪一个位点文件停止解析
  13. MaxBinlogDumpPosition uint32 // 到哪一个位点停止解析
  14. ReplicateDoDb map[string]uint8 // 需要同步的库
  15. ServerId uint32 // 模拟从库的ServerId
  16. AddTime int64 // 添加数据源时候的时间戳
  17. }
案例
  1. func main(){
  2. //跳过证书验证
  3. tr := &http.Transport{
  4. TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
  5. }
  6. url := "https://127.0.0.1:21036/db/list?format=json"
  7. client := &http.Client{Timeout:10 * time.Second,Transport: tr,}
  8. req, err := http.NewRequest("GET",url, nil)
  9. if err != nil {
  10. log.Println(err)
  11. return
  12. }
  13. req.SetBasicAuth("Bifrost","Bifrost123")
  14. resp, err2 := client.Do(req)
  15. if err2 != nil{
  16. log.Println(err2)
  17. return
  18. }
  19. defer resp.Body.Close()
  20. body, err := ioutil.ReadAll(resp.Body)
  21. log.Println("body:",string(body))
  22. }
  1. https://127.0.0.1:21036/db/list?format=json
  1. {"myTest":{"Name":"myTest","ConnectUri":"root:@tcp(127.0.0.1:3306)/test","ConnStatus":"running","ConnErr":"running","ChannelCount":1,"LastChannelID":1,"TableCount":2,"BinlogDumpFileName":"mysql-bin.000015","BinlogDumpPosition":43311,"MaxBinlogDumpFileName":"","MaxBinlogDumpPosition":0,"ReplicateDoDb":{"bifrost_test":1,"test":1},"ServerId":167,"AddTime":0}}

表同步列表

表同步列表是设置了需要同步的表的列表

URL : /synclist?format=json

METHOD : POST | GET

参数
  1. dbname string 数据源名称 可选
  2. toserverkey string 目标库 ToServerKey 可选
  3. channelid int 通道id,不是通道名字 可选
  4. schema_name string 数据库名称 可选
  5. table_name string 表名称 可选

返回数据结构:

  1. []syncListStruct
  2. type syncListStruct struct {
  3. DbName string `json:"DbName"` // 数据源名称
  4. SchemaName string `json:"SchemaName"` // 数据库名
  5. TableName string `json:"TableName"` // 表名
  6. ToServerList []*server.ToServer `json:"ToServerList"`
  7. }
  8. type ToServer struct {
  9. ToServerID int
  10. PluginName string
  11. MustBeSuccess bool
  12. FilterQuery bool
  13. FilterUpdate bool
  14. FieldList []string
  15. ToServerKey string
  16. BinlogFileNum int // 当前同步的位点文件
  17. BinlogPosition uint32 // 当前同步的位点
  18. PluginParam map[string]interface{} // 插件参数
  19. Status string // 同步状态
  20. Error string // 同步失败时候产生的错误信息.假如这个错误不为空,则说明同步有问题了
  21. ErrorWaitDeal int // 1 为下一次重试的时候,则错过一条数据,界面上Miss 按钮,就是将这个值个性为 1
  22. ErrorWaitData interface{} // 当前同步失败的时候的 数据
  23. }

这个接口可以用于监控同步是否正常,当 Error 不为空的时候,则说明同步可能存在问题

监控也要以参考 Bifrost 报警模块

案例
  1. https://127.0.0.1:21036/synclist?dbname=myTest&schema_name=&table_name=&toserverkey=&channelid=0&format=json
  1. [{"DbName":"myTest","SchemaName":"bifrost_test","TableName":"binlog_field_test","ToServerList":[{"ToServerID":1,"PluginName":"hprose","MustBeSuccess":true,"FilterQuery":false,"FilterUpdate":false,"FieldList":[],"ToServerKey":"sdfsdfsf","BinlogFileNum":0,"BinlogPosition":0,"PluginParam":{},"Status":"","Error":"","ErrorWaitDeal":0,"ErrorWaitData":null}]},{"DbName":"myTest","SchemaName":"test","TableName":"test","ToServerList":[]}]

流量

流量接口,可提供 1分钟,10分钟,1小时,8小时,24小时内的的流量信息

返回的流量是全量信息,不是增量,但可以自行通过全量数据的差值算出增量数据

URL : /flow/get?format=json

METHOD : GET

参数
  1. dbname string 数据源名称 可选
  2. channelid int 通道id,不是通道名字 可选
  3. schema string 数据库名称 可选
  4. table_name string 表名称 可选
  5. type string 查询数据类型(minute,tenminute,hour,eighthour,day) 必填

返回数据结构:

  1. []CountContent
  2. type CountContent struct {
  3. Time int64 // 时间戳
  4. Count int64 // 全量条数
  5. ByteSize int64 // 全量大小,单位 byte
  6. }
案例
  1. https://127.0.0.1:21036/flow/get?format=json&type=minute
  1. [
  2. {"Time":1555079740,"Count":0,"ByteSize":0},{"Time":1555079745,"Count":0,"ByteSize":0},
  3. {"Time":1555079750,"Count":0,"ByteSize":0},{"Time":1555079755,"Count":0,"ByteSize":0},
  4. {"Time":1555079760,"Count":0,"ByteSize":0},{"Time":1555079765,"Count":0,"ByteSize":0},
  5. {"Time":1555079770,"Count":0,"ByteSize":0},{"Time":1555079775,"Count":0,"ByteSize":0},
  6. {"Time":1555079780,"Count":0,"ByteSize":0},{"Time":1555079790,"Count":0,"ByteSize":0},{"Time":1555079800,"Count":0,"ByteSize":0},{"Time":1555079805,"Count":0,"ByteSize":0}
  7. ]