Skip to content

Commit

Permalink
Merge pull request linuxkerneltravel#320 from Gui-Yue/add_websocket
Browse files Browse the repository at this point in the history
改进websocket
  • Loading branch information
helight authored Aug 26, 2022
2 parents 6b7c87e + 2f972f2 commit 530cce9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tags
/eBPF_Visualization/eBPF_server/log
/eBPF_Visualization/eBPF_web/node_modules
/eBPF_Visualization/eBPF_web/dist
/eBPF_Visualization/eBPF_server/model/data_collector/dao/tables/ebpfplugin.db
/eBPF_Visualization/eBPF_server/model/data_collector/dao/tables/*.db

*.iml

Expand Down
17 changes: 10 additions & 7 deletions eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (e *EbpfPluginsApi) GetSinglePluginData(c *gin.Context) {
client, _ := upgrager.Upgrade(c.Writer, c.Request, nil)
data_lenth := 0
for {
err, singleplugindata := ebpfService.FindRows(id)
err, singleplugindata, running := ebpfService.FindRows(id)
if err != nil {
global.GVA_LOG.Error("获取失败", zap.Error(err))
_ = client.WriteMessage(websocket.TextMessage, []byte("数据获取失败"))
Expand All @@ -280,18 +280,21 @@ func (e *EbpfPluginsApi) GetSinglePluginData(c *gin.Context) {
if err != nil {
global.GVA_LOG.Error("写入json数据失败", zap.Error(err))
_ = client.WriteMessage(websocket.TextMessage, []byte("写入json数据失败"))
_ = client.Close()
return
}
time.Sleep(time.Second * 2)
data_lenth = len(singleplugindata)
} else {
if err := client.WriteMessage(websocket.TextMessage, []byte("数据加载完毕,无数据更新")); err != nil {
global.GVA_LOG.Error("websocket message写入错误", zap.Error(err))
}
if err := client.Close(); err != nil {
global.GVA_LOG.Error("websocket 关闭失败:", zap.Error(err))
if !running {
_ = client.WriteMessage(websocket.TextMessage, []byte("插件已停止运行"))
global.GVA_LOG.Info("插件已卸载")
_ = client.Close()
return
}
return
_ = client.WriteMessage(websocket.TextMessage, []byte("无数据更新"))
time.Sleep(time.Second * 2)
continue
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,23 @@ func (ebpf EbpfpluginsService) GetRunningPluginsInfo(info request.PageInfo) (err
//@description: 获取单个插件的数据
//@param: pluginid int
//@return: err error, list []map[string]interface{}
func (ebpf EbpfpluginsService) FindRows(pluginid int) (error, []map[string]interface{}) {
func (ebpf EbpfpluginsService) FindRows(pluginid int) (error, []map[string]interface{}, bool) {
var runningplugin dao.Indextable
dao.GLOBALDB.Table("indextable").Where("IndexID=?", pluginid).First(&runningplugin)
var results []map[string]interface{}
rows, err := dao.GLOBALDB.Table(runningplugin.PluginName).Rows()
if err != nil {
return err, results
return err, results, false
}
for rows.Next() {
result := map[string]interface{}{}
if err := dao.GLOBALDB.ScanRows(rows, &result); err != nil {
return err, results
return err, results, false
}
results = append(results, result)
}
return err, results
if runningplugin.State == false {
return err, results, false
}
return err, results, true
}

0 comments on commit 530cce9

Please sign in to comment.