ffplayout/components/SystemStats.vue

161 lines
5.9 KiB
Vue
Raw Normal View History

2023-11-16 06:44:12 -05:00
<template>
2024-04-25 08:49:57 -04:00
<!-- <div v-if="data">{{ systemStatus(data) }}</div> -->
<div class="grid grid-cols-1 xs:grid-cols-2 border-4 rounded-md border-primary text-left shadow min-w-[728px] max-w-[960px]">
2024-04-08 03:35:31 -04:00
<div class="p-4 bg-base-100">
<span class="text-3xl">{{ sysStat.system.name }} {{ sysStat.system.version }}</span>
<span v-if="sysStat.system.kernel">
<br />
2024-04-08 03:35:31 -04:00
{{ sysStat.system.kernel }}
</span>
</div>
<div class="p-4 bg-base-100 flex items-center">
<span v-if="sysStat.system.ffp_version">
2024-04-11 15:34:03 -04:00
<strong>ffplayout:</strong>
v{{ sysStat.system.ffp_version }}
2024-04-08 03:35:31 -04:00
</span>
2023-11-16 09:45:46 -05:00
</div>
2024-04-04 17:28:25 -04:00
<div class="p-4 border border-primary">
<div class="text-xl">{{ t('system.cpu') }}</div>
2024-04-17 06:32:07 -04:00
<div class="grid grid-cols-2 gap-2">
<div>
<strong>{{ t('system.cores') }}:</strong> {{ sysStat.cpu.cores }}
</div>
<div>
<strong>{{ t('system.usage') }}:</strong> {{ sysStat.cpu.usage.toFixed(2) }}%
</div>
2023-11-16 09:45:46 -05:00
</div>
</div>
2024-04-04 17:28:25 -04:00
<div class="p-4 border border-primary">
<div class="text-xl">{{ t('system.load') }}</div>
2024-04-17 06:32:07 -04:00
<div class="grid grid-cols-3 gap-2">
2024-04-04 17:28:25 -04:00
<div>{{ sysStat.load.one }}</div>
<div>{{ sysStat.load.five }}</div>
<div>{{ sysStat.load.fifteen }}</div>
2023-11-16 09:45:46 -05:00
</div>
</div>
2024-04-04 17:28:25 -04:00
<div class="p-4 border border-primary">
<div class="text-xl">{{ t('system.memory') }}</div>
2024-04-17 06:32:07 -04:00
<div class="grid grid-cols-2 gap-2">
<div>
<strong>{{ t('system.total') }}:</strong> {{ fileSize(sysStat.memory.total) }}
</div>
<div>
<strong>{{ t('system.usage') }}:</strong> {{ fileSize(sysStat.memory.used) }}
</div>
2023-11-16 09:45:46 -05:00
</div>
</div>
2024-04-04 17:28:25 -04:00
<div class="p-4 border border-primary">
<div class="text-xl">{{ t('system.swap') }}</div>
2024-04-17 06:32:07 -04:00
<div class="grid grid-cols-2 gap-2">
<div>
<strong>{{ t('system.total') }}:</strong> {{ fileSize(sysStat.swap.total) }}
</div>
<div>
<strong>{{ t('system.usage') }}:</strong> {{ fileSize(sysStat.swap.used) }}
</div>
2023-11-16 09:45:46 -05:00
</div>
</div>
2024-04-04 17:28:25 -04:00
<div class="p-4 border border-primary">
<div class="text-xl">
{{ t('system.network') }} <span v-if="sysStat.network" class="fs-6">{{ sysStat.network?.name }}</span>
2023-11-16 09:45:46 -05:00
</div>
2024-04-17 06:32:07 -04:00
<div class="grid grid-cols-2 gap-2">
<div>
<strong>{{ t('system.in') }}:</strong> {{ fileSize(sysStat.network?.current_in) }}
</div>
<div>
<strong>{{ t('system.out') }}:</strong> {{ fileSize(sysStat.network?.current_out) }}
</div>
2024-04-04 17:28:25 -04:00
<div>{{ fileSize(sysStat.network?.total_in) }}</div>
<div>{{ fileSize(sysStat.network?.total_out) }}</div>
2023-11-16 09:45:46 -05:00
</div>
</div>
2024-04-04 17:28:25 -04:00
<div v-if="sysStat.storage?.path" class="p-4 border border-primary">
<div class="text-xl">{{ t('system.storage') }}</div>
2023-11-16 09:45:46 -05:00
2024-04-17 06:32:07 -04:00
<div v-if="sysStat.storage" class="grid grid-cols-2 gap-2">
<div v-if="sysStat.storage" class="col-span-2">
<strong>{{ t('system.device') }}:</strong> {{ sysStat.storage?.path }}
2024-04-17 06:32:07 -04:00
</div>
<div>
<strong>{{ t('system.size') }}:</strong> {{ fileSize(sysStat.storage?.total) }}
</div>
<div>
<strong>{{ t('system.used') }}:</strong> {{ fileSize(sysStat.storage?.used) }}
</div>
2023-11-16 09:45:46 -05:00
</div>
2023-11-16 06:44:12 -05:00
</div>
<div v-else class="col-6 bg-primary p-2 border" />
2023-11-16 06:44:12 -05:00
</div>
</template>
<script setup lang="ts">
const { fileSize } = stringFormatter()
const { t } = useI18n()
2023-11-16 06:44:12 -05:00
const authStore = useAuth()
const configStore = useConfig()
2024-04-25 08:49:57 -04:00
const indexStore = useIndex()
const streamUrl = ref(
`/data/event/${configStore.channels[configStore.id].id}?endpoint=system&uuid=${authStore.uuid}`
2024-04-25 08:49:57 -04:00
)
// 'http://127.0.0.1:8787/data/event/1?endpoint=system&uuid=f2f8c29b-712a-48c5-8919-b535d3a05a3a'
const { status, data, error, close } = useEventSource(streamUrl, [], {
autoReconnect: {
retries: -1,
delay: 1000,
onFailed() {
indexStore.sseConnected = false
},
},
})
const errorCounter = ref(0)
const defaultStat = {
cpu: { cores: 1, usage: 0.0 },
2023-11-16 09:45:46 -05:00
load: { one: 0.0, five: 0.0, fifteen: 0.0 },
memory: { total: 0.0, used: 0.0, free: 0.0 },
2024-04-25 08:49:57 -04:00
network: { name: '...', current_in: 0.0, current_out: 0.0, total_in: 0.0, total_out: 0.0 },
2023-11-16 09:45:46 -05:00
storage: { path: '', total: 0.0, used: 0.0 },
swap: { total: 0.0, used: 0.0, free: 0.0 },
2024-04-25 08:49:57 -04:00
system: { name: '...', kernel: '...', version: '...', ffp_version: '...' },
} as SystemStatistics
2023-11-16 06:44:12 -05:00
2024-04-25 08:49:57 -04:00
const sysStat = ref(defaultStat)
2023-11-16 06:44:12 -05:00
onBeforeUnmount(() => {
2024-04-25 08:49:57 -04:00
close()
indexStore.sseConnected = false
2023-11-16 06:44:12 -05:00
})
2024-04-25 08:49:57 -04:00
watch([status, error], async () => {
if (status.value === 'OPEN') {
indexStore.sseConnected = true
errorCounter.value = 0
} else {
indexStore.sseConnected = false
errorCounter.value += 1
sysStat.value = defaultStat
2023-11-16 06:44:12 -05:00
2024-04-25 08:49:57 -04:00
if (errorCounter.value > 15) {
await authStore.obtainUuid()
streamUrl.value = `/data/event/${configStore.channels[configStore.id].id}?endpoint=system&uuid=${
2024-04-25 08:49:57 -04:00
authStore.uuid
}`
errorCounter.value = 0
}
2023-11-16 06:44:12 -05:00
}
2024-04-25 08:49:57 -04:00
})
2023-11-16 06:44:12 -05:00
2024-04-25 08:49:57 -04:00
watch([data], () => {
if (data.value) {
try {
sysStat.value = JSON.parse(data.value)
} catch {
2024-04-25 08:49:57 -04:00
indexStore.sseConnected = true
}
}
2024-04-25 08:49:57 -04:00
})
2023-11-16 06:44:12 -05:00
</script>