2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-01-03 14:38:32 +01:00
|
|
|
<template>
|
|
|
|
<div class="oxxrhrto">
|
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
|
|
|
<polygon
|
|
|
|
:points="inPolygonPoints"
|
|
|
|
fill="#94a029"
|
|
|
|
fill-opacity="0.5"
|
|
|
|
/>
|
|
|
|
<polyline
|
|
|
|
:points="inPolylinePoints"
|
|
|
|
fill="none"
|
|
|
|
stroke="#94a029"
|
|
|
|
stroke-width="1"
|
|
|
|
/>
|
|
|
|
<circle
|
|
|
|
:cx="inHeadX"
|
|
|
|
:cy="inHeadY"
|
|
|
|
r="1.5"
|
|
|
|
fill="#94a029"
|
|
|
|
/>
|
|
|
|
<text x="1" y="5">NET rx <tspan>{{ bytes(inRecent) }}</tspan></text>
|
|
|
|
</svg>
|
|
|
|
<svg :viewBox="`0 0 ${ viewBoxX } ${ viewBoxY }`">
|
|
|
|
<polygon
|
|
|
|
:points="outPolygonPoints"
|
|
|
|
fill="#ff9156"
|
|
|
|
fill-opacity="0.5"
|
|
|
|
/>
|
|
|
|
<polyline
|
|
|
|
:points="outPolylinePoints"
|
|
|
|
fill="none"
|
|
|
|
stroke="#ff9156"
|
|
|
|
stroke-width="1"
|
|
|
|
/>
|
|
|
|
<circle
|
|
|
|
:cx="outHeadX"
|
|
|
|
:cy="outHeadY"
|
|
|
|
r="1.5"
|
|
|
|
fill="#ff9156"
|
|
|
|
/>
|
|
|
|
<text x="1" y="5">NET tx <tspan>{{ bytes(outRecent) }}</tspan></text>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-05-25 09:43:12 +02:00
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { onMounted, onBeforeUnmount, ref } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import bytes from '@/filters/bytes.js';
|
2021-01-03 14:38:32 +01:00
|
|
|
|
2022-05-25 09:43:12 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
connection: any,
|
|
|
|
meta: any
|
|
|
|
}>();
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const viewBoxX = ref<number>(50);
|
|
|
|
const viewBoxY = ref<number>(30);
|
|
|
|
const stats = ref<any[]>([]);
|
|
|
|
const inPolylinePoints = ref<string>('');
|
|
|
|
const outPolylinePoints = ref<string>('');
|
|
|
|
const inPolygonPoints = ref<string>('');
|
|
|
|
const outPolygonPoints = ref<string>('');
|
|
|
|
const inHeadX = ref<any>(null);
|
|
|
|
const inHeadY = ref<any>(null);
|
|
|
|
const outHeadX = ref<any>(null);
|
|
|
|
const outHeadY = ref<any>(null);
|
|
|
|
const inRecent = ref<number>(0);
|
|
|
|
const outRecent = ref<number>(0);
|
2022-05-25 09:43:12 +02:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
props.connection.on('stats', onStats);
|
|
|
|
props.connection.on('statsLog', onStatsLog);
|
|
|
|
props.connection.send('requestLog', {
|
2023-07-14 00:59:54 +02:00
|
|
|
id: Math.random().toString().substring(2, 10),
|
2022-05-25 09:43:12 +02:00
|
|
|
});
|
2021-01-03 14:38:32 +01:00
|
|
|
});
|
2022-05-25 09:43:12 +02:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
props.connection.off('stats', onStats);
|
|
|
|
props.connection.off('statsLog', onStatsLog);
|
|
|
|
});
|
|
|
|
|
|
|
|
function onStats(connStats) {
|
2023-12-07 06:42:09 +01:00
|
|
|
stats.value.push(connStats);
|
|
|
|
if (stats.value.length > 50) stats.value.shift();
|
2022-05-25 09:43:12 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const inPeak = Math.max(1024 * 64, Math.max(...stats.value.map(s => s.net.rx)));
|
|
|
|
const outPeak = Math.max(1024 * 64, Math.max(...stats.value.map(s => s.net.tx)));
|
2022-05-25 09:43:12 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
let inPolylinePointsStats = stats.value.map((s, i) => [viewBoxX.value - ((stats.value.length - 1) - i), (1 - (s.net.rx / inPeak)) * viewBoxY.value]);
|
|
|
|
let outPolylinePointsStats = stats.value.map((s, i) => [viewBoxX.value - ((stats.value.length - 1) - i), (1 - (s.net.tx / outPeak)) * viewBoxY.value]);
|
|
|
|
inPolylinePoints.value = inPolylinePointsStats.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
|
|
|
outPolylinePoints.value = outPolylinePointsStats.map(xy => `${xy[0]},${xy[1]}`).join(' ');
|
2022-05-25 09:43:12 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
inPolygonPoints.value = `${viewBoxX.value - (stats.value.length - 1)},${viewBoxY.value} ${inPolylinePoints.value} ${viewBoxX.value},${viewBoxY.value}`;
|
|
|
|
outPolygonPoints.value = `${viewBoxX.value - (stats.value.length - 1)},${viewBoxY.value} ${outPolylinePoints.value} ${viewBoxX.value},${viewBoxY.value}`;
|
2022-05-25 09:43:12 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
inHeadX.value = inPolylinePointsStats.at(-1)![0];
|
|
|
|
inHeadY.value = inPolylinePointsStats.at(-1)![1];
|
|
|
|
outHeadX.value = outPolylinePointsStats.at(-1)![0];
|
|
|
|
outHeadY.value = outPolylinePointsStats.at(-1)![1];
|
2022-05-25 09:43:12 +02:00
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
inRecent.value = connStats.net.rx;
|
|
|
|
outRecent.value = connStats.net.tx;
|
2022-05-25 09:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onStatsLog(statsLog) {
|
|
|
|
for (const revStats of [...statsLog].reverse()) {
|
|
|
|
onStats(revStats);
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 14:38:32 +01:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 10:29:39 +01:00
|
|
|
<style lang="scss" scoped>
|
2021-01-03 14:38:32 +01:00
|
|
|
.oxxrhrto {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> svg {
|
|
|
|
display: block;
|
|
|
|
padding: 10px;
|
|
|
|
width: 50%;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
padding-right: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
padding-left: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> text {
|
2022-12-10 08:48:45 +01:00
|
|
|
font-size: 4.5px;
|
2021-01-03 14:38:32 +01:00
|
|
|
fill: currentColor;
|
|
|
|
|
|
|
|
> tspan {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|