This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/views/charts2/charts/npm/NpmNetworkQuantity.vue

130 lines
4.2 KiB
Vue
Raw Normal View History

2022-07-18 15:04:32 +08:00
<template>
<div class="npm-network-quantity">
<single-value
:npm-network-name="npmNetworkName"
:npm-network-data="npmNetworkData"
></single-value>
</div>
2022-07-18 15:04:32 +08:00
</template>
<script>
import SingleValue from '@/views/charts2/charts/SingleValue'
import { get } from '@/utils/http'
import { getSecond } from '@/utils/date-util'
import { api } from '@/utils/api'
import chartMixin from '@/views/charts2/chart-mixin'
import _ from 'lodash'
import { getChainRatio } from '@/utils/tools'
2022-07-18 15:04:32 +08:00
export default {
name: 'NpmNetworkQuantity',
components: { SingleValue },
mixins: [chartMixin],
data () {
return {
npmNetworkName: [
{ name: 'networkAppPerformance.tcpConnectionEstablishLatency' },
{ name: 'networkAppPerformance.httpResponse' },
{ name: 'networkAppPerformance.sslResponseLatency' },
{ name: 'networkAppPerformance.packetLoss' },
{ name: 'overall.packetRetrans' }
],
npmNetworkCycleData: [],
npmNetworkLastCycleData: [],
npmNetworkData: [],
side: '',
chartData: {}
}
},
methods: {
npmNetworkCycleQuery () {
const condition = this.$store.getters.getQueryCondition.split(/["|'](.*?)["|']/)
const type = this.$store.getters.getDimensionType
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
cycle: 0
}
if (this.chartData.id === 23) {
this.side = 'client'
} else {
this.side = 'server'
}
if (condition && type) {
params.q = `${type}='${condition[1]}' and side='${this.side}'`
params.type = type
}
const tcp = get(api.npm.overview.tcpSessionDelay, params)
const http = get(api.npm.overview.httpResponseDelay, params)
const ssl = get(api.npm.overview.sslConDelay, params)
const tcpPercent = get(api.npm.overview.tcpLostlenPercent, params)
const packetPercent = get(api.npm.overview.packetRetransPercent, params)
this.toggleLoading(true)
Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => {
res.forEach(t => {
if (t.code === 200) {
this.npmNetworkCycleData.push(t.data.result)
}
})
}).finally(() => {
this.toggleLoading(false)
})
},
npmNetworkLastCycleQuery () {
const condition = this.$store.getters.getQueryCondition.split(/["|'](.*?)["|']/)
const type = this.$store.getters.getDimensionType
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime),
cycle: 1
}
if (this.chartData.id === 23) {
this.side = 'client'
} else {
this.side = 'server'
}
if (condition && type) {
params.q = `${type}='${condition[1]}' and side='${this.side}'`
params.type = type
}
const tcp = get(api.npm.overview.tcpSessionDelay, params)
const http = get(api.npm.overview.httpResponseDelay, params)
const ssl = get(api.npm.overview.sslConDelay, params)
const tcpPercent = get(api.npm.overview.tcpLostlenPercent, params)
const packetPercent = get(api.npm.overview.packetRetransPercent, params)
this.toggleLoading(true)
Promise.all([tcp, http, ssl, tcpPercent, packetPercent]).then(res => {
res.forEach(t => {
if (t.code === 200) {
this.npmNetworkLastCycleData.push(t.data.result)
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData)
}
})
}).finally(() => {
this.toggleLoading(false)
})
},
npmNetworkQuantity (cycle, lastCycle) {
cycle.forEach(t => {
lastCycle.forEach(e => {
Object.keys(t).forEach(r => {
Object.keys(e).forEach(d => {
if (r === d) {
t.value = getChainRatio(t[r], e[d])
}
})
})
})
})
this.npmNetworkData = cycle
}
},
mounted () {
if (this.chart) {
this.chartData = _.cloneDeep(this.chart)
}
this.npmNetworkCycleQuery()
this.npmNetworkLastCycleQuery()
}
2022-07-18 15:04:32 +08:00
}
</script>