From 4327af2fcdcccaeb602f1af4ec46fa99424d71ea Mon Sep 17 00:00:00 2001 From: jc3wish Date: Sat, 14 Oct 2023 16:15:58 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E8=BE=93=E5=85=A5=E6=A1=86=E4=BB=8Einput?= =?UTF-8?q?=E6=8D=A2=E6=88=90texterea=E4=B9=8B=E5=A4=96=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E8=83=BD=E4=BC=9A=E6=97=A0=E6=84=8F=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E6=9C=AB=E5=B0=BE=E6=9C=89=E6=8D=A2=E8=A1=8C=E7=AC=A6?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E9=83=A8=E5=88=86=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8JS=E5=BC=BA=E5=88=B6=E5=B0=86=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9A=84=E8=BE=93=E5=85=A5=E6=A1=86=E5=80=BC?= =?UTF-8?q?=20=EF=BC=8C=E5=8E=BB=E9=99=A4=E6=8E=89=E5=89=8D=E5=90=8E?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/view/template/db.list.html | 4 ++++ admin/view/template/toserver.list.html | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/admin/view/template/db.list.html b/admin/view/template/db.list.html index 89a94cca..c6bd3cc6 100644 --- a/admin/view/template/db.list.html +++ b/admin/view/template/db.list.html @@ -309,6 +309,10 @@
Add new DB
$("#uri").change( function(){ dbUriChecked = false; + // 去除前后换行符 + var uri = $(this).val() + uri = uri.replace(/^\n+|\n+$/g, ''); + $(this).val(uri); $("#checkUriBtn").show(); } ); diff --git a/admin/view/template/toserver.list.html b/admin/view/template/toserver.list.html index c000f9fb..6fa39c4f 100644 --- a/admin/view/template/toserver.list.html +++ b/admin/view/template/toserver.list.html @@ -262,6 +262,10 @@
Add new Server
$("#ConnUri").change( function(){ uriChecked = false; + // 去除前后换行符 + var uri = $(this).val() + uri = uri.replace(/^\n+|\n+$/g, ''); + $(this).val(uri); $("#checkUriBtn").show(); } ); @@ -377,6 +381,8 @@
Add new Server
var ToServerKey = $("#updateToServerInfoDiv input[name=ToServerKey]").val(); var PluginName = $("#updateToServerInfoDiv input[name=PluginName]").val(); var ConnUri = $("#updateToServerInfoDiv textarea[name=ConnUri]").val(); + // 去除前后换行符 + ConnUri = ConnUri.replace(/^\n+|\n+$/g, ''); var Notes = $("#updateToServerInfoDiv textarea[name=Notes]").val(); var url = "/toserver/update"; if( MinConn == "" || isNaN(MinConn) ){ From 3bd60033443127ac6613b10e60a48bb2c111fef3 Mon Sep 17 00:00:00 2001 From: jc3wish Date: Sat, 14 Oct 2023 16:19:07 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20input=20mock=20?= =?UTF-8?q?=E5=9C=A8batch=E6=A8=A1=E5=BC=8F=E4=B8=8B=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=89=8D=E9=80=80=E5=87=BAbatch=E7=9A=84=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input/mock/performance_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/input/mock/performance_table.go b/input/mock/performance_table.go index 2de51f78..2917fc39 100644 --- a/input/mock/performance_table.go +++ b/input/mock/performance_table.go @@ -61,7 +61,7 @@ func (t *PerformanceTable) Start(ctx context.Context, ch chan *pluginDriver.Plug t.Batch(&count, halfDataCount) timer := time.NewTimer(t.InterVal) for { - if t.TableRowsEventCount >= count { + if count >= t.TableRowsEventCount { return } select { From 537998f46418ba4c886482361b14435230c66490 Mon Sep 17 00:00:00 2001 From: jc3wish Date: Sat, 14 Oct 2023 16:48:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dinput=20mock=20=E5=85=A8?= =?UTF-8?q?=E9=87=8F=E5=AE=8C=E5=90=8E=EF=BC=8C=E5=86=85=E5=AD=98=E5=B9=B6?= =?UTF-8?q?=E6=B2=A1=E9=87=8A=E6=94=BE=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- input/mock/input.go | 4 ++-- input/mock/performance_table.go | 3 +++ input/mock/status.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/input/mock/input.go b/input/mock/input.go index f6142355..2400fb53 100644 --- a/input/mock/input.go +++ b/input/mock/input.go @@ -94,7 +94,7 @@ func (c *InputMock) Start0() error { c.StartNormalTables() c.StartPerformanceTables() if len(c.tableMap) == 0 { - c.setStatus(inputDriver.CLOSED) + c.Close() return errors.New("no table setting sync") } go c.TableTaskWait() @@ -115,7 +115,7 @@ func (c *InputMock) TableTaskWait() { c.Unlock() }() c.ws.Wait() - c.setStatus(inputDriver.CLOSED) + c.Close() } func (c *InputMock) StartNormalTables() { diff --git a/input/mock/performance_table.go b/input/mock/performance_table.go index 2917fc39..b408cb36 100644 --- a/input/mock/performance_table.go +++ b/input/mock/performance_table.go @@ -49,6 +49,9 @@ func (t *PerformanceTable) Start(ctx context.Context, ch chan *pluginDriver.Plug t.event = pluginTestData.NewEvent() t.event.SetSchema(t.SchemaName) t.event.SetTable(t.TableName) + defer func() { + t.event = nil + }() var count int var halfDataCount int diff --git a/input/mock/status.go b/input/mock/status.go index 30f53723..aca2a5b0 100644 --- a/input/mock/status.go +++ b/input/mock/status.go @@ -45,6 +45,7 @@ func (c *InputMock) Stop() error { } func (c *InputMock) Close() error { + c.tableMap = nil c.Stop() c.setStatus(inputDriver.CLOSED) return nil From d632cb0690405d55e41ad827f6ca6114a1270feb Mon Sep 17 00:00:00 2001 From: jc3wish Date: Sat, 14 Oct 2023 16:59:22 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Linux=20=E4=BD=9C=E4=B8=BA=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=EF=BC=8C?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E8=AF=BB=E5=8F=96=20/proc/[pid]/status=20?= =?UTF-8?q?=E5=86=85=E6=A0=B8=E6=96=87=E4=BB=B6=E4=B8=8B=E7=9A=84=20VmRSS?= =?UTF-8?q?=20=E4=BD=9C=E4=B8=BA=E5=86=85=E5=AD=98=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=87=8F=20=E5=85=B6=E4=BB=96=E7=B3=BB=E7=BB=9F=20=EF=BC=8C?= =?UTF-8?q?=E5=B0=86=E7=BB=A7=E7=BB=AD=E4=BD=BF=E7=94=A8Go=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E7=9A=84runtime.MemStats=E9=87=8C=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/controller/index.go | 57 +++++++++++++++++++++++++++++++--- admin/view/template/index.html | 11 +++++-- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/admin/controller/index.go b/admin/controller/index.go index 8c91ea23..94314b7d 100644 --- a/admin/controller/index.go +++ b/admin/controller/index.go @@ -16,13 +16,18 @@ limitations under the License. package controller import ( + "fmt" "github.com/brokercap/Bifrost/config" "github.com/brokercap/Bifrost/plugin/driver" pluginStorage "github.com/brokercap/Bifrost/plugin/storage" "github.com/brokercap/Bifrost/server" + "io" + "os" "runtime" - "time" "runtime/debug" + "strconv" + "strings" + "time" ) var StartTime = "" @@ -38,7 +43,7 @@ type IndexController struct { // 首页 func (c *IndexController) Index() { c.SetTitle("Index") - c.AddAdminTemplate("index.html","header.html","footer.html") + c.AddAdminTemplate("index.html", "header.html", "footer.html") } // Bifrostd 基本信息 @@ -70,12 +75,56 @@ func (c *IndexController) Overview() { // 获取 golang 运行的基本信息 func (c *IndexController) ServerMonitor() { - memStat := new(runtime.MemStats) - runtime.ReadMemStats(memStat) + type MemStat struct { + ResUsed uint64 + Runtime *runtime.MemStats + } + memStat := MemStat{ + Runtime: new(runtime.MemStats), + } + runtime.ReadMemStats(memStat.Runtime) + memStat.ResUsed = c.getMemResUsed() c.SetJsonData(memStat) c.StopServeJSON() } +// 获取当前进程相对应Top命令出来的结果值中相对应的RES列的值 +// RES对应的值,对于真正内存使用理,相对更为准确合理 +// runtime.MemStats 中是由Go自行统计的,可能存在误差 +func (c *IndexController) getMemResUsed() uint64 { + if runtime.GOOS != "linux" { + return 0 + } + + statusFilePath := fmt.Sprintf("/proc/%d/status", os.Getpid()) + + f, err := os.Open(statusFilePath) + if err != nil { + return 0 + } + defer f.Close() + content, err := io.ReadAll(f) + if err != nil { + return 0 + } + + lines := strings.Split(string(content), "\n") + for _, line := range lines { + if strings.HasPrefix(line, "VmRSS:") { + fields := strings.Fields(line) + if len(fields) >= 2 { + // 解析VmRSS值为uint64 + vmRSSValue, parseErr := strconv.ParseUint(fields[1], 10, 64) + if parseErr != nil { + return 0 + } + return vmRSSValue * 1024 + } + } + } + return 0 +} + // 强制运行 golang gc func (c *IndexController) FreeOSMemory() { debug.FreeOSMemory() diff --git a/admin/view/template/index.html b/admin/view/template/index.html index 6f5a9847..f4998484 100644 --- a/admin/view/template/index.html +++ b/admin/view/template/index.html @@ -91,7 +91,7 @@

0

0 - +

Bifrost Used
@@ -336,7 +336,7 @@
Bifrost动态
$("#freeOSMemory").click( function() { var callback = function (data) { - alert("释放成功!"); + alert("提交成功!"); return true; }; Ajax("GET","/freeOSMemory",{},callback,true); @@ -361,7 +361,12 @@
Bifrost动态
function getServerInfo() { var callback = function (d) { - var size = d.Sys/1024/1024; + var size = 0 + if(d.ResUsed > 0 ){ + size = d.ResUsed/1024/1024; + }else{ + size = d.Runtime.Sys/1024/1024; + } var sizeString = ""; if (size>1024){ sizeString = (size / 1024).toFixed(2) + " G";