From c35321bf610392bdfe6c81642a4a9e60b4ef05e7 Mon Sep 17 00:00:00 2001 From: Gui-Yue Date: Wed, 24 Aug 2022 22:04:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9Bwebsocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/ebpfplugins/ebpfplugins.go | 16 +++++++++------- .../service/ebpfplugins/ebpfplugins.go | 11 +++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go b/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go index f95594c67..e736c167b 100644 --- a/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go +++ b/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go @@ -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("数据获取失败")) @@ -280,18 +280,20 @@ 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("插件已停止运行")) + _ = client.Close() + return } - return + _ = client.WriteMessage(websocket.TextMessage, []byte("无数据更新")) + time.Sleep(time.Second * 2) + continue } } } diff --git a/eBPF_Visualization/eBPF_server/service/ebpfplugins/ebpfplugins.go b/eBPF_Visualization/eBPF_server/service/ebpfplugins/ebpfplugins.go index 4eb4d2558..28282d09d 100644 --- a/eBPF_Visualization/eBPF_server/service/ebpfplugins/ebpfplugins.go +++ b/eBPF_Visualization/eBPF_server/service/ebpfplugins/ebpfplugins.go @@ -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 } From 6d1924ff1e7a09045bd85cf10046bc4d99e7d09f Mon Sep 17 00:00:00 2001 From: Gui-Yue Date: Thu, 25 Aug 2022 10:42:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BF=BD=E7=95=A5.db=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E5=8F=98=E5=8A=A8=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0info=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../eBPF_server/api/v1/ebpfplugins/ebpfplugins.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ce3636ec0..72bd14f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go b/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go index e736c167b..b4659f2ff 100644 --- a/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go +++ b/eBPF_Visualization/eBPF_server/api/v1/ebpfplugins/ebpfplugins.go @@ -288,6 +288,7 @@ func (e *EbpfPluginsApi) GetSinglePluginData(c *gin.Context) { } else { if !running { _ = client.WriteMessage(websocket.TextMessage, []byte("插件已停止运行")) + global.GVA_LOG.Info("插件已卸载") _ = client.Close() return }