Compare commits
10 Commits
e52fbaf799
...
v1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2f2e8f255 | ||
| 5cfafa88cf | |||
| 656917c776 | |||
| 90fd395a26 | |||
| 35cfcb1bcf | |||
| 92ed9b040f | |||
| 7643600196 | |||
| b6375b4242 | |||
| 9393abc8df | |||
| 31e101abbd |
8
.env.example
Normal file
8
.env.example
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
API_SECRET_KEY=
|
||||||
|
DISCORD_BOT_TOKEN=
|
||||||
|
DISCORD_CHANNEL_ID=
|
||||||
|
BACKUPS_REMOTE_HOST=
|
||||||
|
BACKUPS_REMOTE_ROOT=
|
||||||
|
BACKUPS_MAX_FILES=
|
||||||
|
DISK_COMMAND_REMOTE=
|
||||||
|
DISK_COMMAND_LOCAL=
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
# [1.3.0](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.4...v1.3.0) (2026-03-13)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add system metrics dashboard ([31e101a](https://gitea.malio.fr/MALIO-DEV/Supervisor/commit/31e101abbd3ed82c22770d840a4f7fd20de1c936))
|
||||||
|
|
||||||
## [1.2.4](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.3...v1.2.4) (2026-03-10)
|
## [1.2.4](https://gitea.malio.fr/MALIO-DEV/Supervisor/compare/v1.2.3...v1.2.4) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@
|
|||||||
import { computed, onMounted, ref } from "vue"
|
import { computed, onMounted, ref } from "vue"
|
||||||
import { Icon as IconifyIcon } from "@iconify/vue"
|
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||||
import { apiFetch } from "~/composables/useApiAuth"
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
import { useApiAuthHeader } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
type BackupScript = {
|
type BackupScript = {
|
||||||
key: string
|
key: string
|
||||||
@@ -119,6 +120,7 @@ const scripts = ref<BackupScript[]>([])
|
|||||||
const output = ref<string>("")
|
const output = ref<string>("")
|
||||||
const message = ref<string>("")
|
const message = ref<string>("")
|
||||||
const isError = ref(false)
|
const isError = ref(false)
|
||||||
|
const apiAuthHeader = useApiAuthHeader()
|
||||||
|
|
||||||
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
||||||
|
|
||||||
@@ -137,7 +139,7 @@ const loadScripts = async () => {
|
|||||||
try {
|
try {
|
||||||
const data = await apiFetch<BackupScriptListResponse>("/api/backup-script")
|
const data = await apiFetch<BackupScriptListResponse>("/api/backup-script")
|
||||||
scripts.value = data.scripts
|
scripts.value = data.scripts
|
||||||
} catch (error) {
|
} catch {
|
||||||
scripts.value = []
|
scripts.value = []
|
||||||
isError.value = true
|
isError.value = true
|
||||||
message.value = "Erreur lors de l'opération"
|
message.value = "Erreur lors de l'opération"
|
||||||
@@ -174,9 +176,21 @@ const runScript = async (key: string) => {
|
|||||||
isError: false,
|
isError: false,
|
||||||
downloadFolders: data.downloadFolders || []
|
downloadFolders: data.downloadFolders || []
|
||||||
})
|
})
|
||||||
} catch (error: any) {
|
} catch (error: unknown) {
|
||||||
isError.value = true
|
isError.value = true
|
||||||
message.value = error?.data?.statusMessage || "Erreur lors de l'opération"
|
const statusMessage =
|
||||||
|
typeof error === "object" &&
|
||||||
|
error !== null &&
|
||||||
|
"data" in error &&
|
||||||
|
typeof error.data === "object" &&
|
||||||
|
error.data !== null &&
|
||||||
|
"statusMessage" in error.data &&
|
||||||
|
typeof error.data.statusMessage === "string"
|
||||||
|
? error.data.statusMessage
|
||||||
|
: null
|
||||||
|
|
||||||
|
message.value = statusMessage || "Erreur lors de l'opération"
|
||||||
|
message.value = error?.data?.statusMessage || "Erreur execution script"
|
||||||
output.value = ""
|
output.value = ""
|
||||||
emit("result", {
|
emit("result", {
|
||||||
key,
|
key,
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
<h2 class="card-title">Speedtest</h2>
|
<h2 class="card-title">Speedtest</h2>
|
||||||
<button
|
<button
|
||||||
class="reload-btn"
|
class="reload-btn"
|
||||||
@click="runTests"
|
|
||||||
:disabled="isTesting"
|
:disabled="isTesting"
|
||||||
|
@click="runTests"
|
||||||
>
|
>
|
||||||
<IconifyIcon
|
<IconifyIcon
|
||||||
icon="mdi:reload"
|
icon="mdi:reload"
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-else
|
|
||||||
v-for="row in rows"
|
v-for="row in rows"
|
||||||
|
v-else
|
||||||
:key="`${row.label}-${row.url}`"
|
:key="`${row.label}-${row.url}`"
|
||||||
class="status-row"
|
class="status-row"
|
||||||
:class="row.status === 200 ? 'row-ok' : 'row-error'"
|
:class="row.status === 200 ? 'row-ok' : 'row-error'"
|
||||||
|
|||||||
333
components/SystemMetricsChart.vue
Normal file
333
components/SystemMetricsChart.vue
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
<template>
|
||||||
|
<section class="chart-card card-glow">
|
||||||
|
<div class="card-header">
|
||||||
|
<div>
|
||||||
|
<h2 class="card-title">Historique systeme</h2>
|
||||||
|
<p class="card-copy">CPU, RAM et debit reseau sur les derniers releves</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="toggle-group" role="radiogroup" aria-label="Metrique affichee">
|
||||||
|
<label
|
||||||
|
v-for="option in options"
|
||||||
|
:key="option.value"
|
||||||
|
class="toggle-pill"
|
||||||
|
:class="{ 'toggle-pill-active': selectedMetric === option.value }"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model="selectedMetric"
|
||||||
|
type="radio"
|
||||||
|
name="system-metric"
|
||||||
|
class="sr-only"
|
||||||
|
:value="option.value"
|
||||||
|
>
|
||||||
|
<span class="toggle-dot" :style="{ backgroundColor: option.color }" />
|
||||||
|
<span>{{ option.label }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="chart-shell">
|
||||||
|
<template v-if="loading && points.length === 0">
|
||||||
|
<div class="chart-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="chart-meta">
|
||||||
|
<div>
|
||||||
|
<span class="meta-label">Actuel</span>
|
||||||
|
<strong class="meta-value" :style="{ color: activeOption.color }">{{ formattedCurrentValue }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="meta-label">Pic</span>
|
||||||
|
<strong class="meta-value">{{ formattedPeakValue }}</strong>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="meta-label">Echelle</span>
|
||||||
|
<strong class="meta-value">{{ scaleLabel }}</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<svg
|
||||||
|
class="chart-svg"
|
||||||
|
viewBox="0 0 960 320"
|
||||||
|
preserveAspectRatio="none"
|
||||||
|
aria-label="Graphique des ressources"
|
||||||
|
>
|
||||||
|
<line
|
||||||
|
v-for="line in gridLines"
|
||||||
|
:key="line"
|
||||||
|
x1="0"
|
||||||
|
:y1="line"
|
||||||
|
x2="960"
|
||||||
|
:y2="line"
|
||||||
|
class="grid-line"
|
||||||
|
/>
|
||||||
|
<polyline
|
||||||
|
:points="polylinePoints"
|
||||||
|
class="chart-line"
|
||||||
|
:style="{ stroke: activeOption.color }"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {computed, ref, watch} from "vue"
|
||||||
|
|
||||||
|
type MetricKey = "cpu" | "ram" | "incoming" | "outgoing"
|
||||||
|
|
||||||
|
type SystemMetrics = {
|
||||||
|
cpuPercent: number
|
||||||
|
memoryPercent: number
|
||||||
|
totalMemory: number
|
||||||
|
usedMemory: number
|
||||||
|
incomingMbps: number
|
||||||
|
outgoingMbps: number
|
||||||
|
sampledAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type HistoryPoint = {
|
||||||
|
sampledAt: string
|
||||||
|
cpu: number
|
||||||
|
ram: number
|
||||||
|
incoming: number
|
||||||
|
outgoing: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
metrics: SystemMetrics | null
|
||||||
|
loading: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const selectedMetric = ref<MetricKey>("ram")
|
||||||
|
const history = ref<HistoryPoint[]>([])
|
||||||
|
const maxPoints = 40
|
||||||
|
|
||||||
|
const options: Array<{value: MetricKey; label: string; color: string}> = [
|
||||||
|
{value: "cpu", label: "CPU", color: "#5aa9ff"},
|
||||||
|
{value: "ram", label: "RAM", color: "#31c48d"},
|
||||||
|
{value: "incoming", label: "Entrant", color: "#f59e0b"},
|
||||||
|
{value: "outgoing", label: "Sortant", color: "#ef4444"}
|
||||||
|
]
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.metrics?.sampledAt,
|
||||||
|
() => {
|
||||||
|
if (!props.metrics) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
history.value = [
|
||||||
|
...history.value,
|
||||||
|
{
|
||||||
|
sampledAt: props.metrics.sampledAt,
|
||||||
|
cpu: props.metrics.cpuPercent,
|
||||||
|
ram: props.metrics.memoryPercent,
|
||||||
|
incoming: props.metrics.incomingMbps,
|
||||||
|
outgoing: props.metrics.outgoingMbps
|
||||||
|
}
|
||||||
|
].slice(-maxPoints)
|
||||||
|
},
|
||||||
|
{immediate: true}
|
||||||
|
)
|
||||||
|
|
||||||
|
const activeOption = computed(() => {
|
||||||
|
return options.find((option) => option.value === selectedMetric.value) || options[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
const points = computed(() => history.value.map((point) => point[selectedMetric.value]))
|
||||||
|
|
||||||
|
const peakValue = computed(() => {
|
||||||
|
return points.value.reduce((max, value) => Math.max(max, value), 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
const scaleMax = computed(() => {
|
||||||
|
if (selectedMetric.value === "cpu" || selectedMetric.value === "ram") {
|
||||||
|
return 100
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(1, Math.ceil(peakValue.value))
|
||||||
|
})
|
||||||
|
|
||||||
|
const formatValue = (value: number, metric: MetricKey) => {
|
||||||
|
if (metric === "cpu" || metric === "ram") {
|
||||||
|
return `${Math.round(value)}%`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${value.toFixed(2)} Mbps`
|
||||||
|
}
|
||||||
|
|
||||||
|
const formattedCurrentValue = computed(() => {
|
||||||
|
const currentValue = points.value.at(-1) ?? 0
|
||||||
|
return formatValue(currentValue, selectedMetric.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const formattedPeakValue = computed(() => {
|
||||||
|
return formatValue(peakValue.value, selectedMetric.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const scaleLabel = computed(() => {
|
||||||
|
return formatValue(scaleMax.value, selectedMetric.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const gridLines = [40, 120, 200, 280]
|
||||||
|
|
||||||
|
const polylinePoints = computed(() => {
|
||||||
|
if (points.value.length === 0) {
|
||||||
|
return "0,280"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (points.value.length === 1) {
|
||||||
|
const normalizedValue = points.value[0] / scaleMax.value
|
||||||
|
const y = 280 - normalizedValue * 240
|
||||||
|
return `0,${y} 960,${y}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return points.value
|
||||||
|
.map((value, index) => {
|
||||||
|
const x = (index / (points.value.length - 1)) * 960
|
||||||
|
const normalizedValue = scaleMax.value > 0 ? value / scaleMax.value : 0
|
||||||
|
const y = 280 - normalizedValue * 240
|
||||||
|
|
||||||
|
return `${x},${Math.max(24, Math.min(280, y))}`
|
||||||
|
})
|
||||||
|
.join(" ")
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.chart-card {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-copy {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-group {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.625rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-pill {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.1);
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
padding: 0.55rem 0.8rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.72rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-pill-active {
|
||||||
|
border-color: rgb(var(--m-accent) / 0.28);
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toggle-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-shell {
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1rem;
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgb(var(--m-tertiary)) 0%, rgb(var(--m-secondary)) 100%);
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-meta {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.68rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.14em;
|
||||||
|
color: rgb(var(--m-muted));
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-value {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-svg {
|
||||||
|
width: 100%;
|
||||||
|
height: 320px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid-line {
|
||||||
|
stroke: rgb(var(--m-border) / 0.35);
|
||||||
|
stroke-width: 1;
|
||||||
|
stroke-dasharray: 6 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-line {
|
||||||
|
fill: none;
|
||||||
|
stroke-width: 4;
|
||||||
|
stroke-linecap: round;
|
||||||
|
stroke-linejoin: round;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chart-skeleton {
|
||||||
|
width: 100%;
|
||||||
|
height: 320px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 820px) {
|
||||||
|
.chart-meta {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
199
components/SystemResources.vue
Normal file
199
components/SystemResources.vue
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
<template>
|
||||||
|
<div class="resources-card card-glow">
|
||||||
|
<div class="card-header">
|
||||||
|
<h2 class="card-title">Ressources</h2>
|
||||||
|
<span class="font-mono text-[10px] uppercase tracking-widest text-m-muted">CPU / RAM</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="metrics-list">
|
||||||
|
<div
|
||||||
|
v-for="metric in metrics"
|
||||||
|
:key="metric.label"
|
||||||
|
class="metric-row"
|
||||||
|
>
|
||||||
|
<div class="metric-copy">
|
||||||
|
<div class="metric-head">
|
||||||
|
<span class="font-display text-sm font-semibold text-m-text">{{ metric.label }}</span>
|
||||||
|
<span class="font-mono text-xs text-m-muted">{{ metric.detail }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="isLoading">
|
||||||
|
<div class="metric-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="metric-bar">
|
||||||
|
<div
|
||||||
|
class="metric-bar-fill"
|
||||||
|
:class="metric.toneClass"
|
||||||
|
:style="{ width: `${metric.percent}%` }"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="metric-value-area">
|
||||||
|
<template v-if="isLoading">
|
||||||
|
<div class="value-skeleton animate-shimmer" />
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<span class="metric-value font-mono">{{ metric.percent }}%</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import {computed} from "vue"
|
||||||
|
|
||||||
|
type SystemMetrics = {
|
||||||
|
cpuPercent: number
|
||||||
|
memoryPercent: number
|
||||||
|
totalMemory: number
|
||||||
|
usedMemory: number
|
||||||
|
incomingMbps: number
|
||||||
|
outgoingMbps: number
|
||||||
|
sampledAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
metrics: SystemMetrics | null
|
||||||
|
loading: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const formatMemory = (value: number) => {
|
||||||
|
if (!Number.isFinite(value) || value <= 0) {
|
||||||
|
return "0 GB"
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${(value / 1024 / 1024 / 1024).toFixed(1)} GB`
|
||||||
|
}
|
||||||
|
|
||||||
|
const toneClass = (percent: number) => {
|
||||||
|
if (percent >= 85) return "tone-error"
|
||||||
|
if (percent >= 65) return "tone-warning"
|
||||||
|
return "tone-success"
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLoading = computed(() => props.loading || !props.metrics)
|
||||||
|
|
||||||
|
const metrics = computed(() => [
|
||||||
|
{
|
||||||
|
label: "CPU",
|
||||||
|
percent: props.metrics?.cpuPercent ?? 0,
|
||||||
|
detail: "Charge instantanee",
|
||||||
|
toneClass: toneClass(props.metrics?.cpuPercent ?? 0)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "RAM",
|
||||||
|
percent: props.metrics?.memoryPercent ?? 0,
|
||||||
|
detail: `${formatMemory(props.metrics?.usedMemory ?? 0)} / ${formatMemory(props.metrics?.totalMemory ?? 0)}`,
|
||||||
|
toneClass: toneClass(props.metrics?.memoryPercent ?? 0)
|
||||||
|
}
|
||||||
|
])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.resources-card {
|
||||||
|
background: rgb(var(--m-secondary));
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 1.25rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
transition: background-color 0.4s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.metrics-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) auto;
|
||||||
|
gap: 0.75rem;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.875rem 1rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: rgb(var(--m-tertiary));
|
||||||
|
border: 1px solid rgb(var(--m-accent) / 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-copy {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
margin-bottom: 0.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-bar {
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: rgb(var(--m-bg) / 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-bar-fill {
|
||||||
|
height: 100%;
|
||||||
|
border-radius: inherit;
|
||||||
|
transition: width 0.35s ease, background-color 0.35s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value-area {
|
||||||
|
min-width: 54px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-value {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: rgb(var(--m-text));
|
||||||
|
}
|
||||||
|
|
||||||
|
.metric-skeleton {
|
||||||
|
height: 10px;
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.value-skeleton {
|
||||||
|
width: 48px;
|
||||||
|
height: 28px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-success {
|
||||||
|
background: rgb(var(--m-success));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-warning {
|
||||||
|
background: rgb(var(--m-warning));
|
||||||
|
}
|
||||||
|
|
||||||
|
.tone-error {
|
||||||
|
background: rgb(var(--m-error));
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -32,14 +32,18 @@ function getDownloadFileName(contentDisposition: string | null, fallback: string
|
|||||||
return fallback
|
return fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withApiAuth(init: RequestInit = {}) {
|
export function useApiAuthHeader() {
|
||||||
// Les appels frontend reutilisent les cookies httpOnly poses cote serveur.
|
const runtimeConfig = useRuntimeConfig()
|
||||||
return {
|
const token = runtimeConfig.public.apiSecretKey
|
||||||
...init,
|
|
||||||
headers: {
|
if (!token) {
|
||||||
...toHeadersObject(init.headers)
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tous les appels frontend vers /api/* reutilisent ce header commun.
|
||||||
|
return {
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const apiFetch = $fetch.create({})
|
export const apiFetch = $fetch.create({})
|
||||||
@@ -73,3 +77,14 @@ export async function downloadApiFile(url: string, fileNameFallback: string) {
|
|||||||
link.remove()
|
link.remove()
|
||||||
URL.revokeObjectURL(objectUrl)
|
URL.revokeObjectURL(objectUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function withApiAuth(init: RequestInit = {}) {
|
||||||
|
// Fusionne le header d'auth avec d'eventuels headers deja fournis.
|
||||||
|
return {
|
||||||
|
...init,
|
||||||
|
headers: {
|
||||||
|
...useApiAuthHeader(),
|
||||||
|
...toHeadersObject(init.headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
3
eslint.config.mjs
Normal file
3
eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import createConfigForNuxt from "@nuxt/eslint-config"
|
||||||
|
|
||||||
|
export default createConfigForNuxt()
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
:src="logoSrc"
|
:src="logoSrc"
|
||||||
alt="Logo Malio"
|
alt="Logo Malio"
|
||||||
class="logo"
|
class="logo"
|
||||||
/>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="brand-copy">
|
<div class="brand-copy">
|
||||||
<p class="brand-title">Supervisor</p>
|
<p class="brand-title">Supervisor</p>
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
:src="logoSrc"
|
:src="logoSrc"
|
||||||
alt="Logo Malio"
|
alt="Logo Malio"
|
||||||
class="logo"
|
class="logo"
|
||||||
/>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="brand-copy">
|
<div class="brand-copy">
|
||||||
<p class="brand-kicker">Control Center</p>
|
<p class="brand-kicker">Control Center</p>
|
||||||
|
|||||||
3138
package-lock.json
generated
3138
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@@ -7,14 +7,14 @@
|
|||||||
"dev": "nuxt dev",
|
"dev": "nuxt dev",
|
||||||
"generate": "nuxt generate",
|
"generate": "nuxt generate",
|
||||||
"preview": "nuxt preview",
|
"preview": "nuxt preview",
|
||||||
"postinstall": "nuxt prepare"
|
"postinstall": "nuxt prepare",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify/vue": "^5.0.0",
|
"@iconify/vue": "^5.0.0",
|
||||||
"iconify": "^1.4.0",
|
"@nuxt/eslint": "^1.15.2",
|
||||||
"nuxt": "^4.3.1",
|
"nuxt": "^4.3.1"
|
||||||
"vue": "^3.5.29",
|
|
||||||
"vue-router": "^4.6.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
|
|||||||
@@ -33,9 +33,24 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid-middle">
|
<div class="grid-middle">
|
||||||
<Speedtest class="animate-fade-in-up speedtest-card-mobile" style="animation-delay: 150ms" />
|
<SpeedTest class="animate-fade-in-up speedtest-card-mobile" style="animation-delay: 150ms" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="metrics-row">
|
||||||
|
<SystemMetricsChart
|
||||||
|
:metrics="systemMetrics"
|
||||||
|
:loading="systemLoading"
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
style="animation-delay: 200ms"
|
||||||
|
/>
|
||||||
|
<SystemResources
|
||||||
|
:metrics="systemMetrics"
|
||||||
|
:loading="systemLoading"
|
||||||
|
class="animate-fade-in-up"
|
||||||
|
style="animation-delay: 225ms"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content-aside">
|
<div class="content-aside">
|
||||||
@@ -47,8 +62,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
definePageMeta({layout: false})
|
|
||||||
import {computed, onMounted, ref} from "vue"
|
import {computed, onMounted, ref} from "vue"
|
||||||
|
definePageMeta({layout: false})
|
||||||
import { apiFetch } from "~/composables/useApiAuth"
|
import { apiFetch } from "~/composables/useApiAuth"
|
||||||
|
|
||||||
type DiskSourceResult = {
|
type DiskSourceResult = {
|
||||||
@@ -75,11 +90,23 @@ type DiagramItem = {
|
|||||||
totalText: string
|
totalText: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedBackup = ref<string | null>(null)
|
type SystemMetrics = {
|
||||||
|
cpuPercent: number
|
||||||
|
memoryPercent: number
|
||||||
|
totalMemory: number
|
||||||
|
usedMemory: number
|
||||||
|
incomingMbps: number
|
||||||
|
outgoingMbps: number
|
||||||
|
sampledAt: string
|
||||||
|
}
|
||||||
|
|
||||||
const rawResults = ref<DiskSourceResult[]>([])
|
const rawResults = ref<DiskSourceResult[]>([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
const systemMetrics = ref<SystemMetrics | null>(null)
|
||||||
|
const systemLoading = ref(true)
|
||||||
const chartRadius = 52
|
const chartRadius = 52
|
||||||
const chartCircumference = 2 * Math.PI * chartRadius
|
const chartCircumference = 2 * Math.PI * chartRadius
|
||||||
|
let systemTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
const getHostName = (output: string, fallback: string) => {
|
const getHostName = (output: string, fallback: string) => {
|
||||||
const hostMatch = output.match(/Name:\s*(.+)/i)
|
const hostMatch = output.match(/Name:\s*(.+)/i)
|
||||||
@@ -168,8 +195,27 @@ const runScript = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const loadSystemMetrics = async () => {
|
||||||
|
try {
|
||||||
|
systemMetrics.value = await $fetch<SystemMetrics>("/api/system")
|
||||||
|
} catch {
|
||||||
|
systemMetrics.value = null
|
||||||
|
} finally {
|
||||||
|
systemLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
runScript()
|
runScript()
|
||||||
|
loadSystemMetrics()
|
||||||
|
systemTimer = setInterval(loadSystemMetrics, 2000)
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
if (systemTimer) {
|
||||||
|
clearInterval(systemTimer)
|
||||||
|
systemTimer = null
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -229,6 +275,14 @@ onMounted(() => {
|
|||||||
align-items: start;
|
align-items: start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.metrics-row {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) 280px;
|
||||||
|
gap: 1.5rem;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
.grid-left,
|
.grid-left,
|
||||||
.grid-middle,
|
.grid-middle,
|
||||||
.grid-right {
|
.grid-right {
|
||||||
@@ -260,7 +314,8 @@ onMounted(() => {
|
|||||||
|
|
||||||
.storage-grid,
|
.storage-grid,
|
||||||
.content-grid,
|
.content-grid,
|
||||||
.dashboard-grid {
|
.dashboard-grid,
|
||||||
|
.metrics-row {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { execFile } from "node:child_process"
|
import { execFile } from "node:child_process"
|
||||||
import folderMap from "../config/backup-folders.json"
|
import folderMap from "../config/backup-folders.json"
|
||||||
|
|
||||||
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b"
|
const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST
|
||||||
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups"
|
const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT
|
||||||
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES || "200")
|
const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES)
|
||||||
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value)
|
||||||
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'`
|
||||||
const FOLDER_MAP = folderMap as Record<string, string>
|
const FOLDER_MAP = folderMap as Record<string, string>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { execFile } from "child_process"
|
import { exec, execFile } from "child_process"
|
||||||
import diskSources from "../config/disk-commands.json"
|
import diskSources from "../config/disk-commands.json"
|
||||||
|
|
||||||
type DiskSource = {
|
type DiskSource = {
|
||||||
@@ -8,12 +8,12 @@ type DiskSource = {
|
|||||||
args?: string[]
|
args?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCommand(source: DiskSource) {
|
function getEnvCommand(source: DiskSource) {
|
||||||
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
||||||
const legacyEnvKey =
|
const legacyEnvKey =
|
||||||
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : ""
|
||||||
|
|
||||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || source.command
|
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
function runCommand(command: string, args: string[] = []): Promise<string> {
|
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||||
@@ -28,11 +28,26 @@ function runCommand(command: string, args: string[] = []): Promise<string> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runShellCommand(command: string): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
exec(command, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
reject(stderr || error.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolve(stdout)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async () => {
|
export default defineEventHandler(async () => {
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
(diskSources as DiskSource[]).map(async (source) => {
|
(diskSources as DiskSource[]).map(async (source) => {
|
||||||
try {
|
try {
|
||||||
const output = await runCommand(source.command, source.args || [])
|
const envCommand = getEnvCommand(source)
|
||||||
|
const output = envCommand
|
||||||
|
? await runShellCommand(envCommand)
|
||||||
|
: await runCommand(source.command, source.args || [])
|
||||||
return {
|
return {
|
||||||
key: source.key,
|
key: source.key,
|
||||||
label: source.label,
|
label: source.label,
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ function buildContentDisposition(fileName: string) {
|
|||||||
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
return `attachment; filename="${asciiName}"; filename*=UTF-8''${encodeURIComponent(fileName)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function speedtestStream(event: any) {
|
function speedtestStream(event: H3Event) {
|
||||||
const size = 128 * 1024 * 1024
|
const size = 128 * 1024 * 1024
|
||||||
let sent = 0
|
let sent = 0
|
||||||
|
|
||||||
|
|||||||
165
server/api/system.get.ts
Normal file
165
server/api/system.get.ts
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
import fs from "node:fs"
|
||||||
|
import os from "node:os"
|
||||||
|
|
||||||
|
type CpuTimesSnapshot = {
|
||||||
|
idle: number
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
|
||||||
|
type NetworkSnapshot = {
|
||||||
|
rxBytes: number
|
||||||
|
txBytes: number
|
||||||
|
timestamp: number
|
||||||
|
}
|
||||||
|
|
||||||
|
let previousNetworkSnapshot: NetworkSnapshot | null = null
|
||||||
|
|
||||||
|
function getCpuSnapshot(): CpuTimesSnapshot {
|
||||||
|
const cpus = os.cpus()
|
||||||
|
|
||||||
|
return cpus.reduce(
|
||||||
|
(snapshot, cpu) => {
|
||||||
|
const total = Object.values(cpu.times).reduce((sum, value) => sum + value, 0)
|
||||||
|
|
||||||
|
snapshot.idle += cpu.times.idle
|
||||||
|
snapshot.total += total
|
||||||
|
|
||||||
|
return snapshot
|
||||||
|
},
|
||||||
|
{idle: 0, total: 0}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function wait(durationMs: number) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
setTimeout(resolve, durationMs)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCpuUsagePercent(sampleMs: number) {
|
||||||
|
const start = getCpuSnapshot()
|
||||||
|
await wait(sampleMs)
|
||||||
|
const end = getCpuSnapshot()
|
||||||
|
|
||||||
|
const idleDelta = end.idle - start.idle
|
||||||
|
const totalDelta = end.total - start.total
|
||||||
|
|
||||||
|
if (totalDelta <= 0) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.max(0, Math.min(100, Math.round((1 - idleDelta / totalDelta) * 100)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNetworkTotals() {
|
||||||
|
try {
|
||||||
|
const content = fs.readFileSync("/proc/net/dev", "utf8")
|
||||||
|
const totals = content
|
||||||
|
.split("\n")
|
||||||
|
.slice(2)
|
||||||
|
.map((line) => line.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.reduce(
|
||||||
|
(accumulator, line) => {
|
||||||
|
const [namePart, valuesPart] = line.split(":")
|
||||||
|
const interfaceName = namePart?.trim()
|
||||||
|
|
||||||
|
if (!interfaceName || interfaceName === "lo" || !valuesPart) {
|
||||||
|
return accumulator
|
||||||
|
}
|
||||||
|
|
||||||
|
const values = valuesPart.trim().split(/\s+/)
|
||||||
|
const rxBytes = Number.parseInt(values[0] || "0", 10)
|
||||||
|
const txBytes = Number.parseInt(values[8] || "0", 10)
|
||||||
|
|
||||||
|
if (Number.isFinite(rxBytes)) {
|
||||||
|
accumulator.rxBytes += rxBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Number.isFinite(txBytes)) {
|
||||||
|
accumulator.txBytes += txBytes
|
||||||
|
}
|
||||||
|
|
||||||
|
return accumulator
|
||||||
|
},
|
||||||
|
{rxBytes: 0, txBytes: 0}
|
||||||
|
)
|
||||||
|
|
||||||
|
return totals
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNetworkRatesMbps() {
|
||||||
|
const totals = getNetworkTotals()
|
||||||
|
const now = Date.now()
|
||||||
|
|
||||||
|
if (!totals) {
|
||||||
|
previousNetworkSnapshot = null
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentSnapshot: NetworkSnapshot = {
|
||||||
|
...totals,
|
||||||
|
timestamp: now
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!previousNetworkSnapshot) {
|
||||||
|
previousNetworkSnapshot = currentSnapshot
|
||||||
|
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const elapsedSeconds = (currentSnapshot.timestamp - previousNetworkSnapshot.timestamp) / 1000
|
||||||
|
|
||||||
|
if (elapsedSeconds <= 0) {
|
||||||
|
previousNetworkSnapshot = currentSnapshot
|
||||||
|
|
||||||
|
return {
|
||||||
|
incomingMbps: 0,
|
||||||
|
outgoingMbps: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const incomingMbps = Math.max(
|
||||||
|
0,
|
||||||
|
Number((((currentSnapshot.rxBytes - previousNetworkSnapshot.rxBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||||
|
)
|
||||||
|
const outgoingMbps = Math.max(
|
||||||
|
0,
|
||||||
|
Number((((currentSnapshot.txBytes - previousNetworkSnapshot.txBytes) * 8) / elapsedSeconds / 1000000).toFixed(2))
|
||||||
|
)
|
||||||
|
|
||||||
|
previousNetworkSnapshot = currentSnapshot
|
||||||
|
|
||||||
|
return {
|
||||||
|
incomingMbps,
|
||||||
|
outgoingMbps
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineEventHandler(async () => {
|
||||||
|
const totalMemory = os.totalmem()
|
||||||
|
const freeMemory = os.freemem()
|
||||||
|
const usedMemory = totalMemory - freeMemory
|
||||||
|
const memoryPercent = totalMemory > 0 ? Math.round((usedMemory / totalMemory) * 100) : 0
|
||||||
|
const cpuPercent = await getCpuUsagePercent(200)
|
||||||
|
const {incomingMbps, outgoingMbps} = getNetworkRatesMbps()
|
||||||
|
|
||||||
|
return {
|
||||||
|
cpuPercent,
|
||||||
|
memoryPercent,
|
||||||
|
totalMemory,
|
||||||
|
usedMemory,
|
||||||
|
incomingMbps,
|
||||||
|
outgoingMbps,
|
||||||
|
sampledAt: new Date().toISOString()
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user