优化节点列表

This commit is contained in:
GoEdgeLab
2022-04-07 18:31:38 +08:00
parent 63d070f7e0
commit cc1e806cee
7 changed files with 329 additions and 33 deletions

View File

@@ -6,6 +6,7 @@ import (
_ "github.com/go-sql-driver/mysql"
_ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
@@ -52,3 +53,29 @@ func TestNodeValueDAO_CreateManyValues(t *testing.T) {
}
t.Log("finished")
}
func TestNodeValueDAO_SumAllNodeValues(t *testing.T) {
var dao = models.NewNodeValueDAO()
sum, avg, max, err := dao.SumAllNodeValues(nil, nodeconfigs.NodeRoleNode, nodeconfigs.NodeValueItemCPU, "usage", 1, nodeconfigs.NodeValueDurationUnitMinute)
if err != nil {
t.Fatal(err)
}
t.Log("sum:", sum, "avg:", avg, "max:", max)
}
func TestNodeValueDAO_ComposeNodeStatus(t *testing.T) {
var dao = models.NewNodeValueDAO()
one, err := dao.Query(nil).DescPk().Find()
if err != nil {
t.Fatal(err)
}
if one != nil {
var config = &nodeconfigs.NodeStatus{}
err = dao.ComposeNodeStatus(nil, one.(*models.NodeValue).Role, int64(one.(*models.NodeValue).NodeId), config)
if err != nil {
t.Fatal(err)
}
logs.PrintAsJSON(config, t)
}
}