2022-07-18 15:04:32 +08:00
|
|
|
<template>
|
2022-07-19 09:52:28 +08:00
|
|
|
<div class="npm-network-quantity">
|
2022-08-08 17:45:50 +08:00
|
|
|
<single-value
|
2022-11-24 11:02:06 +08:00
|
|
|
v-if="npmNetworkData.length>0"
|
2022-08-08 17:45:50 +08:00
|
|
|
:npm-network-name="npmNetworkName"
|
2022-08-23 16:12:24 +08:00
|
|
|
:npm-network-data="npmNetworkData"
|
2022-08-08 17:45:50 +08:00
|
|
|
></single-value>
|
2022-07-19 09:52:28 +08:00
|
|
|
</div>
|
2022-07-18 15:04:32 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2022-09-13 17:52:38 +08:00
|
|
|
import SingleValue from '@/views/charts2/charts/npm/localComponents/SingleValue'
|
2022-08-08 17:45:50 +08:00
|
|
|
import { get } from '@/utils/http'
|
|
|
|
|
import { getSecond } from '@/utils/date-util'
|
|
|
|
|
import { api } from '@/utils/api'
|
2022-08-21 22:11:53 +08:00
|
|
|
import chartMixin from '@/views/charts2/chart-mixin'
|
2022-08-22 15:49:38 +08:00
|
|
|
import _ from 'lodash'
|
2022-11-11 10:33:00 +08:00
|
|
|
import { getChainRatio } from '@/utils/tools'
|
2022-09-20 10:35:39 +08:00
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
import { ref } from 'vue'
|
2022-07-18 15:04:32 +08:00
|
|
|
export default {
|
2022-07-19 09:52:28 +08:00
|
|
|
name: 'NpmNetworkQuantity',
|
|
|
|
|
components: { SingleValue },
|
2022-08-21 22:11:53 +08:00
|
|
|
mixins: [chartMixin],
|
2022-09-20 10:35:39 +08:00
|
|
|
setup () {
|
|
|
|
|
const { query } = useRoute()
|
|
|
|
|
const queryCondition = ref(query.queryCondition || '')
|
|
|
|
|
const dimensionType = ref(query.dimensionType || '')
|
2022-12-01 16:33:53 +08:00
|
|
|
const tabIndex = ref(query.tabIndex || 0)
|
2022-11-25 16:08:32 +08:00
|
|
|
const tabOperationType = ref(query.tabOperationType)
|
2022-11-17 15:55:34 +08:00
|
|
|
const networkOverviewBeforeTab = ref(query.networkOverviewBeforeTab || '')
|
2022-09-20 10:35:39 +08:00
|
|
|
return {
|
|
|
|
|
queryCondition,
|
2022-11-11 15:25:12 +08:00
|
|
|
dimensionType,
|
2022-11-17 15:55:34 +08:00
|
|
|
tabIndex,
|
2022-11-25 16:08:32 +08:00
|
|
|
tabOperationType,
|
2022-11-17 15:55:34 +08:00
|
|
|
networkOverviewBeforeTab
|
2022-09-20 10:35:39 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-07-19 09:52:28 +08:00
|
|
|
data () {
|
|
|
|
|
return {
|
2022-08-08 17:45:50 +08:00
|
|
|
npmNetworkName: [
|
2022-08-09 11:39:08 +08:00
|
|
|
{ name: 'networkAppPerformance.tcpConnectionEstablishLatency' },
|
|
|
|
|
{ name: 'networkAppPerformance.httpResponse' },
|
|
|
|
|
{ name: 'networkAppPerformance.sslResponseLatency' },
|
|
|
|
|
{ name: 'networkAppPerformance.packetLoss' },
|
|
|
|
|
{ name: 'overall.packetRetrans' }
|
2022-08-08 17:45:50 +08:00
|
|
|
],
|
2022-08-22 15:49:38 +08:00
|
|
|
npmNetworkCycleData: [],
|
2022-08-23 16:12:24 +08:00
|
|
|
npmNetworkLastCycleData: [],
|
|
|
|
|
npmNetworkData: [],
|
2022-08-22 15:49:38 +08:00
|
|
|
side: '',
|
|
|
|
|
chartData: {}
|
2022-08-08 17:45:50 +08:00
|
|
|
}
|
|
|
|
|
},
|
2022-08-24 17:09:42 +08:00
|
|
|
watch: {
|
|
|
|
|
timeFilter: {
|
|
|
|
|
handler (n) {
|
|
|
|
|
this.npmNetworkCycleData = []
|
|
|
|
|
this.npmNetworkLastCycleData = []
|
|
|
|
|
this.npmNetworkCycleQuery()
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-08 17:45:50 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
npmNetworkCycleQuery () {
|
2022-08-24 16:58:34 +08:00
|
|
|
let condition = ''
|
2022-11-25 16:08:32 +08:00
|
|
|
let url = ''
|
2022-09-30 17:03:12 +08:00
|
|
|
if (this.queryCondition.indexOf(' OR ') > -1) {
|
2022-09-20 10:35:39 +08:00
|
|
|
condition = this.queryCondition.split(/["|'](.*?)["|']/)
|
2022-08-24 16:58:34 +08:00
|
|
|
} else {
|
2022-09-20 10:35:39 +08:00
|
|
|
condition = this.queryCondition
|
2022-08-24 16:58:34 +08:00
|
|
|
}
|
2022-11-17 15:55:34 +08:00
|
|
|
const type = this.dimensionType || this.networkOverviewBeforeTab
|
2022-08-08 17:45:50 +08:00
|
|
|
const params = {
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
|
|
|
|
cycle: 0
|
|
|
|
|
}
|
2022-11-11 15:25:12 +08:00
|
|
|
if (this.tabIndex == 0) {
|
2022-08-22 15:49:38 +08:00
|
|
|
this.side = 'client'
|
2022-11-11 15:25:12 +08:00
|
|
|
} else if (this.tabIndex == 1) {
|
2022-08-22 15:49:38 +08:00
|
|
|
this.side = 'server'
|
|
|
|
|
}
|
2022-08-24 16:58:34 +08:00
|
|
|
if (condition && (typeof condition !== 'object') && type) {
|
2022-11-15 11:13:11 +08:00
|
|
|
if (type === 'clientIp') {
|
|
|
|
|
params.q = `ip='${condition.split(/'(.*?)'/)[1]}' and side='client'`
|
|
|
|
|
} else if (type === 'serverIp') {
|
|
|
|
|
params.q = `ip='${condition.split(/'(.*?)'/)[1]}' and side='server'`
|
2022-11-16 11:55:11 +08:00
|
|
|
} else if (type === 'clientCity') {
|
2022-11-17 15:55:34 +08:00
|
|
|
params.q = `client_city='${condition.split(/'(.*?)'/)[1]}'`
|
2022-11-16 11:55:11 +08:00
|
|
|
} else if (type === 'serverCity') {
|
2022-11-17 15:55:34 +08:00
|
|
|
params.q = `server_city='${condition.split(/'(.*?)'/)[1]}'`
|
2022-11-15 11:13:11 +08:00
|
|
|
} else {
|
|
|
|
|
params.q = condition
|
|
|
|
|
}
|
2022-08-30 10:58:22 +08:00
|
|
|
params.type = type
|
2022-08-24 16:58:34 +08:00
|
|
|
} else if (condition.length > 1 && type && type === 'ip') {
|
2022-08-22 15:49:38 +08:00
|
|
|
params.q = `${type}='${condition[1]}' and side='${this.side}'`
|
2022-08-30 10:58:22 +08:00
|
|
|
params.type = type
|
2022-08-24 16:58:34 +08:00
|
|
|
} else if (condition.length > 1 && type && type !== 'ip') {
|
2022-08-24 18:18:28 +08:00
|
|
|
if (type === 'country' || type === 'asn' || type === 'province' || type === 'city' || type === 'isp') {
|
2022-08-24 16:58:34 +08:00
|
|
|
params.q = `${type}='${condition[1]}'`
|
2022-08-30 10:58:22 +08:00
|
|
|
params.type = type
|
2022-08-24 16:58:34 +08:00
|
|
|
} else if (type === 'idcRenter') {
|
|
|
|
|
params.q = `idc_renter='${condition[1]}'`
|
2022-08-30 10:58:22 +08:00
|
|
|
params.type = type
|
2022-08-24 16:58:34 +08:00
|
|
|
} else {
|
|
|
|
|
params.q = `${condition[0]}'${condition[1]}'`
|
2022-08-30 10:58:22 +08:00
|
|
|
params.type = type
|
2022-08-24 16:58:34 +08:00
|
|
|
}
|
2022-08-22 15:49:38 +08:00
|
|
|
}
|
2022-11-25 16:08:32 +08:00
|
|
|
if (parseFloat(this.tabOperationType) === 3) {
|
|
|
|
|
url = api.npm.overview.allNetworkAnalysis
|
|
|
|
|
} else {
|
|
|
|
|
url = api.npm.overview.networkAnalysis
|
|
|
|
|
}
|
2022-11-17 15:55:34 +08:00
|
|
|
if ((type && condition) || type) {
|
|
|
|
|
params.type = params.type || type
|
2022-08-30 19:08:29 +08:00
|
|
|
this.toggleLoading(true)
|
2022-11-25 16:08:32 +08:00
|
|
|
get(url, params).then(res => {
|
2022-08-30 19:08:29 +08:00
|
|
|
if (res.code === 200) {
|
2022-11-02 10:59:21 +08:00
|
|
|
this.npmNetworkCycleData = res.data.result
|
2022-08-09 11:39:08 +08:00
|
|
|
}
|
2022-11-25 16:08:32 +08:00
|
|
|
this.npmNetworkLastCycleQuery(url, params)
|
2022-09-06 11:41:36 +08:00
|
|
|
}).catch(e => {
|
2022-08-30 19:08:29 +08:00
|
|
|
this.toggleLoading(false)
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
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 => {
|
2022-09-06 11:37:56 +08:00
|
|
|
this.npmNetworkCycleData = []
|
2022-11-24 11:03:53 +08:00
|
|
|
res.forEach(t => {
|
2022-08-30 19:08:29 +08:00
|
|
|
if (t.code === 200) {
|
|
|
|
|
this.npmNetworkCycleData.push(t.data.result)
|
2022-11-24 11:02:06 +08:00
|
|
|
} else {
|
|
|
|
|
this.npmNetworkCycleData.push(t)
|
2022-08-30 19:08:29 +08:00
|
|
|
}
|
|
|
|
|
})
|
2022-09-06 11:37:56 +08:00
|
|
|
this.npmNetworkLastCycleQuery()
|
|
|
|
|
}).catch(e => {
|
2022-08-30 19:08:29 +08:00
|
|
|
this.toggleLoading(false)
|
2022-11-24 11:02:06 +08:00
|
|
|
// 此时e为数组
|
|
|
|
|
if (e instanceof Array) {
|
|
|
|
|
this.npmNetworkCycleData = []
|
2022-11-24 11:03:53 +08:00
|
|
|
e.forEach(t => {
|
2022-11-24 11:02:06 +08:00
|
|
|
this.npmNetworkCycleData.push(t)
|
|
|
|
|
})
|
|
|
|
|
this.npmNetworkLastCycleQuery()
|
|
|
|
|
}
|
2022-08-09 11:39:08 +08:00
|
|
|
})
|
2022-08-30 19:08:29 +08:00
|
|
|
}
|
2022-08-23 16:12:24 +08:00
|
|
|
},
|
2022-11-25 16:08:32 +08:00
|
|
|
npmNetworkLastCycleQuery (url, param) {
|
2022-08-23 16:12:24 +08:00
|
|
|
const params = {
|
|
|
|
|
startTime: getSecond(this.timeFilter.startTime),
|
|
|
|
|
endTime: getSecond(this.timeFilter.endTime),
|
|
|
|
|
cycle: 1
|
|
|
|
|
}
|
2022-11-25 16:08:32 +08:00
|
|
|
if (param && param.type && param.q) {
|
|
|
|
|
params.type = param.type
|
|
|
|
|
params.q = param.q
|
2022-08-23 16:12:24 +08:00
|
|
|
}
|
2022-11-25 16:08:32 +08:00
|
|
|
if ((params.type && params.q) || (param && param.type)) {
|
|
|
|
|
params.type = params.type || param.type
|
2022-11-17 15:55:34 +08:00
|
|
|
this.toggleLoading(true)
|
2022-11-25 16:08:32 +08:00
|
|
|
get(url, params).then(res => {
|
2022-11-17 15:55:34 +08:00
|
|
|
if (res.code === 200) {
|
|
|
|
|
this.npmNetworkLastCycleData = res.data.result
|
2022-11-24 11:02:06 +08:00
|
|
|
} else {
|
|
|
|
|
this.npmNetworkLastCycleData = [res]
|
2022-11-17 15:55:34 +08:00
|
|
|
}
|
2022-11-24 11:02:06 +08:00
|
|
|
let timer = null
|
|
|
|
|
if (timer) {
|
|
|
|
|
clearTimeout(timer)
|
|
|
|
|
}
|
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
|
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0)
|
|
|
|
|
}, 300)
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
let timer = null
|
|
|
|
|
if (timer) {
|
|
|
|
|
clearTimeout(timer)
|
|
|
|
|
}
|
|
|
|
|
this.npmNetworkLastCycleData = [e]
|
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
|
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0)
|
|
|
|
|
}, 300)
|
2022-11-17 15:55:34 +08:00
|
|
|
}).finally(() => {
|
|
|
|
|
this.toggleLoading(false)
|
2022-08-23 16:12:24 +08:00
|
|
|
})
|
2022-08-30 19:08:29 +08:00
|
|
|
} else {
|
|
|
|
|
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, i) => {
|
|
|
|
|
if (t.code === 200) {
|
|
|
|
|
this.npmNetworkLastCycleData.push(t.data.result)
|
2022-11-24 11:02:06 +08:00
|
|
|
} else {
|
|
|
|
|
this.npmNetworkLastCycleData.push(t)
|
2022-08-30 19:08:29 +08:00
|
|
|
}
|
2022-11-24 11:02:06 +08:00
|
|
|
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 1)
|
2022-08-30 19:08:29 +08:00
|
|
|
})
|
2022-11-24 11:02:06 +08:00
|
|
|
}).catch((e) => {
|
|
|
|
|
// todo 此处的e可能为数组
|
|
|
|
|
if (e instanceof Array) {
|
|
|
|
|
e.forEach((t, i) => {
|
|
|
|
|
this.npmNetworkLastCycleData.push(t)
|
|
|
|
|
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 1)
|
|
|
|
|
})
|
|
|
|
|
}
|
2022-08-30 19:08:29 +08:00
|
|
|
}).finally(() => {
|
|
|
|
|
this.toggleLoading(false)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
npmNetworkQuantity (cycle, lastCycle, num) {
|
|
|
|
|
if (num === 0) {
|
|
|
|
|
this.npmNetworkData[0] = {
|
2022-09-01 16:35:56 +08:00
|
|
|
establishLatencyMsAvg: Math.floor(cycle.establishLatencyMsAvg),
|
2022-08-30 19:08:29 +08:00
|
|
|
establishLatencyMsP99: cycle.establishLatencyMsP99,
|
|
|
|
|
establishLatencyMsP95: cycle.establishLatencyMsP95,
|
|
|
|
|
value: getChainRatio(cycle.establishLatencyMsAvg, lastCycle.establishLatencyMsAvg)
|
2022-08-24 11:43:04 +08:00
|
|
|
}
|
2022-08-30 19:08:29 +08:00
|
|
|
this.npmNetworkData[1] = {
|
2022-09-01 16:35:56 +08:00
|
|
|
httpResponseLatencyAvg: Math.floor(cycle.httpResponseLatencyAvg),
|
2022-08-30 19:08:29 +08:00
|
|
|
httpResponseLatencyP99: cycle.httpResponseLatencyP99,
|
|
|
|
|
httpResponseLatencyP95: cycle.httpResponseLatencyP95,
|
|
|
|
|
value: getChainRatio(cycle.httpResponseLatencyAvg, lastCycle.httpResponseLatencyAvg)
|
2022-08-24 14:33:39 +08:00
|
|
|
}
|
2022-08-30 19:08:29 +08:00
|
|
|
this.npmNetworkData[2] = {
|
2022-09-01 16:35:56 +08:00
|
|
|
sslConLatencyAvg: Math.floor(cycle.sslConLatencyAvg),
|
2022-08-30 19:08:29 +08:00
|
|
|
sslConLatencyP99: cycle.sslConLatencyP99,
|
|
|
|
|
sslConLatencyP95: cycle.sslConLatencyP95,
|
|
|
|
|
value: getChainRatio(cycle.sslConLatencyAvg, lastCycle.sslConLatencyAvg)
|
|
|
|
|
}
|
|
|
|
|
this.npmNetworkData[3] = {
|
|
|
|
|
tcpLostlenPercentAvg: cycle.tcpLostlenPercentAvg,
|
|
|
|
|
tcpLostlenPercentP99: cycle.tcpLostlenPercentP99,
|
|
|
|
|
tcpLostlenPercentP95: cycle.tcpLostlenPercentP95,
|
|
|
|
|
value: getChainRatio(cycle.tcpLostlenPercentAvg, lastCycle.tcpLostlenPercentAvg)
|
|
|
|
|
}
|
|
|
|
|
this.npmNetworkData[4] = {
|
|
|
|
|
pktRetransPercentAvg: cycle.pktRetransPercentAvg,
|
|
|
|
|
pktRetransPercentP99: cycle.pktRetransPercentP99,
|
|
|
|
|
pktRetransPercentP95: cycle.pktRetransPercentP95,
|
|
|
|
|
value: getChainRatio(cycle.pktRetransPercentAvg, lastCycle.pktRetransPercentAvg)
|
|
|
|
|
}
|
|
|
|
|
} else if (num === 1) {
|
|
|
|
|
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])
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-08-23 16:12:24 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-08-30 19:08:29 +08:00
|
|
|
this.npmNetworkData = cycle
|
|
|
|
|
}
|
2022-07-19 09:52:28 +08:00
|
|
|
}
|
2022-08-08 17:45:50 +08:00
|
|
|
},
|
|
|
|
|
mounted () {
|
2022-08-22 15:49:38 +08:00
|
|
|
if (this.chart) {
|
|
|
|
|
this.chartData = _.cloneDeep(this.chart)
|
|
|
|
|
}
|
2022-08-08 17:45:50 +08:00
|
|
|
this.npmNetworkCycleQuery()
|
2022-07-19 09:52:28 +08:00
|
|
|
}
|
2022-07-18 15:04:32 +08:00
|
|
|
}
|
|
|
|
|
</script>
|