Merge pull request #9782 from zhaoxiangchun/feature/zxc-alerthistory-overview-master

fix(monitor,suggestion): order commonalert metric and modify alertresoruce type value and add suggestion models climc
This commit is contained in:
Zexi Li
2021-01-07 21:14:24 +08:00
committed by GitHub
7 changed files with 44 additions and 9 deletions
@@ -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))
}
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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,
@@ -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"},
@@ -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
}
+3 -3
View File
@@ -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
+9 -2
View File
@@ -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
}