diff --git a/nezha-fronted/src/components/chart/ChartScreenHeader.vue b/nezha-fronted/src/components/chart/ChartScreenHeader.vue
index 66c72218c..1145957b6 100644
--- a/nezha-fronted/src/components/chart/ChartScreenHeader.vue
+++ b/nezha-fronted/src/components/chart/ChartScreenHeader.vue
@@ -13,6 +13,19 @@
+
@@ -74,7 +83,10 @@ export default {
chartData: [],
loading: true,
isError: false,
- MultipleTime: false
+ multipleTime: false,
+ minusTime: '',
+ showAllData: false,
+ allDataLength: 0
}
},
computed: {
@@ -87,8 +99,7 @@ export default {
},
methods: {
isGroup,
- dateChange (filter, MultipleTime) {
- console.log(filter, MultipleTime)
+ dateChange (filter, multipleTime) {
this.loading = true
// TODO assetInfo、endpointInfo、echarts等进行不同的处理
let startTime = filter.start_time
@@ -97,6 +108,14 @@ export default {
startTime = this.$stringTimeParseToUnix(startTime)
endTime = this.$stringTimeParseToUnix(endTime)
const elements = this.chartInfo.elements || []
+ if (multipleTime.length) {
+ const minusTime = (new Date(filter.start_time).getTime() - new Date(multipleTime[0]).getTime())
+ this.minusTime = minusTime
+ this.multipleTime = true
+ } else {
+ this.minusTime = ''
+ this.multipleTime = false
+ }
this.chartInfo.loaded && this.query(elements, startTime, endTime, step)
},
// 参数 isRefresh 标识是否是刷新操作
@@ -128,6 +147,7 @@ export default {
},
query (elements, startTime, endTime, step) {
this.isError = false
+ this.allDataLength = 0
try {
switch (this.chartInfo.datasource) {
case 'metrics':
@@ -138,7 +158,7 @@ export default {
} else if (this.chartInfo.datasource === 'logs') {
urlPre += '/logs/loki'
}
- const requests = elements.map((element) => {
+ let requests = elements.map((element) => {
if (this.from === fromRoute.chartTemp) {
return chartTempData
}
@@ -146,21 +166,61 @@ export default {
if (isTimeSeries(this.chartInfo.type)) {
query += `&nullType=${this.chartInfo.param.nullType || 'null'}`
}
+ if (element.filter) {
+ query += `&filter=${element.filter}`
+ }
// if (isChartPie(this.chartInfo.type)) {
// query += `&statistics=${this.chartInfo.param.statistics || 'last'}`
// }
query += `&query=${element.expression}`
return this.$get(query)
})
-
+ if (this.multipleTime) {
+ const multipleRequests = elements.map((element) => {
+ if (this.from === fromRoute.chartTemp) {
+ return chartTempData
+ }
+ let query = `${urlPre}/api/v1/query_range?start=${startTime - this.minusTime / 1000}&end=${endTime - this.minusTime / 1000}&step=${step}`
+ if (isTimeSeries(this.chartInfo.type)) {
+ query += `&nullType=${this.chartInfo.param.nullType || 'null'}`
+ }
+ if (element.filter) {
+ query += `&filter=${element.filter}`
+ }
+ // if (isChartPie(this.chartInfo.type)) {
+ // query += `&statistics=${this.chartInfo.param.statistics || 'last'}`
+ // }
+ query += `&query=${element.expression}`
+ return this.$get(query)
+ })
+ requests = requests.concat(multipleRequests)
+ }
const chartData = []
- axios.all(requests).then(res => {
- res.forEach(r => {
- if (r.status === 'success') {
- chartData.push(r.data.result)
+ axios.all(requests).then((res) => {
+ res.forEach((r, rIndex) => {
+ if (rIndex < elements.length) {
+ if (r.status === 'success') {
+ r.data.result.forEach(item => {
+ this.allDataLength++
+ })
+ chartData.push(r.data.result)
+ } else {
+ chartData.push({ error: r.msg || r.error || r })
+ this.isError = true
+ }
} else {
- chartData.push({ error: r.msg || r.error || r })
- this.isError = true
+ if (r.status === 'success') {
+ r.data.result.forEach(item => {
+ this.allDataLength++
+ item.values.forEach(values => {
+ values[0] = values[0] + this.minusTime / 1000
+ })
+ })
+ chartData.push(r.data.result)
+ } else {
+ chartData.push({ error: r.msg || r.error || r })
+ this.isError = true
+ }
}
})
this.chartData = chartData
@@ -316,6 +376,21 @@ export default {
this.groupInit()
bus.$emit('groupMove', '', '', true)
this.$emit('groupShow', this.chartInfo)
+ },
+ showMultiple (type) {
+ switch (type) {
+ case 'line' :
+ case 'area' :
+ case 'point' :
+ return true
+ default: return false
+ }
+ },
+ loadMore () {
+ this.showAllData = true
+ this.$nextTick(() => {
+ this.$refs.chart && this.$refs.chart.$refs['chart' + this.chartInfo.id].initChart()
+ })
}
},
watch: {
@@ -334,6 +409,7 @@ export default {
},
mounted () {
this.chartInfo.loaded && this.getChartData()
+ this.showAllData = !this.showMultiple(this.chartInfo.type)
}
}
diff --git a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue
index 7bcfdcc82..700297ec3 100644
--- a/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue
+++ b/nezha-fronted/src/components/common/bottomBox/tabs/alertMessageTabNew.vue
@@ -47,36 +47,56 @@
-
-
- {{errorContent}}
-
-
-
-
-
-
- {{$t("project.endpoint.dialogTitle")}}
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{
this.currentMsg = { ...row, alertRule: { ...res.data } }
- this.graphShow = true
this.$nextTick(() => {
this.searchTime = [bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000), bus.computeTimezoneTime(new Date().getTime())]
this.queryDate()
@@ -683,12 +708,15 @@ export default {
queryDate () {
this.chartLoading = true
if (this.currentMsg.alertRule.type === 1) {
- this.resultType = 'matrix'
- this.$nextTick(() => {
- this.queryChartDate()
- })
+ const chartInfo = lodash.cloneDeep(lineData)
+ chartInfo.elements[0].expression = encodeURIComponent(this.currentMsg.alertRule.expr.replace(/\"/g, '\'').replace(/\r|\n+/g, ''))
+ chartInfo.elements[0].filter = encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))
+ this.showFullscreen(true, chartInfo)
} else if (this.currentMsg.alertRule.type === 2) {
- this.queryLogData(1000)
+ const chartInfo = lodash.cloneDeep(logData)
+ chartInfo.elements[0].expression = encodeURIComponent(this.currentMsg.alertRule.expr.replace(/\"/g, '\'').replace(/\r|\n+/g, ''))
+ chartInfo.elements[0].filter = encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))
+ this.showFullscreen(true, chartInfo)
}
},
exportLog ({ limit, descending }) {
@@ -841,6 +869,10 @@ export default {
showText (row) {
this.dialogShowText = true
this.dialogText = row.alertRule.trbShot
+ },
+ showFullscreen (show, chartInfo) {
+ this.chartInfo = chartInfo
+ this.graphShow = show
}
}
}
diff --git a/nezha-fronted/src/components/page/alert/alertMessage.vue b/nezha-fronted/src/components/page/alert/alertMessage.vue
index b7368d9e9..bee157783 100644
--- a/nezha-fronted/src/components/page/alert/alertMessage.vue
+++ b/nezha-fronted/src/components/page/alert/alertMessage.vue
@@ -101,36 +101,24 @@
-
-
- {{errorContent}}
-
-
-
-
-
-
- {{$t("project.endpoint.dialogTitle")}}
-
-
-
-
-
-
+
+
{
this.currentMsg = { ...row, alertRule: { ...res.data } }
- this.graphShow = true
+ console.log(this.currentMsg )
this.$nextTick(() => {
this.searchTimeDialog = [bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000), bus.computeTimezoneTime(new Date().getTime())]
this.queryDate()
@@ -578,132 +572,15 @@ export default {
queryDate () {
this.chartLoading = true
if (this.currentMsg.alertRule.type === 1) {
- this.resultType = 'matrix'
- this.$nextTick(() => {
- this.queryChartDate()
- })
+ const chartInfo = lodash.cloneDeep(lineData)
+ chartInfo.elements[0].expression = encodeURIComponent(this.currentMsg.alertRule.expr.replace(/\"/g, '\'').replace(/\r|\n+/g, ''))
+ chartInfo.elements[0].filter = encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))
+ this.showFullscreen(true, chartInfo)
} else if (this.currentMsg.alertRule.type === 2) {
- this.queryLogData(100)
- }
- },
- queryChartDate () {
- const $temp = this
- const start = this.searchTimeDialog[0] ? this.searchTimeDialog[0] : bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000)
- const end = this.searchTimeDialog[1] ? this.searchTimeDialog[1] : bus.computeTimezoneTime(new Date().getTime())
- this.searchTimeDialog = [start, end]
- const timeDiff = (new Date(end).getTime() - new Date(start).getTime()) / 1000 / (24 * 60 * 60)
- let step = '15s'
- if (timeDiff < 1) {
- step = '15s'
- } else if (timeDiff < 7) {
- step = '5m'
- } else if (timeDiff < 30) {
- step = '10m'
- } else {
- step = '30m'
- }
- if (this.$refs.messageChart) {
- this.$refs.messageChart.startLoading()
- const axiosArr = []
- axiosArr.push(axios.get('/prom/api/v1/query_range?query=' + encodeURIComponent(this.currentMsg.alertRule.expr.replace(/\"/g, '\'').replace(/\r|\n+/g, '')) + '&start=' + this.$stringTimeParseToUnix(start) + '&end=' + this.$stringTimeParseToUnix(end) + '&step=' + step + '&filter=' + encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))))
- this.legend = []
- this.chartDatas = []
- axios.all(axiosArr).then(res => {
- this.chartLoading = false
- try {
- res.forEach((response, promIndex) => {
- if (response.status === 200) {
- if (response.data.status === 'success') {
- const queryData = response.data.data.result[0]
- if (queryData) {
- const chartData = {
- type: 'line',
- symbol: 'none', // 去掉点
- smooth: 0.2, // 曲线变平滑
- name: '',
- lineStyle: {
- width: 1,
- opacity: 0.9
- },
- markLine: {
- silent: true,
- symbol: ['circle', 'circle'],
- label: {
- distance: this.computeDistance(chartDataFormat.getUnit(this.currentMsg.alertRule.unit ? this.currentMsg.alertRule.unit : 2).compute(this.currentMsg.alertRule.threshold)),
- formatter (params) {
- return chartDataFormat.getUnit($temp.currentMsg.alertRule.unit ? $temp.currentMsg.alertRule.unit : 2).compute(params.value)
- }
- },
- lineStyle: {
- color: '#d64f40',
- width: 2,
- type: 'dotted'
- },
- data: [{
- yAxis: Number(this.currentMsg.alertRule.threshold)
- }]
- },
- markArea: {
- itemStyle: {
- color: '#d64f40',
- opacity: 0.1
- },
- data: [this.returnMarkArea()]
- }
- }
- if (this.currentMsg.alertRule.operator == '==' || this.currentMsg.alertRule.operator == '!=') {
- delete chartData.markArea
- }
- let alias = chartData.name
- chartData.name += '{'
- alias += '{'
- Object.keys(queryData.metric).forEach((item, index) => {
- const label = item
- const value = queryData.metric[label]
- chartData.name += label + "='" + value + "',"
- })
- chartData.name = chartData.name.charAt(chartData.name.length - 1) == ',' ? chartData.name.substr(0, chartData.name.length - 1) : chartData.name
- chartData.name += '}'
- const legend = {
- name: chartData.name,
- alias: chartData.name,
- isGray: false
- }
- this.legend.push(legend)
- chartData.data = queryData.values.map((dpsItem, dpsIndex) => {
- return [dpsItem[0] * 1000, parseFloat(dpsItem[1]).toFixed(2)]
- })
- this.chartDatas.push(chartData)
- }
- } else {
- this.$message.error(response.data.error)
- }
- } else {
- this.$refs.messageChart.endLoading()
- this.chartLoading = false
- this.isError = true
- if (response.msg) {
- this.errorContent = response.msg
- } else if (response.error) {
- this.errorContent = response.error
- } else {
- this.errorContent = response
- }
- }
- })
- this.$nextTick(() => {
- this.$refs.messageChart.setRandomColors(this.chartDatas.length)
- this.$refs.messageChart.setLegend(this.legend)
- this.$refs.messageChart.setSeries(this.chartDatas)
- this.$refs.messageChart.endLoading()
- this.$refs.messageChart.resize()
- })
- } catch (err) {
- // this.$message.error(err)
- this.$refs.messageChart.endLoading()
- this.chartLoading = false
- }
- })
+ const chartInfo = lodash.cloneDeep(logData)
+ chartInfo.elements[0].expression = encodeURIComponent(this.currentMsg.alertRule.expr.replace(/\"/g, '\'').replace(/\r|\n+/g, ''))
+ chartInfo.elements[0].filter = encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))
+ this.showFullscreen(true, chartInfo)
}
},
exportLog ({ limit, descending }) {
@@ -746,33 +623,6 @@ export default {
reader.readAsText(error.response.data)
})
},
- queryLogData (limit) { // log的chart和table是一个请求
- if (!limit) {
- limit = 100
- }
- const start = this.searchTimeDialog[0] ? this.searchTimeDialog[0] : bus.computeTimezoneTime(new Date().getTime() - 1 * 60 * 60 * 1000)
- const end = this.searchTimeDialog[1] ? this.searchTimeDialog[1] : bus.computeTimezoneTime(new Date().getTime())
- this.expressions = [this.currentMsg.alertRule.expr]
- this.$get('/logs/loki/api/v1/query_range?format=1&query=' + encodeURIComponent(this.currentMsg.alertRule.expr) + '&start=' + this.$stringTimeParseToUnix(start) + '&end=' + this.$stringTimeParseToUnix(end) + '&limit=' + limit + '&filter=' + encodeURIComponent(decodeURIComponent(this.promQueryParamLabels(this.currentMsg.labels)))).then(res => {
- this.chartLoading = false
- const logData = [res.data]
- this.resultType = res.data.resultType
- this.$nextTick(() => {
- if (this.$refs.logDetail) {
- this.$refs.logDetail.time = this.chartData.param.time
- this.$refs.logDetail.wrapLines = this.chartData.param.wrapLines
- this.$refs.logDetail.operations.descending = this.chartData.param.descending
- }
- // logData.forEach((item, index) => {
- // item.result.forEach(result => {
- // result.elements = this.expressions[index]
- // })
- // })
- this.logData = logData
- this.resultType === 'matrix' && this.loadLogGraph()
- })
- })
- },
loadLogGraph () {
const graphData = this.logData.filter(l => l.resultType === 'matrix')
if (graphData && graphData.length > 0) {
@@ -1251,6 +1101,10 @@ export default {
params.ids = this.batchDeleteObjs.map(item => item.id).join(',')
this.exportExcel(this.exportUrl, params, this.exportFileName + '-' + this.getTimeString() + '.xlsx')
this.closeDialog()
+ },
+ showFullscreen (show, chartInfo) {
+ this.chartInfo = chartInfo
+ this.graphShow = show
}
},
destroyed () {
diff --git a/nezha-fronted/src/components/page/dashboard/panel.vue b/nezha-fronted/src/components/page/dashboard/panel.vue
index eb536cc22..59089b87e 100644
--- a/nezha-fronted/src/components/page/dashboard/panel.vue
+++ b/nezha-fronted/src/components/page/dashboard/panel.vue
@@ -34,11 +34,11 @@