2021-01-03 06:38:32 -07:00
|
|
|
<template>
|
2023-04-07 18:01:42 -06:00
|
|
|
<div class="oxxrhrto">
|
|
|
|
<svg :viewBox="`0 0 ${viewBoxX} ${viewBoxY}`">
|
|
|
|
<polygon
|
|
|
|
:points="inPolygonPoints"
|
2023-04-26 16:10:33 -06:00
|
|
|
fill="#f6c177"
|
2023-04-07 18:01:42 -06:00
|
|
|
fill-opacity="0.5"
|
|
|
|
/>
|
|
|
|
<polyline
|
|
|
|
:points="inPolylinePoints"
|
|
|
|
fill="none"
|
2023-04-26 16:10:33 -06:00
|
|
|
stroke="#f6c177"
|
2023-04-07 18:01:42 -06:00
|
|
|
stroke-width="1"
|
|
|
|
/>
|
2023-04-26 16:10:33 -06:00
|
|
|
<circle :cx="inHeadX" :cy="inHeadY" r="1.5" fill="#f6c177" />
|
2023-04-07 18:01:42 -06:00
|
|
|
<text x="1" y="5">
|
|
|
|
NET rx
|
|
|
|
<tspan>{{ bytes(inRecent) }}</tspan>
|
|
|
|
</text>
|
|
|
|
</svg>
|
|
|
|
<svg :viewBox="`0 0 ${viewBoxX} ${viewBoxY}`">
|
|
|
|
<polygon
|
|
|
|
:points="outPolygonPoints"
|
2023-04-26 16:10:33 -06:00
|
|
|
fill="#31748f"
|
2023-04-07 18:01:42 -06:00
|
|
|
fill-opacity="0.5"
|
|
|
|
/>
|
|
|
|
<polyline
|
|
|
|
:points="outPolylinePoints"
|
|
|
|
fill="none"
|
2023-04-26 16:10:33 -06:00
|
|
|
stroke="#31748f"
|
2023-04-07 18:01:42 -06:00
|
|
|
stroke-width="1"
|
|
|
|
/>
|
2023-04-26 16:10:33 -06:00
|
|
|
<circle :cx="outHeadX" :cy="outHeadY" r="1.5" fill="#31748f" />
|
2023-04-07 18:01:42 -06:00
|
|
|
<text x="1" y="5">
|
|
|
|
NET tx
|
|
|
|
<tspan>{{ bytes(outRecent) }}</tspan>
|
|
|
|
</text>
|
|
|
|
</svg>
|
|
|
|
</div>
|
2021-01-03 06:38:32 -07:00
|
|
|
</template>
|
|
|
|
|
2022-05-25 01:43:12 -06:00
|
|
|
<script lang="ts" setup>
|
2023-04-07 18:01:42 -06:00
|
|
|
import { onMounted, onBeforeUnmount } from "vue";
|
|
|
|
import bytes from "@/filters/bytes";
|
2021-01-03 06:38:32 -07:00
|
|
|
|
2022-05-25 01:43:12 -06:00
|
|
|
const props = defineProps<{
|
2023-04-07 18:01:42 -06:00
|
|
|
connection: any;
|
|
|
|
meta: any;
|
2022-05-25 01:43:12 -06:00
|
|
|
}>();
|
|
|
|
|
|
|
|
let viewBoxX: number = $ref(50);
|
|
|
|
let viewBoxY: number = $ref(30);
|
|
|
|
let stats: any[] = $ref([]);
|
2023-04-07 18:01:42 -06:00
|
|
|
let inPolylinePoints: string = $ref("");
|
|
|
|
let outPolylinePoints: string = $ref("");
|
|
|
|
let inPolygonPoints: string = $ref("");
|
|
|
|
let outPolygonPoints: string = $ref("");
|
2022-05-25 01:43:12 -06:00
|
|
|
let inHeadX: any = $ref(null);
|
|
|
|
let inHeadY: any = $ref(null);
|
|
|
|
let outHeadX: any = $ref(null);
|
|
|
|
let outHeadY: any = $ref(null);
|
|
|
|
let inRecent: number = $ref(0);
|
|
|
|
let outRecent: number = $ref(0);
|
|
|
|
|
|
|
|
onMounted(() => {
|
2023-04-07 18:01:42 -06:00
|
|
|
props.connection.on("stats", onStats);
|
|
|
|
props.connection.on("statsLog", onStatsLog);
|
|
|
|
props.connection.send("requestLog", {
|
|
|
|
id: Math.random().toString().substr(2, 8),
|
2022-05-25 01:43:12 -06:00
|
|
|
});
|
2021-01-03 06:38:32 -07:00
|
|
|
});
|
2022-05-25 01:43:12 -06:00
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
2023-04-07 18:01:42 -06:00
|
|
|
props.connection.off("stats", onStats);
|
|
|
|
props.connection.off("statsLog", onStatsLog);
|
2022-05-25 01:43:12 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
function onStats(connStats) {
|
|
|
|
stats.push(connStats);
|
|
|
|
if (stats.length > 50) stats.shift();
|
|
|
|
|
2023-04-07 18:01:42 -06:00
|
|
|
const inPeak = Math.max(1024 * 64, Math.max(...stats.map((s) => s.net.rx)));
|
|
|
|
const outPeak = Math.max(
|
|
|
|
1024 * 64,
|
|
|
|
Math.max(...stats.map((s) => s.net.tx))
|
|
|
|
);
|
|
|
|
|
|
|
|
let inPolylinePointsStats = stats.map((s, i) => [
|
|
|
|
viewBoxX - (stats.length - 1 - i),
|
|
|
|
(1 - s.net.rx / inPeak) * viewBoxY,
|
|
|
|
]);
|
|
|
|
let outPolylinePointsStats = stats.map((s, i) => [
|
|
|
|
viewBoxX - (stats.length - 1 - i),
|
|
|
|
(1 - s.net.tx / outPeak) * viewBoxY,
|
|
|
|
]);
|
|
|
|
inPolylinePoints = inPolylinePointsStats
|
|
|
|
.map((xy) => `${xy[0]},${xy[1]}`)
|
|
|
|
.join(" ");
|
|
|
|
outPolylinePoints = outPolylinePointsStats
|
|
|
|
.map((xy) => `${xy[0]},${xy[1]}`)
|
|
|
|
.join(" ");
|
|
|
|
|
|
|
|
inPolygonPoints = `${
|
|
|
|
viewBoxX - (stats.length - 1)
|
|
|
|
},${viewBoxY} ${inPolylinePoints} ${viewBoxX},${viewBoxY}`;
|
|
|
|
outPolygonPoints = `${
|
|
|
|
viewBoxX - (stats.length - 1)
|
|
|
|
},${viewBoxY} ${outPolylinePoints} ${viewBoxX},${viewBoxY}`;
|
2022-05-25 01:43:12 -06:00
|
|
|
|
2022-06-01 00:51:00 -06:00
|
|
|
inHeadX = inPolylinePointsStats[inPolylinePointsStats.length - 1][0];
|
|
|
|
inHeadY = inPolylinePointsStats[inPolylinePointsStats.length - 1][1];
|
|
|
|
outHeadX = outPolylinePointsStats[outPolylinePointsStats.length - 1][0];
|
|
|
|
outHeadY = outPolylinePointsStats[outPolylinePointsStats.length - 1][1];
|
2022-05-25 01:43:12 -06:00
|
|
|
|
|
|
|
inRecent = connStats.net.rx;
|
|
|
|
outRecent = connStats.net.tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStatsLog(statsLog) {
|
|
|
|
for (const revStats of [...statsLog].reverse()) {
|
|
|
|
onStats(revStats);
|
|
|
|
}
|
|
|
|
}
|
2021-01-03 06:38:32 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.oxxrhrto {
|
|
|
|
display: flex;
|
|
|
|
|
|
|
|
> svg {
|
|
|
|
display: block;
|
|
|
|
padding: 10px;
|
|
|
|
width: 50%;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
padding-right: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
padding-left: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> text {
|
|
|
|
font-size: 5px;
|
|
|
|
fill: currentColor;
|
|
|
|
|
|
|
|
> tspan {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|