mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-09 00:20:26 +08:00
增加连接数监控图表
This commit is contained in:
@@ -44,6 +44,7 @@ func init() {
|
||||
Post("/node/monitor/load", new(monitor.LoadAction)).
|
||||
Post("/node/monitor/trafficIn", new(monitor.TrafficInAction)).
|
||||
Post("/node/monitor/trafficOut", new(monitor.TrafficOutAction)).
|
||||
Post("/node/monitor/connections", new(monitor.ConnectionsAction)).
|
||||
|
||||
// 分组相关
|
||||
Get("/groups", new(groups.IndexAction)).
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ConnectionsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ConnectionsAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemConnections,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]int64{} // YmdHi => count
|
||||
for _, v := range resp.NodeValues {
|
||||
if len(v.ValueJSON) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
valueMap := maps.Map{}
|
||||
err = json.Unmarshal(v.ValueJSON, &valueMap)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
valuesMap[timeutil.FormatTime("YmdHi", v.CreatedAt)] = valueMap.GetInt64("total")
|
||||
}
|
||||
|
||||
// 过去一个小时
|
||||
result := []maps.Map{}
|
||||
for i := 60; i >= 1; i-- {
|
||||
timestamp := time.Now().Unix() - int64(i)*60
|
||||
minute := timeutil.FormatTime("YmdHi", timestamp)
|
||||
total, ok := valuesMap[minute]
|
||||
if ok {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": total,
|
||||
"text": numberutils.FormatInt64(total),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": "0",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -12,6 +12,9 @@
|
||||
<h4>下行流量</h4>
|
||||
<div class="chart-box" id="traffic-out-chart"></div>
|
||||
|
||||
<h4>连接数</h4>
|
||||
<div class="chart-box" id="connections-chart"></div>
|
||||
|
||||
<h4>CPU</h4>
|
||||
<div class="chart-box" id="cpu-chart"></div>
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ Tea.context(function () {
|
||||
this.$delay(function () {
|
||||
this.loadTrafficInChart()
|
||||
this.loadTrafficOutChart()
|
||||
this.loadConnectionsChart()
|
||||
this.loadCPUChart()
|
||||
this.loadMemoryChart()
|
||||
this.loadLoadChart()
|
||||
@@ -10,6 +11,7 @@ Tea.context(function () {
|
||||
window.addEventListener("resize", function () {
|
||||
that.resizeChart("traffic-in-chart")
|
||||
that.resizeChart("traffic-out-chart")
|
||||
that.resizeChart("connections-chart")
|
||||
that.resizeChart("cpu-chart")
|
||||
that.resizeChart("memory-chart")
|
||||
that.resizeChart("load-chart")
|
||||
@@ -84,6 +86,40 @@ Tea.context(function () {
|
||||
})
|
||||
}
|
||||
|
||||
this.loadConnectionsChart = function () {
|
||||
this.$post(".connections")
|
||||
.params({
|
||||
nodeId: this.nodeId
|
||||
})
|
||||
.success(function (resp) {
|
||||
let values = resp.data.values
|
||||
let maxFunc = function () {
|
||||
let max = values.map(function (v) {
|
||||
return v.value
|
||||
}).$max()
|
||||
if (max < 10) {
|
||||
return 10
|
||||
}
|
||||
if (max < 100) {
|
||||
return 100
|
||||
}
|
||||
if (max < 1000) {
|
||||
return 1000
|
||||
}
|
||||
return null
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value
|
||||
}
|
||||
this.reloadChart("connections-chart", "", values, "", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadConnectionsChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
this.loadCPUChart = function () {
|
||||
this.$post(".cpu")
|
||||
.params({
|
||||
|
||||
Reference in New Issue
Block a user