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/linkMonitor/LinkDirectionGrid.vue

300 lines
11 KiB
Vue
Raw Normal View History

2022-09-10 23:13:42 +08:00
<template>
2022-09-15 15:51:00 +08:00
<div class="link-direction-grid">
<!--左侧链路出入口-->
2022-11-21 17:31:30 +08:00
<popover-content :isNoData="isLinkNoData" :gridData="linkGridData" :showError="isLinkShowError" :content="linkErrorMsg" style="width: 900px;"/>
<!--右侧链路下一跳-->
2022-11-21 17:31:30 +08:00
<popover-content :isNoData="isNextNoData" :gridData="nextGridData" :showError="isNextShowError" :content="nextErrorMsg" />
2022-09-15 15:51:00 +08:00
</div>
2022-09-10 23:13:42 +08:00
</template>
<script>
import chartMixin from '@/views/charts2/chart-mixin'
2022-09-15 15:51:00 +08:00
import { getSecond } from '@/utils/date-util'
import { api } from '@/utils/api'
import { storageKey } from '@/utils/constants'
import PopoverContent from './LinkDirectionGrid/PopoverContent'
import { computeScore } from '@/utils/tools'
import axios from 'axios'
2022-09-10 23:13:42 +08:00
export default {
name: 'LinkDirectionGrid',
2022-09-15 15:51:00 +08:00
mixins: [chartMixin],
data () {
return {
2022-11-21 17:31:30 +08:00
linkGridData: [],
nextGridData: [],
isLinkNoData: false,
isNextNoData: false,
isLinkShowError: false, // 显示左侧链路报错标识
linkErrorMsg: '', // 左侧链路的报错信息
isNextShowError: false, // 显示右侧下一跳报错标识
nextErrorMsg: '' // 右侧下一跳的报错信息
2022-09-15 15:51:00 +08:00
}
},
components: {
PopoverContent
},
watch: {
timeFilter: {
2022-11-21 17:31:30 +08:00
handler () {
this.init()
}
}
},
mounted () {
this.init()
},
2022-09-15 15:51:00 +08:00
methods: {
init () {
// 链路基本信息
let linkInfo = localStorage.getItem(storageKey.linkInfo)
linkInfo = JSON.parse(linkInfo)
2022-09-15 15:51:00 +08:00
const params = {
startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime)
}
const dataRequest = axios.get(api.linkMonitor.bigramAnalysis, { params: params })
const nextHopRequest = axios.get(api.linkMonitor.bigramNextHopAnalysis, { params: params })
this.toggleLoading(true)
Promise.all([dataRequest, nextHopRequest]).then(response => {
const res = []
res[0] = response[0].data
res[1] = response[1].data
2022-11-21 17:31:30 +08:00
if (res[0].code === 200) {
this.isLinkShowError = false
// 链路流量数据
const linkData = res[0].data.result
// 接口数据乱序根据入链路idingressLinkId大小排序之后
// 再根据同ingressLinkId下的egressLinkId进行排序
linkData.sort((a, b) => {
if (a.ingressLinkId !== b.ingressLinkId) {
return a.ingressLinkId - b.ingressLinkId
}
return a.egressLinkId - b.egressLinkId
})
this.isLinkNoData = linkData.length === 0
if (!this.isLinkNoData) {
// 链路流量数据
const linkGridData = []
linkData.forEach(d => {
const ingressLink = linkInfo.find(l => l.originalLinkId === d.ingressLinkId)
const egressLink = linkInfo.find(l => l.originalLinkId === d.egressLinkId)
if (ingressLink && egressLink) {
const data = linkGridData.find(g => g.linkId === ingressLink.linkId)
// 上行使用情况计算
const egressUsage = this.computeUsage(d.egressBitsRate, egressLink.bandwidth)
// 下行使用情况计算
const ingressUsage = this.computeUsage(d.ingressBitsRate, ingressLink.bandwidth)
// 宽带使用超过90%,赋红点
2022-11-21 17:31:30 +08:00
d.usageMore90 = egressUsage >= 0.9 || ingressUsage >= 0.9
// 计算npm分数
// 分数低于3分赋红点
d.score = this.localComputeScore(d)
2022-11-21 17:31:30 +08:00
d.scoreLow3 = d.score < 3 || d.score === '-'
if (data) {
const existedEgressLink = data.egress.find(e => e.linkId === egressLink.linkId)
if (!existedEgressLink) {
data.egress.push({
linkId: egressLink.linkId,
egressUsage: egressUsage,
ingressUsage: ingressUsage,
popoverWidth: this.computeWidth(egressUsage, ingressUsage, 'popover'),
valueWidth: this.computeWidth(egressUsage, ingressUsage, 'value'),
totalBitsRate: d.totalBitsRate,
...d
})
}
} else {
linkGridData.push({
linkId: ingressLink.linkId,
egress: [{
linkId: egressLink.linkId,
egressUsage: egressUsage,
ingressUsage: ingressUsage,
popoverWidth: this.computeWidth(egressUsage, ingressUsage, 'popover'),
valueWidth: this.computeWidth(egressUsage, ingressUsage, 'value'),
totalBitsRate: d.totalBitsRate,
...d
}]
})
2022-09-15 15:51:00 +08:00
}
}
})
2022-09-30 14:16:23 +08:00
this.linkGridData = linkGridData
}
2022-11-21 17:31:30 +08:00
} else {
this.isLinkNoData = false
this.isLinkShowError = true
this.linkErrorMsg = res[0].message
}
if (res[1].code === 200) {
this.isNextShowError = false
// 链路下一跳信息
const nextLinkData = res[1].data.result
// 接口数据乱序,根据入方向排序,再根据同个入方向下的出方向进行排序
2022-11-21 17:31:30 +08:00
nextLinkData.sort((a, b) => {
if (a.ingressLinkDirection !== b.ingressLinkDirection) {
return a.ingressLinkDirection.localeCompare(b.ingressLinkDirection, 'zh')
2022-11-21 17:31:30 +08:00
}
return a.egressLinkDirection.localeCompare(b.egressLinkDirection, 'zh')
2022-11-21 17:31:30 +08:00
})
this.isNextNoData = nextLinkData.length === 0
if (!this.isNextNoData) {
// 链路下一跳数据
const nextGridData = []
nextLinkData.forEach(d => {
const ingressLink = linkInfo.find(l => l.nextHop === d.ingressLinkDirection && l.direction === 'ingress')
const egressLink = linkInfo.find(l => l.nextHop === d.egressLinkDirection && l.direction === 'egress')
if (ingressLink && egressLink) {
const data = nextGridData.find(g => g.linkId === ingressLink.linkId)
let egressBanwidth = 0
let ingressBanwidth = 0
linkInfo.forEach((item) => {
if (item.nextHop === d.egressLinkDirection && item.direction === 'egress') {
egressBanwidth += item.bandwidth
}
if (item.nextHop === d.ingressLinkDirection && item.direction === 'ingress') {
ingressBanwidth += item.bandwidth
}
})
// 上行使用情况计算
const egressUsage = this.computeUsage(d.egressBitsRate, egressBanwidth)
// 下行使用情况计算
const ingressUsage = this.computeUsage(d.ingressBitsRate, ingressBanwidth)
// 宽带使用超过90%,赋红点
2022-11-21 17:31:30 +08:00
d.usageMore90 = egressUsage >= 0.9 || ingressUsage >= 0.9
// 计算npm分数
// 分数低于3分赋红点
d.score = this.localComputeScore(d)
2022-11-21 17:31:30 +08:00
d.scoreLow3 = d.score < 3 || d.score === '-'
if (data) {
const existedEgressLink = data.egress.find(e => e.linkId === egressLink.linkId)
if (!existedEgressLink) {
data.egress.push({
linkId: egressLink.linkId,
nextHop: egressLink.nextHop,
egressUsage: egressUsage,
ingressUsage: ingressUsage,
popoverWidth: this.computeWidth(egressUsage, ingressUsage, 'popover'),
valueWidth: this.computeWidth(egressUsage, ingressUsage, 'value'),
totalBitsRate: d.totalBitsRate,
...d
})
}
} else {
nextGridData.push({
linkId: ingressLink.linkId,
nextHop: ingressLink.nextHop,
egress: [{
linkId: egressLink.linkId,
nextHop: ingressLink.nextHop,
egressUsage: egressUsage,
ingressUsage: ingressUsage,
popoverWidth: this.computeWidth(egressUsage, ingressUsage, 'popover'),
valueWidth: this.computeWidth(egressUsage, ingressUsage, 'value'),
totalBitsRate: d.totalBitsRate,
...d
}]
})
}
}
})
this.nextGridData = nextGridData
}
} else {
2022-11-29 17:21:01 +08:00
this.isNextNoData = false
2022-11-21 17:31:30 +08:00
this.isNextShowError = true
this.nextErrorMsg = res[1].message
2022-09-15 15:51:00 +08:00
}
}).catch(e => {
2022-11-21 17:31:30 +08:00
this.isLinkShowError = true
this.linkErrorMsg = e.message
2022-11-21 17:31:30 +08:00
this.isNextShowError = true
this.nextErrorMsg = e.message
}).finally(() => {
this.toggleLoading(false)
2022-09-15 15:51:00 +08:00
})
},
/**
* 计算上下行使用占比
*/
computeUsage (e, bandwidth) {
let usage = e / bandwidth
if (usage >= 1) {
usage = 1
}
return usage
},
/**
* 本地计算npm分数
*/
2022-11-21 17:31:30 +08:00
localComputeScore (data) {
let score = 0
2022-11-01 14:13:47 +08:00
const dataScore = {
establishLatencyMs: data.establishLatencyMs || null,
httpResponseLatency: data.httpResponseLatency || null,
sslConLatency: data.sslConLatency || null,
tcpLostlenPercent: data.tcpLostlenPercent || null,
pktRetransPercent: data.pktRetransPercent || null
}
2022-11-01 14:13:47 +08:00
score = computeScore(dataScore)
return score
},
/**
* 计算popover弹窗和右侧数据模块的宽度
* 弹窗最小宽度为360px右侧数据最小宽度为75px右侧数据每大一位popover弹窗宽度增加7px
*/
computeWidth (egress, ingress, flag) {
let width = 0
let length = 0
let egressUsage = ''
let ingressUsage = ''
if (egress < 0.0001 && egress !== 0) {
egressUsage = '<0.01%'
} else {
egressUsage = JSON.stringify(parseFloat((egress * 100).toFixed(2)))
}
if (ingress < 0.0001 && ingress !== 0) {
ingressUsage = '<0.01%'
} else {
ingressUsage = JSON.stringify(parseFloat((ingress * 100).toFixed(2)))
}
length = egressUsage.length + ingressUsage.length - 1
if (flag === 'popover') {
width = 360 + length * 7
} else {
width = 75 + length * 7
}
return width
2022-09-15 15:51:00 +08:00
}
}
2022-09-10 23:13:42 +08:00
}
</script>