Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix(9195): monitor default commonalert accuracy #5445

Open
wants to merge 1 commit into
base: master-bk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion containers/Monitor/sections/Metric/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default {
metricOpts () {
const metricKeyItem = this.metricKeyOpts.find(item => item.key === this.metric_key)
if (metricKeyItem && _.isArray(metricKeyItem.field_key)) {
return metricKeyItem.field_key.map(val => {
const metricValueOpts = metricKeyItem.field_key.map(val => {
let label = val
const fieldDes = metricKeyItem.field_descriptions
let description = {}
Expand All @@ -135,6 +135,20 @@ export default {
metric_res_type: metricKeyItem.metric_res_type,
}
})
// 默认策略适配
const metric_value = _.get(this.decorators, 'metric_value[1].initialValue')
if (metric_value && !metricKeyItem.field_key.includes(metric_value) && metric_zh[metric_value] && (metric_value === 'free/total' || metric_value === 'inodes_free/inodes_total')) {
metricValueOpts.push({
key: metric_value,
label: metric_zh[metric_value],
metric_res_type: metricKeyItem.metric_res_type,
description: {
name: metric_value,
unit: '%',
},
})
}
return metricValueOpts
} else {
return []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ import _ from 'lodash'
import { mapGetters } from 'vuex'
import Metric from '@Monitor/sections/Metric'
import Filters from '@Monitor/sections/Filters'
import ScopeRadio from '@/sections/ScopeRadio'
import { levelMaps, metric_zh } from '@Monitor/constants'
import ScopeRadio from '@/sections/ScopeRadio'
import { resolveValueChangeField } from '@/utils/common/ant'
import NotifyTypes from '@/sections/NotifyTypes'
import Condition from './Condition'
Expand Down Expand Up @@ -184,6 +184,13 @@ export default {
tags = _.get(this.alertData, 'settings.conditions[0].query.model.tags') || []
initialValue.metric_key = _.get(this.alertData, 'settings.conditions[0].query.model.measurement')
initialValue.metric_value = _.get(this.alertData, 'settings.conditions[0].query.model.select[0][0].params[0]')
// 默认策略适配
if (this.$route.query.alertType === 'system') {
const metricValue = _.get(this.alertData, 'common_alert_metric_details[0].field')
if (initialValue.metric_key === 'disk' && (metricValue === 'free/total' || metricValue === 'inodes_free/inodes_total')) {
initialValue.metric_value = metricValue
}
}
initialValue.threshold = _.get(this.alertData, 'settings.conditions[0].evaluator.params[0]')
if (this.alertData.robot_ids && this.alertData.robot_ids.length) {
initialValue.robot_ids = this.alertData.robot_ids
Expand Down Expand Up @@ -486,6 +493,12 @@ export default {
limit: 0,
}
},
metircField () {
return _.get(this.alertData, 'common_alert_metric_details[0].field')
},
metircMeasurement () {
return _.get(this.alertData, 'common_alert_metric_details[0].measurement')
},
},
watch: {
timeRangeParams () {
Expand Down Expand Up @@ -548,6 +561,10 @@ export default {
this.conditionUnit = ds[k].unit
}
}
// 默认策略适配
if (!this.conditionUnit && (this.metircField === 'free/total' || this.metircField === 'inodes_free/inodes_total') && this.metircMeasurement === 'disk') {
this.conditionUnit = '%'
}
}
},
},
Expand Down Expand Up @@ -705,7 +722,23 @@ export default {
}
const tags = []
if (fd.metric_key) params.measurement = fd.metric_key
if (fd.metric_value) params.select = [[{ type: 'field', params: [fd.metric_value] }]]
if (fd.metric_value) {
params.select = [[{ type: 'field', params: [fd.metric_value] }]]
// 默认策略适配
if ((this.metircField === 'free/total' || this.metircField === 'inodes_free/inodes_total') && this.metircMeasurement === 'disk') {
params.select = [[{
type: 'field',
params: [this.metircField.split('/')[0]],
},
{
type: 'mean',
},
{
type: 'math',
params: [`/ mean("${this.metircField.split('/')[1]}")`],
}]]
}
}
if (R.is(Object, fd.tagValues)) {
R.forEachObjIndexed((value, key) => {
if (value) {
Expand Down