diff --git a/cmd/climc/shell/suggestion/suggestsysalert.go b/cmd/climc/shell/suggestion/suggestsysalert.go index 17c0f9f38f..c156e87ea7 100644 --- a/cmd/climc/shell/suggestion/suggestsysalert.go +++ b/cmd/climc/shell/suggestion/suggestsysalert.go @@ -25,4 +25,6 @@ func init() { cmd.List(new(options.SuggestSysAlertListOptions)) cmd.Show(new(options.SSuggestAlertShowOptions)) cmd.Perform("ignore", new(options.SuggestAlertIgnoreOptions)) + cmd_ := shell.NewResourceCmd(monitor.SuggestSysAlertCostManager) + cmd_.Get("", new(options.SuggestAlertCostOptions)) } diff --git a/pkg/apis/monitor/alertresource.go b/pkg/apis/monitor/alertresource.go index 42d7a5e3cd..fc10ae74b5 100644 --- a/pkg/apis/monitor/alertresource.go +++ b/pkg/apis/monitor/alertresource.go @@ -22,7 +22,7 @@ type AlertResourceType string const ( // AlertResourceTypeNode means onecloud system infrastructure controller or host node - AlertResourceTypeNode AlertResourceType = "node" + AlertResourceTypeNode AlertResourceType = "host" // AlertResourceTypeCloudaccount means cloudaccount resource AlertResourceTypeCloudaccount AlertResourceType = "cloudaccount" // AlertResourceTypeVM means virtual machine guest resource diff --git a/pkg/apis/monitor/metric.go b/pkg/apis/monitor/metric.go index 10b81f1f70..c6de9f5583 100644 --- a/pkg/apis/monitor/metric.go +++ b/pkg/apis/monitor/metric.go @@ -30,8 +30,8 @@ var ( MetricUnit = []string{METRIC_UNIT_PERCENT, METRIC_UNIT_BPS, METRIC_UNIT_MBPS, METRIC_UNIT_BYTEPS, "count/s", METRIC_UNIT_COUNT, METRIC_UNIT_MS, METRIC_UNIT_BYTE, METRIC_UNIT_RMB} ResTypeScoreMap = map[string]int{ - METRIC_RES_TYPE_HOST: 1, - METRIC_RES_TYPE_GUEST: 2, + METRIC_RES_TYPE_GUEST: 1, + METRIC_RES_TYPE_HOST: 2, METRIC_RES_TYPE_OSS: 3, METRIC_RES_TYPE_RDS: 4, METRIC_RES_TYPE_REDIS: 5, diff --git a/pkg/mcclient/modules/monitor/suggestsysrule.go b/pkg/mcclient/modules/monitor/suggestsysrule.go index d26a2a7f78..cf2978d2c5 100644 --- a/pkg/mcclient/modules/monitor/suggestsysrule.go +++ b/pkg/mcclient/modules/monitor/suggestsysrule.go @@ -24,6 +24,7 @@ var ( SuggestSysAlertManager *SSuggestSysAlertManager SuggestSysRuleConfigManager *SSuggestSysRuleConfigManager InfluxdbShemaManager *SInfluxdbShemaManager + SuggestSysAlertCostManager *SSuggestSysAlertManager ) func init() { @@ -31,6 +32,7 @@ func init() { SuggestSysAlertManager = NewSuggestSysAlertManager() SuggestSysRuleConfigManager = NewSuggestSysRuleConfigManager() InfluxdbShemaManager = NewInfluxdbShemaManager() + SuggestSysAlertCostManager = NewSuggestSysAlertCostManager() for _, m := range []modulebase.IBaseManager{ SuggestSysRuleManager, SuggestSysAlertManager, @@ -75,6 +77,15 @@ func NewSuggestSysAlertManager() *SSuggestSysAlertManager { } } +func NewSuggestSysAlertCostManager() *SSuggestSysAlertManager { + man := modules.NewSuggestionManager("suggestsysalert", "suggestsysalerts", + []string{}, + []string{}) + return &SSuggestSysAlertManager{ + ResourceManager: &man, + } +} + func NewSuggestSysRuleConfigManager() *SSuggestSysRuleConfigManager { man := modules.NewSuggestionManager("suggestsysruleconfig", "suggestsysruleconfigs", []string{"id", "name", "type", "resource_type", "enabled", "ignore_alert"}, diff --git a/pkg/mcclient/options/monitor/suggestsysalert.go b/pkg/mcclient/options/monitor/suggestsysalert.go index 9eeb7a8cbf..60cbda1ddd 100644 --- a/pkg/mcclient/options/monitor/suggestsysalert.go +++ b/pkg/mcclient/options/monitor/suggestsysalert.go @@ -22,7 +22,8 @@ import ( type SuggestSysAlertListOptions struct { options.BaseListOptions - Type string `help:"Type of suggest rule" choices:"EIP_UNUSED|"` + Type string `help:"Type of suggest rule"` + Currency string `json:"currency"` } func (o *SuggestSysAlertListOptions) Params() (jsonutils.JSONObject, error) { @@ -55,3 +56,17 @@ func (opt *SuggestAlertIgnoreOptions) Params() (jsonutils.JSONObject, error) { func (o *SuggestAlertIgnoreOptions) GetId() string { return o.ID } + +type SuggestAlertCostOptions struct { + ID string `help:"ID or name of the alert" json:"-"` + options.BaseListOptions + Currency string `json:"currency"` +} + +func (o *SuggestAlertCostOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(o) +} + +func (o *SuggestAlertCostOptions) GetId() string { + return o.ID +} diff --git a/pkg/monitor/dbinit/metric_dbinit.go b/pkg/monitor/dbinit/metric_dbinit.go index 87526e47ee..9c4687dbf8 100644 --- a/pkg/monitor/dbinit/metric_dbinit.go +++ b/pkg/monitor/dbinit/metric_dbinit.go @@ -101,18 +101,18 @@ func init() { // mem RegistryMetricCreateInput("mem", "Memory", monitor.METRIC_RES_TYPE_HOST, - monitor.METRIC_DATABASE_TELE, 3, []monitor.MetricFieldCreateInput{ + monitor.METRIC_DATABASE_TELE, 2, []monitor.MetricFieldCreateInput{ newMetricFieldCreateInput("used_percent", "Used memory rate", monitor.METRIC_UNIT_PERCENT, 1), newMetricFieldCreateInput("available_percent", "Available memory rate", monitor.METRIC_UNIT_PERCENT, 2), newMetricFieldCreateInput("used", "Used memory", monitor.METRIC_UNIT_BYTE, 3), newMetricFieldCreateInput("free", "Free memory", monitor.METRIC_UNIT_BYTE, 4), - newMetricFieldCreateInput("available", "Available memory", monitor.METRIC_UNIT_BYTE, 4), newMetricFieldCreateInput("active", "The amount of active memory", monitor.METRIC_UNIT_BYTE, 5), newMetricFieldCreateInput("inactive", "The amount of inactive memory", monitor.METRIC_UNIT_BYTE, 6), newMetricFieldCreateInput("cached", "Cache memory", monitor.METRIC_UNIT_BYTE, 7), newMetricFieldCreateInput("buffered", "Buffer memory", monitor.METRIC_UNIT_BYTE, 7), newMetricFieldCreateInput("slab", "Number of kernel caches", monitor.METRIC_UNIT_BYTE, 8), - newMetricFieldCreateInput("total", "Total memory", monitor.METRIC_UNIT_BYTE, 9), + newMetricFieldCreateInput("available", "Available memory", monitor.METRIC_UNIT_BYTE, 9), + newMetricFieldCreateInput("total", "Total memory", monitor.METRIC_UNIT_BYTE, 10), }) // net diff --git a/pkg/monitor/models/alertresource.go b/pkg/monitor/models/alertresource.go index 286037527c..8bf741e0e8 100644 --- a/pkg/monitor/models/alertresource.go +++ b/pkg/monitor/models/alertresource.go @@ -226,7 +226,7 @@ func (m *SAlertResourceManager) createOrUpdateFromRecord( if res == nil { return m.createFromRecord(ctx, userCred, ownerId, drv, record, match) } else { - return res.updateFromRecord(ctx, userCred, record, match) + return res.updateFromRecord(ctx, userCred, drv, record, match) } } @@ -297,7 +297,8 @@ func (res *SAlertResource) getAttachedAlerts() ([]SCommonAlert, error) { return alerts, nil } -func (res *SAlertResource) updateFromRecord(ctx context.Context, userCred mcclient.TokenCredential, record *SAlertRecord, match monitor.EvalMatch) error { +func (res *SAlertResource) updateFromRecord(ctx context.Context, userCred mcclient.TokenCredential, + drv IAlertResourceDriver, record *SAlertRecord, match monitor.EvalMatch) error { jObj, err := res.GetJointAlert(record.AlertId) if err != nil { return errors.Wrapf(err, "get joint alert by id %s", record.AlertId) @@ -310,6 +311,12 @@ func (res *SAlertResource) updateFromRecord(ctx context.Context, userCred mcclie if err := jObj.UpdateData(record, &match); err != nil { return errors.Wrapf(err, "update joint object by matches %v", match) } + if _, err := db.Update(res, func() error { + res.Type = string(drv.GetType()) + return nil + }); err != nil { + return err + } } return nil }