mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #12341 from zhaoxiangchun/feature/zxc-monitor_sheild_master
fix(monitor): update usage query param and alert record query support tigger_time
This commit is contained in:
@@ -179,11 +179,13 @@ type resourceUsage struct {
|
||||
|
||||
func getDomainAndProjectServerUsage(session *mcclient.ClientSession, nowTime time.Time) ([]influxdb.SMetricData, error) {
|
||||
metrics := make([]influxdb.SMetricData, 0)
|
||||
param := jsonutils.NewDict()
|
||||
param.Set("scope", jsonutils.NewString("system"))
|
||||
for urlKey, tag := range map[string]string{
|
||||
"domain-statistics": "domain_id.project_domain",
|
||||
"project-statistics": "tenant_id.tenant",
|
||||
} {
|
||||
jsonObject, err := modules.Servers.GetById(session, urlKey, jsonutils.NewDict())
|
||||
jsonObject, err := modules.Servers.GetById(session, urlKey, param)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "get server-%s err", urlKey)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/filterclause"
|
||||
"yunion.io/x/pkg/util/timeutils"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -129,6 +130,15 @@ func (manager *SAlertRecordManager) ListItemFilter(
|
||||
if len(query.ResType) != 0 {
|
||||
q.Filter(sqlchemy.Equals(q.Field("res_type"), query.ResType))
|
||||
}
|
||||
if len(query.Filter) != 0 {
|
||||
for i, _ := range query.Filter {
|
||||
if strings.Contains(query.Filter[i], "trigger_time") {
|
||||
timeFilter := strings.ReplaceAll(query.Filter[i], "trigger_time", "created_at")
|
||||
filterClause := filterclause.ParseFilterClause(timeFilter)
|
||||
q.Filter(filterClause.QueryCondition(q))
|
||||
}
|
||||
}
|
||||
}
|
||||
return q, nil
|
||||
}
|
||||
|
||||
@@ -234,7 +244,9 @@ func (record *SAlertRecord) GetMoreDetails(out monitor.AlertRecordDetails) (moni
|
||||
out.ResNum = int64(len(evalMatchs))
|
||||
}
|
||||
commonAlert, _ := CommonAlertManager.GetAlert(record.AlertId)
|
||||
out.AlertName = commonAlert.GetName()
|
||||
if commonAlert != nil {
|
||||
out.AlertName = commonAlert.GetName()
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user