mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
取消节点的监控图表,使用节点看板代替
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/groups"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node"
|
||||
nodeboards "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/boards"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/monitor"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/thresholds"
|
||||
clusters "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
@@ -43,13 +42,6 @@ func init() {
|
||||
Post("/start", new(node.StartAction)).
|
||||
Post("/stop", new(node.StopAction)).
|
||||
Post("/up", new(node.UpAction)).
|
||||
Get("/monitor", new(monitor.IndexAction)).
|
||||
Post("/monitor/cpu", new(monitor.CpuAction)).
|
||||
Post("/monitor/memory", new(monitor.MemoryAction)).
|
||||
Post("/monitor/load", new(monitor.LoadAction)).
|
||||
Post("/monitor/trafficIn", new(monitor.TrafficInAction)).
|
||||
Post("/monitor/trafficOut", new(monitor.TrafficOutAction)).
|
||||
Post("/monitor/connections", new(monitor.ConnectionsAction)).
|
||||
Get("/thresholds", new(thresholds.IndexAction)).
|
||||
Get("/detail", new(node.DetailAction)).
|
||||
Get("/boards", new(nodeboards.IndexAction)).
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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()
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"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 CpuAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CpuAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemCPU,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]float32{} // YmdHi => usage
|
||||
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.GetFloat32("usage") * 100
|
||||
}
|
||||
|
||||
// 过去一个小时
|
||||
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": fmt.Sprintf("%.2f%%", total),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": "0.0%",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/nodeutils"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "node", "monitor")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
this.Data["nodeId"] = params.NodeId
|
||||
|
||||
// 初始化节点信息(用于菜单)
|
||||
err := nodeutils.InitNodeInfo(this, params.NodeId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"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 LoadAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *LoadAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemLoad,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]float32{} // YmdHi => load5m
|
||||
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.GetFloat32("load5m")
|
||||
}
|
||||
|
||||
// 过去一个小时
|
||||
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": fmt.Sprintf("5分钟: %.2f", total),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": "5分钟: 0.0",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"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 MemoryAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *MemoryAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemMemory,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]float32{} // YmdHi => usage
|
||||
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.GetFloat32("usage") * 100
|
||||
}
|
||||
|
||||
// 过去一个小时
|
||||
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": fmt.Sprintf("%.2f%%", total),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": "0.0%",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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 TrafficInAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TrafficInAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemTrafficIn,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]int64{} // YmdHi => bytes
|
||||
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 / 60,
|
||||
"text": numberutils.FormatBytes(total / 60),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": numberutils.FormatBytes(0),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
// 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 TrafficOutAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *TrafficOutAction) RunPost(params struct {
|
||||
NodeId int64
|
||||
}) {
|
||||
resp, err := this.RPC().NodeValueRPC().ListNodeValues(this.AdminContext(), &pb.ListNodeValuesRequest{
|
||||
Role: "node",
|
||||
NodeId: params.NodeId,
|
||||
Item: nodeconfigs.NodeValueItemTrafficOut,
|
||||
Range: nodeconfigs.NodeValueRangeMinute,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
valuesMap := map[string]int64{} // YmdHi => bytes
|
||||
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 / 60,
|
||||
"text": numberutils.FormatBytes(total / 60),
|
||||
})
|
||||
} else {
|
||||
result = append(result, maps.Map{
|
||||
"label": timeutil.FormatTime("H:i", timestamp),
|
||||
"value": 0,
|
||||
"text": numberutils.FormatBytes(0),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["values"] = result
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
.chart-box {
|
||||
height: 20em;
|
||||
}
|
||||
/*# sourceMappingURL=index.css.map */
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"sources":["index.less"],"names":[],"mappings":"AAAA;EACC,YAAA","file":"index.css"}
|
||||
@@ -1,21 +0,0 @@
|
||||
{$layout}
|
||||
{$template "../node_menu"}
|
||||
{$template "/echarts"}
|
||||
|
||||
<h4>上行流量(字节)</h4>
|
||||
<div class="chart-box" id="traffic-in-chart"></div>
|
||||
|
||||
<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>
|
||||
|
||||
<h4>内存</h4>
|
||||
<div class="chart-box" id="memory-chart"></div>
|
||||
|
||||
<h4>负载</h4>
|
||||
<div class="chart-box" id="load-chart"></div>
|
||||
@@ -1,253 +0,0 @@
|
||||
Tea.context(function () {
|
||||
this.$delay(function () {
|
||||
this.loadTrafficInChart()
|
||||
this.loadTrafficOutChart()
|
||||
this.loadConnectionsChart()
|
||||
this.loadCPUChart()
|
||||
this.loadMemoryChart()
|
||||
this.loadLoadChart()
|
||||
|
||||
let that = this
|
||||
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")
|
||||
})
|
||||
})
|
||||
|
||||
this.loadTrafficInChart = function () {
|
||||
this.$post(".trafficIn")
|
||||
.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() / 1024 / 1024
|
||||
if (max < 1) {
|
||||
return 1
|
||||
}
|
||||
if (max < 10) {
|
||||
return 10
|
||||
}
|
||||
if (max < 100) {
|
||||
return 100
|
||||
}
|
||||
return null
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value / 1024 / 1024
|
||||
}
|
||||
this.reloadChart("traffic-in-chart", "", values, "M", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadTrafficInChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
this.loadTrafficOutChart = function () {
|
||||
this.$post(".trafficOut")
|
||||
.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() / 1024 / 1024
|
||||
if (max < 1) {
|
||||
return 1
|
||||
}
|
||||
if (max < 10) {
|
||||
return 10
|
||||
}
|
||||
if (max < 100) {
|
||||
return 100
|
||||
}
|
||||
return null
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value / 1024 / 1024
|
||||
}
|
||||
this.reloadChart("traffic-out-chart", "", values, "M", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadTrafficOutChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
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({
|
||||
nodeId: this.nodeId
|
||||
})
|
||||
.success(function (resp) {
|
||||
let values = resp.data.values
|
||||
let maxFunc = function () {
|
||||
return 100
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value
|
||||
}
|
||||
this.reloadChart("cpu-chart", "", values, "%", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadCPUChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
this.loadMemoryChart = function () {
|
||||
this.$post(".memory")
|
||||
.params({
|
||||
nodeId: this.nodeId
|
||||
})
|
||||
.success(function (resp) {
|
||||
let values = resp.data.values
|
||||
let maxFunc = function () {
|
||||
return 100
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value
|
||||
}
|
||||
this.reloadChart("memory-chart", "", values, "%", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadMemoryChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
this.loadLoadChart = function () {
|
||||
this.$post(".load")
|
||||
.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
|
||||
}
|
||||
return null
|
||||
}
|
||||
let valueFunc = function (v) {
|
||||
return v.value
|
||||
}
|
||||
this.reloadChart("load-chart", "5分钟", values, "", maxFunc, valueFunc)
|
||||
})
|
||||
.done(function () {
|
||||
this.$delay(function () {
|
||||
this.loadLoadChart()
|
||||
}, 30000)
|
||||
})
|
||||
}
|
||||
|
||||
this.reloadChart = function (chartId, name, stats, unit, maxFunc, valueFunc) {
|
||||
let chartBox = document.getElementById(chartId)
|
||||
if (chartBox == null) {
|
||||
return
|
||||
}
|
||||
let chart = echarts.init(chartBox)
|
||||
let option = {
|
||||
xAxis: {
|
||||
data: stats.map(function (stat) {
|
||||
return stat.label
|
||||
})
|
||||
},
|
||||
yAxis: {
|
||||
max: maxFunc(),
|
||||
axisLabel: {
|
||||
formatter: function (value) {
|
||||
return value + unit
|
||||
}
|
||||
}
|
||||
},
|
||||
tooltip: {
|
||||
show: true,
|
||||
trigger: "item",
|
||||
formatter: function (args) {
|
||||
return stats[args.dataIndex].label + ": " + stats[args.dataIndex].text
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: 50,
|
||||
top: 10,
|
||||
right: 20,
|
||||
bottom: 20
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: name,
|
||||
type: "line",
|
||||
data: stats.map(valueFunc),
|
||||
itemStyle: {
|
||||
color: "#9DD3E8"
|
||||
},
|
||||
areaStyle: {}
|
||||
}
|
||||
],
|
||||
animation: true
|
||||
}
|
||||
chart.setOption(option)
|
||||
chart.resize()
|
||||
}
|
||||
|
||||
this.resizeChart = function (chartId) {
|
||||
let chartBox = document.getElementById(chartId)
|
||||
if (chartBox == null) {
|
||||
return
|
||||
}
|
||||
let chart = echarts.init(chartBox)
|
||||
chart.resize()
|
||||
}
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
.chart-box {
|
||||
height: 20em;
|
||||
}
|
||||
Reference in New Issue
Block a user