mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-12 23:00:25 +08:00
看板增加离线节点数字
This commit is contained in:
@@ -211,6 +211,24 @@ func (this *APINodeDAO) CountAllEnabledAPINodes(tx *dbs.Tx) (int64, error) {
|
||||
Count()
|
||||
}
|
||||
|
||||
// CountAllEnabledAndOnAPINodes 计算启用中的API节点数量
|
||||
func (this *APINodeDAO) CountAllEnabledAndOnAPINodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(APINodeStateEnabled).
|
||||
Attr("isOn", true).
|
||||
Count()
|
||||
}
|
||||
|
||||
|
||||
// CountAllEnabledAndOnOfflineAPINodes 计算API节点数量
|
||||
func (this *APINodeDAO) CountAllEnabledAndOnOfflineAPINodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(APINodeStateEnabled).
|
||||
Attr("isOn", true).
|
||||
Where("(status IS NULL OR NOT JSON_EXTRACT(status, '$.isActive') OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>60)").
|
||||
Count()
|
||||
}
|
||||
|
||||
// ListEnabledAPINodes 列出单页的API节点
|
||||
func (this *APINodeDAO) ListEnabledAPINodes(tx *dbs.Tx, offset int64, size int64) (result []*APINode, err error) {
|
||||
_, err = this.Query(tx).
|
||||
|
||||
@@ -259,6 +259,16 @@ func (this *NodeDAO) CountAllEnabledNodes(tx *dbs.Tx) (int64, error) {
|
||||
Count()
|
||||
}
|
||||
|
||||
// CountAllEnabledOfflineNodes 计算所有离线节点数量
|
||||
func (this *NodeDAO) CountAllEnabledOfflineNodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(NodeStateEnabled).
|
||||
Where("clusterId IN (SELECT id FROM "+SharedNodeClusterDAO.Table+" WHERE state=:clusterState)").
|
||||
Param("clusterState", NodeClusterStateEnabled).
|
||||
Where("(status IS NULL OR NOT JSON_EXTRACT(status, '$.isActive') OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>60)").
|
||||
Count()
|
||||
}
|
||||
|
||||
// ListEnabledNodesMatch 列出单页节点
|
||||
func (this *NodeDAO) ListEnabledNodesMatch(tx *dbs.Tx,
|
||||
clusterId int64,
|
||||
@@ -493,9 +503,9 @@ func (this *NodeDAO) FindAllInactiveNodesWithClusterId(tx *dbs.Tx, clusterId int
|
||||
_, err = this.Query(tx).
|
||||
State(NodeStateEnabled).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("isOn", true). // 只监控启用的节点
|
||||
Attr("isOn", true). // 只监控启用的节点
|
||||
Attr("isInstalled", true). // 只监控已经安装的节点
|
||||
Attr("isActive", true). // 当前已经在线的
|
||||
Attr("isActive", true). // 当前已经在线的
|
||||
Where("(status IS NULL OR (JSON_EXTRACT(status, '$.isActive')=false AND UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>10) OR UNIX_TIMESTAMP()-JSON_EXTRACT(status, '$.updatedAt')>120)").
|
||||
Result("id", "name").
|
||||
Slice(&result).
|
||||
|
||||
@@ -96,6 +96,14 @@ func (this *UserNodeDAO) CountAllEnabledUserNodes(tx *dbs.Tx) (int64, error) {
|
||||
Count()
|
||||
}
|
||||
|
||||
// CountAllEnabledAndOnUserNodes 计算启用的用户节点数量
|
||||
func (this *UserNodeDAO) CountAllEnabledAndOnUserNodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(UserNodeStateEnabled).
|
||||
Attr("isOn", true).
|
||||
Count()
|
||||
}
|
||||
|
||||
// ListEnabledUserNodes 列出单页的用户节点
|
||||
func (this *UserNodeDAO) ListEnabledUserNodes(tx *dbs.Tx, offset int64, size int64) (result []*UserNode, err error) {
|
||||
_, err = this.Query(tx).
|
||||
@@ -266,10 +274,11 @@ func (this *UserNodeDAO) CountAllLowerVersionNodes(tx *dbs.Tx, version string) (
|
||||
Count()
|
||||
}
|
||||
|
||||
// CountOfflineNodes 计算离线节点数量
|
||||
func (this *UserNodeDAO) CountOfflineNodes(tx *dbs.Tx) (int64, error) {
|
||||
// CountAllEnabledAndOnOfflineNodes 计算离线节点数量
|
||||
func (this *UserNodeDAO) CountAllEnabledAndOnOfflineNodes(tx *dbs.Tx) (int64, error) {
|
||||
return this.Query(tx).
|
||||
State(UserNodeStateEnabled).
|
||||
Where("(status IS NULL OR JSON_EXTRACT(status, '$.updatedAt')<UNIX_TIMESTAMP()-120)").
|
||||
Attr("isOn", true).
|
||||
Where("(status IS NULL OR JSON_EXTRACT(status, '$.updatedAt')<UNIX_TIMESTAMP()-60)").
|
||||
Count()
|
||||
}
|
||||
|
||||
@@ -497,6 +497,13 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com
|
||||
}
|
||||
result.CountNodes = countNodes
|
||||
|
||||
// 离线节点
|
||||
countOfflineNodes, err := models.SharedNodeDAO.CountAllEnabledOfflineNodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.CountOfflineNodes = countOfflineNodes
|
||||
|
||||
// 服务数
|
||||
countServers, err := models.SharedServerDAO.CountAllEnabledServers(tx)
|
||||
if err != nil {
|
||||
@@ -512,12 +519,19 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com
|
||||
result.CountUsers = countUsers
|
||||
|
||||
// API节点数
|
||||
countAPINodes, err := models.SharedAPINodeDAO.CountAllEnabledAPINodes(tx)
|
||||
countAPINodes, err := models.SharedAPINodeDAO.CountAllEnabledAndOnAPINodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.CountAPINodes = countAPINodes
|
||||
|
||||
// 离线API节点
|
||||
countOfflineAPINodes, err := models.SharedAPINodeDAO.CountAllEnabledAndOnOfflineAPINodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.CountOfflineAPINodes = countOfflineAPINodes
|
||||
|
||||
// 数据库节点数
|
||||
countDBNodes, err := models.SharedDBNodeDAO.CountAllEnabledNodes(tx)
|
||||
if err != nil {
|
||||
@@ -526,12 +540,19 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com
|
||||
result.CountDBNodes = countDBNodes
|
||||
|
||||
// 用户节点数
|
||||
countUserNodes, err := models.SharedUserNodeDAO.CountAllEnabledUserNodes(tx)
|
||||
countUserNodes, err := models.SharedUserNodeDAO.CountAllEnabledAndOnUserNodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.CountUserNodes = countUserNodes
|
||||
|
||||
// 离线用户节点数
|
||||
countOfflineUserNodes, err := models.SharedUserNodeDAO.CountAllEnabledAndOnOfflineNodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.CountOfflineUserNodes = countOfflineUserNodes
|
||||
|
||||
// 按日流量统计
|
||||
dayFrom := timeutil.Format("Ymd", time.Now().AddDate(0, 0, -14))
|
||||
dailyTrafficStats, err := stats.SharedTrafficDailyStatDAO.FindDailyStats(tx, dayFrom, timeutil.Format("Ymd"))
|
||||
|
||||
@@ -496,7 +496,7 @@ func (this *UserService) ComposeUserGlobalBoard(ctx context.Context, req *pb.Com
|
||||
result.CountUserNodes = countUserNodes
|
||||
|
||||
// 离线用户节点
|
||||
countOfflineUserNodes, err := models.SharedUserNodeDAO.CountOfflineNodes(tx)
|
||||
countOfflineUserNodes, err := models.SharedUserNodeDAO.CountAllEnabledAndOnOfflineNodes(tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user