mirror of
https://github.com/hi2shark/nazhua.git
synced 2026-01-16 09:10:42 +08:00
✨ 调整网络监控,方便过滤后能继续刷新
This commit is contained in:
parent
633ba25b7f
commit
dfc3d9e750
@ -17,6 +17,7 @@
|
|||||||
"flag-icons": "^7.2.3",
|
"flag-icons": "^7.2.3",
|
||||||
"font-logos": "^1.3.0",
|
"font-logos": "^1.3.0",
|
||||||
"remixicon": "^4.5.0",
|
"remixicon": "^4.5.0",
|
||||||
|
"uniqolor": "^1.1.1",
|
||||||
"vue": "^3.5.12",
|
"vue": "^3.5.12",
|
||||||
"vue-echarts": "^7.0.3",
|
"vue-echarts": "^7.0.3",
|
||||||
"vue-router": "^4.4.5",
|
"vue-router": "^4.4.5",
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { CanvasRenderer } from 'echarts/renderers';
|
|||||||
import { LineChart } from 'echarts/charts';
|
import { LineChart } from 'echarts/charts';
|
||||||
import {
|
import {
|
||||||
TooltipComponent,
|
TooltipComponent,
|
||||||
LegendComponent,
|
// LegendComponent,
|
||||||
GridComponent,
|
GridComponent,
|
||||||
DataZoomComponent,
|
DataZoomComponent,
|
||||||
} from 'echarts/components';
|
} from 'echarts/components';
|
||||||
@ -15,7 +15,7 @@ use([
|
|||||||
CanvasRenderer,
|
CanvasRenderer,
|
||||||
LineChart,
|
LineChart,
|
||||||
TooltipComponent,
|
TooltipComponent,
|
||||||
LegendComponent,
|
// LegendComponent,
|
||||||
GridComponent,
|
GridComponent,
|
||||||
DataZoomComponent,
|
DataZoomComponent,
|
||||||
]);
|
]);
|
||||||
@ -28,6 +28,7 @@ export default (
|
|||||||
) => {
|
) => {
|
||||||
const fontFamily = config.nazhua.disableSarasaTermSC === true ? undefined : 'Sarasa Term SC';
|
const fontFamily = config.nazhua.disableSarasaTermSC === true ? undefined : 'Sarasa Term SC';
|
||||||
const option = {
|
const option = {
|
||||||
|
darkMode: mode === 'dark',
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'axis',
|
trigger: 'axis',
|
||||||
axisPointer: {
|
axisPointer: {
|
||||||
@ -49,26 +50,35 @@ export default (
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
legend: {
|
// legend: {
|
||||||
top: 5,
|
// show: false,
|
||||||
data: cateList,
|
// data: cateList.map((i) => ({
|
||||||
textStyle: {
|
// name: i.name,
|
||||||
color: mode === 'dark' ? '#ddd' : '#222',
|
// itemStyle: {
|
||||||
fontFamily,
|
// color: i.color,
|
||||||
fontSize: 14,
|
// },
|
||||||
},
|
// lineStyle: {
|
||||||
},
|
// color: i.color,
|
||||||
|
// },
|
||||||
|
// })),
|
||||||
|
// textStyle: {
|
||||||
|
// color: mode === 'dark' ? '#ddd' : '#222',
|
||||||
|
// fontFamily,
|
||||||
|
// fontSize: 14,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
grid: {
|
grid: {
|
||||||
left: 0,
|
top: 10,
|
||||||
|
left: 5,
|
||||||
right: 5,
|
right: 5,
|
||||||
bottom: 0,
|
bottom: 50,
|
||||||
containLabel: true,
|
containLabel: true,
|
||||||
},
|
},
|
||||||
dataZoom: [{
|
dataZoom: [{
|
||||||
id: 'dataZoomX',
|
id: 'dataZoomX',
|
||||||
type: 'slider',
|
type: 'slider',
|
||||||
xAxisIndex: [0],
|
xAxisIndex: [0],
|
||||||
filterMode: 'filter',
|
filterMode: 'none',
|
||||||
}],
|
}],
|
||||||
yAxis: {
|
yAxis: {
|
||||||
type: 'value',
|
type: 'value',
|
||||||
@ -96,9 +106,8 @@ export default (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
series: valueList.map((i) => ({
|
series: valueList.map((i) => ({
|
||||||
|
...i,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: i.data,
|
|
||||||
name: i.name,
|
|
||||||
smooth: true,
|
smooth: true,
|
||||||
connectNulls: true,
|
connectNulls: true,
|
||||||
legendHoverLink: false,
|
legendHoverLink: false,
|
||||||
|
|||||||
@ -43,6 +43,42 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="monitor-cate-group">
|
||||||
|
<div
|
||||||
|
v-for="cateItem in monitorChartData.cateList"
|
||||||
|
:key="cateItem.id"
|
||||||
|
class="monitor-cate-item"
|
||||||
|
:class="{
|
||||||
|
disabled: showCates[cateItem.id] === false,
|
||||||
|
}"
|
||||||
|
:style="{
|
||||||
|
'--cate-color': cateItem.color,
|
||||||
|
}"
|
||||||
|
:title="cateItem.title"
|
||||||
|
@click="toggleShowCate(cateItem.id)"
|
||||||
|
>
|
||||||
|
<span class="cate-legend" />
|
||||||
|
<span
|
||||||
|
class="cate-name"
|
||||||
|
>
|
||||||
|
{{ cateItem.name }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="cateItem.avg !== 0"
|
||||||
|
class="cate-avg-ms"
|
||||||
|
>
|
||||||
|
{{ cateItem.avg }}ms
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-else
|
||||||
|
class="cate-avg-ms"
|
||||||
|
>
|
||||||
|
-ms
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<line-chart
|
<line-chart
|
||||||
:cate-list="monitorChartData.cateList"
|
:cate-list="monitorChartData.cateList"
|
||||||
:date-list="monitorChartData.dateList"
|
:date-list="monitorChartData.dateList"
|
||||||
@ -63,11 +99,13 @@ import {
|
|||||||
} from 'vue';
|
} from 'vue';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
import validate from '@/utils/validate';
|
||||||
|
|
||||||
import LineChart from '@/components/charts/line.vue';
|
import LineChart from '@/components/charts/line.vue';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getThreshold,
|
getThreshold,
|
||||||
|
getLineColor,
|
||||||
} from '@/views/composable/server-monitor';
|
} from '@/views/composable/server-monitor';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -79,6 +117,7 @@ const props = defineProps({
|
|||||||
|
|
||||||
const refreshData = ref(true);
|
const refreshData = ref(true);
|
||||||
const peakShaving = ref(false);
|
const peakShaving = ref(false);
|
||||||
|
const showCates = ref({});
|
||||||
|
|
||||||
const monitorData = ref([]);
|
const monitorData = ref([]);
|
||||||
|
|
||||||
@ -105,6 +144,7 @@ const monitorChartData = computed(() => {
|
|||||||
const dateMap = {};
|
const dateMap = {};
|
||||||
if (!cateMap[i.monitor_name]) {
|
if (!cateMap[i.monitor_name]) {
|
||||||
cateMap[i.monitor_name] = {
|
cateMap[i.monitor_name] = {
|
||||||
|
id: i.monitor_id,
|
||||||
dateMap,
|
dateMap,
|
||||||
avgs: [],
|
avgs: [],
|
||||||
};
|
};
|
||||||
@ -132,10 +172,11 @@ const monitorChartData = computed(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
let dateList = [];
|
let dateList = [];
|
||||||
|
let valueList = [];
|
||||||
const cateList = [];
|
const cateList = [];
|
||||||
const valueList = [];
|
|
||||||
Object.keys(cateMap).forEach((i) => {
|
Object.keys(cateMap).forEach((i) => {
|
||||||
const {
|
const {
|
||||||
|
id,
|
||||||
dateMap,
|
dateMap,
|
||||||
avgs,
|
avgs,
|
||||||
} = cateMap[i];
|
} = cateMap[i];
|
||||||
@ -144,16 +185,44 @@ const monitorChartData = computed(() => {
|
|||||||
avgs.push([time, value]);
|
avgs.push([time, value]);
|
||||||
dateList.push(time);
|
dateList.push(time);
|
||||||
});
|
});
|
||||||
valueList.push({
|
const color = getLineColor(id);
|
||||||
name: i,
|
|
||||||
data: avgs,
|
|
||||||
});
|
|
||||||
if (avgs.length) {
|
if (avgs.length) {
|
||||||
cateList.push(i);
|
if (!validate.hasOwn(showCates.value, id)) {
|
||||||
|
showCates.value[id] = true;
|
||||||
|
}
|
||||||
|
const cateItem = {
|
||||||
|
id,
|
||||||
|
name: i,
|
||||||
|
color,
|
||||||
|
avg: (avgs.reduce((a, b) => a + b[1], 0) / avgs.length).toFixed(2) * 1,
|
||||||
|
over: ((avgs.filter((o) => o[1] > 0).length / avgs.length) * 100).toFixed(2) * 1,
|
||||||
|
};
|
||||||
|
if (Number.isNaN(cateItem.avg)) {
|
||||||
|
cateItem.avg = 0;
|
||||||
|
}
|
||||||
|
const titles = [
|
||||||
|
cateItem.name,
|
||||||
|
`平均延迟:${cateItem.avg}ms`,
|
||||||
|
`执行成功:${cateItem.over}%`,
|
||||||
|
];
|
||||||
|
cateItem.title = titles.join('\n');
|
||||||
|
cateList.push(cateItem);
|
||||||
|
valueList.push({
|
||||||
|
id,
|
||||||
|
name: i,
|
||||||
|
data: avgs,
|
||||||
|
itemStyle: {
|
||||||
|
color,
|
||||||
|
},
|
||||||
|
lineStyle: {
|
||||||
|
color,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 去重
|
// 去重
|
||||||
dateList = Array.from(new Set(dateList)).sort((a, b) => a - b);
|
dateList = Array.from(new Set(dateList)).sort((a, b) => a - b);
|
||||||
|
valueList = valueList.filter((i) => showCates.value[i.id]);
|
||||||
return {
|
return {
|
||||||
dateList,
|
dateList,
|
||||||
cateList,
|
cateList,
|
||||||
@ -169,6 +238,10 @@ function switchRefresh() {
|
|||||||
refreshData.value = !refreshData.value;
|
refreshData.value = !refreshData.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toggleShowCate(id) {
|
||||||
|
showCates.value[id] = !showCates.value[id];
|
||||||
|
}
|
||||||
|
|
||||||
async function loadMonitor() {
|
async function loadMonitor() {
|
||||||
await request({
|
await request({
|
||||||
url: (
|
url: (
|
||||||
@ -221,7 +294,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.server-monitor-group {
|
.server-monitor-group {
|
||||||
--line-chart-size: 280px;
|
--line-chart-size: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module-head-group {
|
.module-head-group {
|
||||||
@ -288,4 +361,65 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.monitor-cate-group {
|
||||||
|
--gap-size: 0;
|
||||||
|
margin: 10px 0;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
// justify-content: center;
|
||||||
|
gap: var(--gap-size);
|
||||||
|
margin-right: calc(var(--gap-size) * -1);
|
||||||
|
|
||||||
|
.monitor-cate-item {
|
||||||
|
// --cate-item-width: calc(20% - var(--gap-size));
|
||||||
|
--cate-item-height: 28px;
|
||||||
|
--cate-item-font-size: 14px;
|
||||||
|
--cate-color: #fff;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: var(--cate-item-width);
|
||||||
|
height: var(--cate-item-height);
|
||||||
|
gap: 6px;
|
||||||
|
padding: 0 6px;
|
||||||
|
font-size: var(--cate-item-font-size);
|
||||||
|
// background: rgba(#fff, 0.2);
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
.cate-legend {
|
||||||
|
width: 0.5em;
|
||||||
|
height: 0.5em;
|
||||||
|
// border-radius: 50%;
|
||||||
|
// width: 6px;
|
||||||
|
// height: calc(var(--cate-item-height) - 10px);
|
||||||
|
// margin-left: -6px;
|
||||||
|
background: var(--cate-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cate-name {
|
||||||
|
// flex: 1;
|
||||||
|
height: var(--cate-item-height);
|
||||||
|
line-height: calc(var(--cate-item-height) + 2px);
|
||||||
|
// text-overflow: ellipsis;
|
||||||
|
// white-space: nowrap;
|
||||||
|
// overflow: hidden;
|
||||||
|
color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cate-avg-ms {
|
||||||
|
// width: 55px;
|
||||||
|
height: var(--cate-item-height);
|
||||||
|
line-height: calc(var(--cate-item-height) + 2px);
|
||||||
|
text-align: right;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.disabled {
|
||||||
|
filter: grayscale(1);
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import uniqolor from 'uniqolor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计算数据的阈值和平均值
|
* 计算数据的阈值和平均值
|
||||||
*
|
*
|
||||||
@ -30,3 +32,20 @@ export function getThreshold(data, tolerance = 2) {
|
|||||||
max,
|
max,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const lineNameColorMap = {};
|
||||||
|
const lineColorNameMap = {};
|
||||||
|
|
||||||
|
export function getLineColor(name) {
|
||||||
|
if (lineNameColorMap[name]) {
|
||||||
|
return lineNameColorMap[name];
|
||||||
|
}
|
||||||
|
const { color } = uniqolor.random({
|
||||||
|
saturation: [75, 90],
|
||||||
|
lightness: [65, 70],
|
||||||
|
differencePoint: 100,
|
||||||
|
});
|
||||||
|
lineNameColorMap[name] = color;
|
||||||
|
lineColorNameMap[color] = name;
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|||||||
@ -2900,6 +2900,11 @@ unbox-primitive@^1.0.2:
|
|||||||
has-symbols "^1.0.3"
|
has-symbols "^1.0.3"
|
||||||
which-boxed-primitive "^1.0.2"
|
which-boxed-primitive "^1.0.2"
|
||||||
|
|
||||||
|
uniqolor@^1.1.1:
|
||||||
|
version "1.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/uniqolor/-/uniqolor-1.1.1.tgz#ef35e41d930d31b90228a18d82dd151b8106b2f3"
|
||||||
|
integrity sha512-HUwezlXCwm5bzsEXW7AP7ybezH13uWENRgYT+3dOdhJPvpYucSqvIGckMiLn+Uy2j0NVf3fPp43uZ4aun3t4Ww==
|
||||||
|
|
||||||
update-browserslist-db@^1.1.1:
|
update-browserslist-db@^1.1.1:
|
||||||
version "1.1.1"
|
version "1.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz#80846fba1d79e82547fb661f8d141e0945755fe5"
|
resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz#80846fba1d79e82547fb661f8d141e0945755fe5"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user