指标图表可以设置忽略空值和其他对象值

This commit is contained in:
GoEdgeLab
2021-07-26 16:44:29 +08:00
parent 7c9afcd130
commit 844ece8e95
7 changed files with 224 additions and 75 deletions

View File

@@ -74,7 +74,7 @@ func (this *MetricChartDAO) FindMetricChartName(tx *dbs.Tx, chartId int64) (stri
}
// CreateChart 创建图表
func (this *MetricChartDAO) CreateChart(tx *dbs.Tx, itemId int64, name string, chartType string, widthDiv int32, maxItems int32, params maps.Map) (int64, error) {
func (this *MetricChartDAO) CreateChart(tx *dbs.Tx, itemId int64, name string, chartType string, widthDiv int32, maxItems int32, params maps.Map, ignoreEmptyKeys bool, ignoredKeys []string) (int64, error) {
op := NewMetricChartOperator()
op.ItemId = itemId
op.Name = name
@@ -90,13 +90,25 @@ func (this *MetricChartDAO) CreateChart(tx *dbs.Tx, itemId int64, name string, c
return 0, err
}
op.Params = paramsJSON
op.IgnoreEmptyKeys = ignoreEmptyKeys
if len(ignoredKeys) == 0 {
op.IgnoredKeys = "[]"
} else {
ignoredKeysJSON, err := json.Marshal(ignoredKeys)
if err != nil {
return 0, err
}
op.IgnoredKeys = ignoredKeysJSON
}
op.IsOn = true
op.State = MetricChartStateEnabled
return this.SaveInt64(tx, op)
}
// UpdateChart 修改图表
func (this *MetricChartDAO) UpdateChart(tx *dbs.Tx, chartId int64, name string, chartType string, widthDiv int32, maxItems int32, params maps.Map, isOn bool) error {
func (this *MetricChartDAO) UpdateChart(tx *dbs.Tx, chartId int64, name string, chartType string, widthDiv int32, maxItems int32, params maps.Map, ignoreEmptyKeys bool, ignoredKeys []string, isOn bool) error {
if chartId <= 0 {
return errors.New("invalid chartId")
}
@@ -115,6 +127,17 @@ func (this *MetricChartDAO) UpdateChart(tx *dbs.Tx, chartId int64, name string,
return err
}
op.Params = paramsJSON
op.IgnoreEmptyKeys = ignoreEmptyKeys
if len(ignoredKeys) == 0 {
op.IgnoredKeys = "[]"
} else {
ignoredKeysJSON, err := json.Marshal(ignoredKeys)
if err != nil {
return err
}
op.IgnoredKeys = ignoredKeysJSON
}
op.IsOn = isOn