Skip to content

Commit

Permalink
Merge branch 'v2.2' into v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jc3wish committed Oct 14, 2023
2 parents 3d1163b + d632cb0 commit 412df9b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 10 deletions.
57 changes: 53 additions & 4 deletions admin/controller/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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 基本信息
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions admin/view/template/db.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ <h5 id="opContairTitle">Add new DB</h5>
$("#uri").change(
function(){
dbUriChecked = false;
// 去除前后换行符
var uri = $(this).val()
uri = uri.replace(/^\n+|\n+$/g, '');
$(this).val(uri);
$("#checkUriBtn").show();
}
);
Expand Down
11 changes: 8 additions & 3 deletions admin/view/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1 class="no-margins">0</h1>

<div class="col-md-12" id="bifrost_memory_used">
<h1 class="no-margins"><span class="number">0</span>
<button data-toggle="button" class="btn-sm btn-primary" type="button" id="freeOSMemory">释放</button>
<button data-toggle="button" class="btn-sm btn-primary" type="button" id="freeOSMemory">GC</button>
</h1>
<div class="font-bold text-navy"><span class="proportion"></span> <i class="fa fa-level-up"></i> <small class="notes">Bifrost Used</small>
</div>
Expand Down Expand Up @@ -336,7 +336,7 @@ <h5><a href="http://www.xbifrost.com" target="_blank">Bifrost动态</a></h5>
$("#freeOSMemory").click(
function() {
var callback = function (data) {
alert("释放成功!");
alert("提交成功!");
return true;
};
Ajax("GET","/freeOSMemory",{},callback,true);
Expand All @@ -361,7 +361,12 @@ <h5><a href="http://www.xbifrost.com" target="_blank">Bifrost动态</a></h5>

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";
Expand Down
6 changes: 6 additions & 0 deletions admin/view/template/toserver.list.html
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ <h5>Add new Server</h5>
$("#ConnUri").change(
function(){
uriChecked = false;
// 去除前后换行符
var uri = $(this).val()
uri = uri.replace(/^\n+|\n+$/g, '');
$(this).val(uri);
$("#checkUriBtn").show();
}
);
Expand Down Expand Up @@ -377,6 +381,8 @@ <h5>Add new Server</h5>
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) ){
Expand Down
4 changes: 2 additions & 2 deletions input/mock/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -115,7 +115,7 @@ func (c *InputMock) TableTaskWait() {
c.Unlock()
}()
c.ws.Wait()
c.setStatus(inputDriver.CLOSED)
c.Close()
}

func (c *InputMock) StartNormalTables() {
Expand Down
5 changes: 4 additions & 1 deletion input/mock/performance_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -61,7 +64,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 {
Expand Down
1 change: 1 addition & 0 deletions input/mock/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 412df9b

Please sign in to comment.