mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-09 19:50:30 +08:00
IP阈值增加节点分组和集群相关统计项目
This commit is contained in:
@@ -173,8 +173,8 @@ func (this *NodeValueDAO) ListValuesForNSNodes(tx *dbs.Tx, item string, key stri
|
||||
return
|
||||
}
|
||||
|
||||
// SumValues 计算某项参数值
|
||||
func (this *NodeValueDAO) SumValues(tx *dbs.Tx, role string, nodeId int64, item string, param string, method nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit) (float64, error) {
|
||||
// SumNodeValues 计算节点的某项参数值
|
||||
func (this *NodeValueDAO) SumNodeValues(tx *dbs.Tx, role string, nodeId int64, item string, param string, method nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit) (float64, error) {
|
||||
if duration <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -202,6 +202,65 @@ func (this *NodeValueDAO) SumValues(tx *dbs.Tx, role string, nodeId int64, item
|
||||
return query.FindFloat64Col(0)
|
||||
}
|
||||
|
||||
// SumNodeGroupValues 计算节点分组的某项参数值
|
||||
func (this *NodeValueDAO) SumNodeGroupValues(tx *dbs.Tx, role string, groupId int64, item string, param string, method nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit) (float64, error) {
|
||||
if duration <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
query := this.Query(tx).
|
||||
Attr("role", role).
|
||||
Where("nodeId IN (SELECT id FROM "+SharedNodeDAO.Table+" WHERE groupId=:groupId AND state=1)").
|
||||
Param("groupId", groupId).
|
||||
Attr("item", item)
|
||||
switch method {
|
||||
case nodeconfigs.NodeValueSumMethodAvg:
|
||||
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
case nodeconfigs.NodeValueSumMethodSum:
|
||||
query.Result("SUM(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
default:
|
||||
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
}
|
||||
switch durationUnit {
|
||||
case nodeconfigs.NodeValueDurationUnitMinute:
|
||||
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration*60))
|
||||
query.Gte("minute", fromMinute)
|
||||
default:
|
||||
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration*60))
|
||||
query.Gte("minute", fromMinute)
|
||||
}
|
||||
return query.FindFloat64Col(0)
|
||||
}
|
||||
|
||||
// SumNodeClusterValues 计算节点集群的某项参数值
|
||||
func (this *NodeValueDAO) SumNodeClusterValues(tx *dbs.Tx, role string, clusterId int64, item string, param string, method nodeconfigs.NodeValueSumMethod, duration int32, durationUnit nodeconfigs.NodeValueDurationUnit) (float64, error) {
|
||||
if duration <= 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
query := this.Query(tx).
|
||||
Attr("role", role).
|
||||
Attr("clusterId", clusterId).
|
||||
Attr("item", item)
|
||||
switch method {
|
||||
case nodeconfigs.NodeValueSumMethodAvg:
|
||||
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
case nodeconfigs.NodeValueSumMethodSum:
|
||||
query.Result("SUM(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
default:
|
||||
query.Result("AVG(JSON_EXTRACT(value, '$." + param + "'))")
|
||||
}
|
||||
switch durationUnit {
|
||||
case nodeconfigs.NodeValueDurationUnitMinute:
|
||||
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration*60))
|
||||
query.Gte("minute", fromMinute)
|
||||
default:
|
||||
fromMinute := timeutil.FormatTime("YmdHi", time.Now().Unix()-int64(duration*60))
|
||||
query.Gte("minute", fromMinute)
|
||||
}
|
||||
return query.FindFloat64Col(0)
|
||||
}
|
||||
|
||||
// FindLatestNodeValue 获取最近一条数据
|
||||
func (this *NodeValueDAO) FindLatestNodeValue(tx *dbs.Tx, role string, nodeId int64, item string) (*NodeValue, error) {
|
||||
one, err := this.Query(tx).
|
||||
|
||||
Reference in New Issue
Block a user