2021-08-05 22:25:55 +08:00
|
|
|
<template>
|
|
|
|
|
<nz-bottom-data-list
|
|
|
|
|
:custom-tool="true"
|
|
|
|
|
:layout="[]"
|
|
|
|
|
:show-pagination="false"
|
|
|
|
|
:tabs="tabs"
|
|
|
|
|
:targetTab="targetTab"
|
|
|
|
|
@changeTab="changeTab"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:title><span :title="obj.name">{{obj.name}}</span></template>
|
|
|
|
|
<template v-slot:top-tool-right>
|
|
|
|
|
<el-input v-model="matchContent" class="margin-r-10" placeholder="" size="small" suffix-icon="el-icon-search" @keyup.enter.native="queryLogData()">
|
|
|
|
|
<el-select slot="prepend" v-model="matchSymbol" class="symbol-select" size="small" style="width: 60px;">
|
|
|
|
|
<el-option value="|="></el-option>
|
|
|
|
|
<el-option value="!="></el-option>
|
|
|
|
|
<el-option value="|~"></el-option>
|
|
|
|
|
<el-option value="!~"></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-input>
|
|
|
|
|
<pick-time id="explore" ref="pickTime" v-model="filterTime" :refresh-data-func="queryLogData" :use-chart-unit="false" :use-refresh="false">
|
|
|
|
|
<template slot="added-text">{{$t('overall.query')}}</template>
|
|
|
|
|
</pick-time>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot>
|
2021-08-31 18:13:15 +08:00
|
|
|
<template v-if="logData && logData.length > 0">
|
|
|
|
|
<log-tab ref="logDetail" v-loading="loading" :log-data="logData" :tab-index="9" @exportLog="exportLog" @limitChange="queryLogData"></log-tab>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<div v-loading="loading" style="height: 300px; width: 100%; display: flex; justify-content: center; align-items: center; color: #999;">No Data</div>
|
|
|
|
|
</template>
|
2021-08-05 22:25:55 +08:00
|
|
|
</template>
|
|
|
|
|
</nz-bottom-data-list>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import nzBottomDataList from '@/components/common/bottomBox/nzBottomDataList'
|
|
|
|
|
import logTab from '@/components/page/dashboard/explore/logTab'
|
|
|
|
|
import subDataListMixin from '@/components/common/mixin/subDataList'
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import bus from '@/libs/bus'
|
2021-08-06 17:06:52 +08:00
|
|
|
import { fromRoute } from '@/components/common/js/constants'
|
2021-08-05 22:25:55 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'logBottomTab',
|
|
|
|
|
mixins: [subDataListMixin],
|
|
|
|
|
components: {
|
|
|
|
|
nzBottomDataList,
|
|
|
|
|
logTab
|
|
|
|
|
},
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
logData: [],
|
|
|
|
|
filterTime: [
|
|
|
|
|
bus.timeFormate(bus.getOffsetTimezoneData(-1), 'yyyy-MM-dd hh:mm:ss'),
|
|
|
|
|
bus.timeFormate(bus.getOffsetTimezoneData(), 'yyyy-MM-dd hh:mm:ss')
|
|
|
|
|
],
|
|
|
|
|
expressions: [''],
|
|
|
|
|
matchSymbol: '|=',
|
2021-08-31 18:13:15 +08:00
|
|
|
matchContent: '',
|
|
|
|
|
loading: true
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
exportLog ({ limit, descending }) {
|
|
|
|
|
const params = {
|
|
|
|
|
logql: this.expressions,
|
|
|
|
|
start: this.$stringTimeParseToUnix(this.filterTime[0]),
|
|
|
|
|
end: this.$stringTimeParseToUnix(this.filterTime[1]),
|
|
|
|
|
direction: descending ? 'backward' : 'forward',
|
|
|
|
|
limit
|
|
|
|
|
}
|
|
|
|
|
axios.get('/logs/loki/export', { responseType: 'blob', params: params }).then(res => {
|
|
|
|
|
if (window.navigator.msSaveOrOpenBlob) {
|
|
|
|
|
// 兼容ie11
|
|
|
|
|
const blobObject = new Blob([res.data])
|
|
|
|
|
window.navigator.msSaveOrOpenBlob(blobObject, 'log')
|
|
|
|
|
} else {
|
|
|
|
|
const url = URL.createObjectURL(new Blob([res.data]))
|
|
|
|
|
const a = document.createElement('a')
|
|
|
|
|
document.body.appendChild(a) // 此处增加了将创建的添加到body当中
|
|
|
|
|
a.href = url
|
|
|
|
|
a.download = 'log'
|
|
|
|
|
a.target = '_blank'
|
|
|
|
|
a.click()
|
|
|
|
|
a.remove() // 将a标签移除
|
|
|
|
|
}
|
|
|
|
|
}, error => {
|
|
|
|
|
const $self = this
|
|
|
|
|
const reader = new FileReader()
|
|
|
|
|
reader.onload = function (event) {
|
|
|
|
|
const responseText = reader.result
|
|
|
|
|
const exception = JSON.parse(responseText)
|
|
|
|
|
if (exception.message) {
|
|
|
|
|
$self.$message.error(exception.message)
|
|
|
|
|
} else {
|
|
|
|
|
console.error(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
reader.readAsText(error.response.data)
|
|
|
|
|
})
|
|
|
|
|
},
|
2021-08-31 18:13:15 +08:00
|
|
|
queryLogData (limit = 1000) { // log的chart和table是一个请求
|
|
|
|
|
this.loading = true
|
2021-08-05 22:25:55 +08:00
|
|
|
if (this.expressions.length > 0) {
|
|
|
|
|
const requestArr = []
|
|
|
|
|
this.expressions.forEach((item, index) => {
|
|
|
|
|
if (item != '') {
|
|
|
|
|
let expr = item
|
2021-08-25 16:05:33 +08:00
|
|
|
this.matchContent && (expr = `${item} ${this.matchSymbol} "${this.matchContent}"`)
|
2021-08-05 22:25:55 +08:00
|
|
|
requestArr.push(this.$get('/logs/loki/api/v1/query_range?format=1&query=' + expr + '&start=' + this.$stringTimeParseToUnix(this.filterTime[0]) + '&end=' + this.$stringTimeParseToUnix(this.filterTime[1]) + '&limit=' + limit))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
axios.all(requestArr).then(res => {
|
|
|
|
|
this.logData = res.map(r => r.data)
|
2021-08-31 18:13:15 +08:00
|
|
|
}).finally(() => {
|
|
|
|
|
this.loading = false
|
2021-08-05 22:25:55 +08:00
|
|
|
})
|
2021-08-31 18:13:15 +08:00
|
|
|
} else {
|
|
|
|
|
this.loading = false
|
2021-08-05 22:25:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
2021-08-05 22:31:36 +08:00
|
|
|
if (this.from === fromRoute.endpoint) {
|
|
|
|
|
this.expressions = [`{project="${this.obj.project.name}",module="${this.obj.module.name}",endpoint="${this.obj.name}"}`]
|
|
|
|
|
} else if (this.from === fromRoute.asset) {
|
|
|
|
|
this.expressions = [`{asset="${this.obj.name}"}`]
|
|
|
|
|
}
|
2021-08-05 22:25:55 +08:00
|
|
|
this.queryLogData()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.symbol-select .el-input__inner {
|
|
|
|
|
padding-left: 8px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|