refactor: simplify switch port speed calculation
This commit is contained in:
@@ -10,12 +10,12 @@ export interface NdmSwitchDiagInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface NdmSwitchPortInfo {
|
export interface NdmSwitchPortInfo {
|
||||||
flow: number;
|
|
||||||
inBytes: number;
|
inBytes: number;
|
||||||
inFlow: number;
|
|
||||||
lastInBytes: number;
|
lastInBytes: number;
|
||||||
lastOutBytes: number;
|
lastOutBytes: number;
|
||||||
outBytes: number;
|
outBytes: number;
|
||||||
|
flow: number;
|
||||||
|
inFlow: number;
|
||||||
outFlow: number;
|
outFlow: number;
|
||||||
portName: string;
|
portName: string;
|
||||||
upDown: number;
|
upDown: number;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import type { NdmSwitchPortInfo } from '@/apis';
|
import type { NdmSwitchPortInfo } from '@/apis';
|
||||||
import { JAVA_UNSIGNED_INTEGER_MAX_VALUE, NDM_SWITCH_PROBE_INTERVAL } from '@/constants';
|
|
||||||
|
|
||||||
export const getPortStatusVal = (portInfo: NdmSwitchPortInfo): string => {
|
export const getPortStatusVal = (portInfo: NdmSwitchPortInfo): string => {
|
||||||
const { upDown } = portInfo;
|
const { upDown } = portInfo;
|
||||||
@@ -7,47 +6,21 @@ export const getPortStatusVal = (portInfo: NdmSwitchPortInfo): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const transformPortSpeed = (portInfo: NdmSwitchPortInfo, type: 'in' | 'out' | 'total'): string => {
|
export const transformPortSpeed = (portInfo: NdmSwitchPortInfo, type: 'in' | 'out' | 'total'): string => {
|
||||||
const units = ['B/s', 'KB/s', 'MB/s', 'GB/s', 'TB/s'];
|
const units = ['b/s', 'Kb/s', 'Mb/s', 'Gb/s', 'Tb/s'];
|
||||||
const { inBytes, lastInBytes, outBytes, lastOutBytes, inFlow, outFlow, flow } = portInfo;
|
const { inFlow, outFlow, flow } = portInfo;
|
||||||
let result: number = 0;
|
let result: number = 0;
|
||||||
if (inFlow && outFlow && flow) {
|
|
||||||
if (type === 'in') {
|
if (type === 'in') {
|
||||||
result = inFlow;
|
result = inFlow;
|
||||||
}
|
} else if (type === 'out') {
|
||||||
if (type === 'out') {
|
|
||||||
result = outFlow;
|
result = outFlow;
|
||||||
}
|
} else if (type === 'total') {
|
||||||
if (type === 'total') {
|
|
||||||
result = flow;
|
result = flow;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
let dInBytes = 0;
|
|
||||||
let dOutBytes = 0;
|
|
||||||
if (inBytes < lastInBytes) {
|
|
||||||
dInBytes = inBytes + JAVA_UNSIGNED_INTEGER_MAX_VALUE - lastInBytes;
|
|
||||||
} else {
|
|
||||||
dInBytes = inBytes - lastInBytes;
|
|
||||||
}
|
|
||||||
if (outBytes < lastOutBytes) {
|
|
||||||
dOutBytes = outBytes + JAVA_UNSIGNED_INTEGER_MAX_VALUE - lastOutBytes;
|
|
||||||
} else {
|
|
||||||
dOutBytes = outBytes - lastOutBytes;
|
|
||||||
}
|
|
||||||
if (type === 'in') {
|
|
||||||
result = dInBytes;
|
|
||||||
}
|
|
||||||
if (type === 'out') {
|
|
||||||
result = dOutBytes;
|
|
||||||
}
|
|
||||||
if (type === 'total') {
|
|
||||||
result = dInBytes + dOutBytes;
|
|
||||||
}
|
|
||||||
result /= NDM_SWITCH_PROBE_INTERVAL;
|
|
||||||
}
|
|
||||||
let index = 0;
|
let index = 0;
|
||||||
while (result >= 1024 && index < units.length - 1) {
|
while (result >= 1024 && index < units.length - 1) {
|
||||||
result /= 1024;
|
result /= 1024;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
result *= 8;
|
||||||
return `${result.toFixed(3)} ${units[index]}`;
|
return `${result.toFixed(3)} ${units[index]}`;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export const NDM_SWITCH_PROBE_INTERVAL = 5;
|
|
||||||
@@ -1,4 +1,2 @@
|
|||||||
export * from './device';
|
|
||||||
export * from './java';
|
|
||||||
export * from './query';
|
export * from './query';
|
||||||
export * from './stomp';
|
export * from './stomp';
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
export const JAVA_INTEGER_MAX_VALUE = 2147483647;
|
|
||||||
export const JAVA_UNSIGNED_INTEGER_MAX_VALUE = 4294967295;
|
|
||||||
Reference in New Issue
Block a user