Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (backendStore.backendUrl) {
settingsStore.init();
automationStore.init();
devicesStore.init();
healthStore.init();
healthStore.init(io);
});
io.on("disconnect", () => backendStore.setServerOnline(false));

Expand Down
2 changes: 1 addition & 1 deletion src/components/automation/MonacoEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface Device
{
getDeviceId: string
getAttribute(attrName: string): Promise<DeviceAttribute | undefined>
setAttribute(attrName: string, value: DeviceAttributeValue): void
setAttribute(attrName: string, value: DeviceAttributeValue): Promise<void>
}
enum DeviceEventType {
deviceUpdateReceived = "deviceUpdateReceived",
Expand Down
34 changes: 12 additions & 22 deletions src/stores/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { defineStore } from "pinia";
import { ref, reactive, type Ref } from "vue";
import type { ChartData } from "chart.js";
import ChartHelper from "../helper/ChartHelper";
import { useBackendStore } from "@/stores/backend";
import { apiFetch } from "@/utils/apiFetch";
import type { Socket } from "socket.io-client";

interface SystemInfo {
process: {
Expand Down Expand Up @@ -47,7 +46,7 @@ type HealthChartData = {
type HealthStore = {
state: Ref<SystemInfo | undefined>;
chartData: HealthChartData;
init: () => void;
init: (socket: Socket) => void;
};

export const useHealthStore = defineStore("health", (): HealthStore => {
Expand Down Expand Up @@ -94,46 +93,37 @@ export const useHealthStore = defineStore("health", (): HealthStore => {
});

// actions
function init(): void {
const backendStore = useBackendStore();
function init(socket: Socket): void {
socket.on("healthMetrics", (data: SystemInfo) => {
state.value = data;

setInterval(async () => {
if (!backendStore.isServerOnline) {
return;
}

const response = await apiFetch(`/health`);
state.value = await response.json();
}, 500);

setInterval(() => {
if (!backendStore.isServerOnline || !chartData || !state.value) {
if (!chartData) {
return;
}

chartData.processMemory.datasets[0].data.push({
x: Date.now(),
y: Number((state.value.process.memoryUsage.rss / 1024 / 1024).toFixed(2)),
y: Number((data.process.memoryUsage.rss / 1024 / 1024).toFixed(2)),
});
chartData.processMemory.datasets[1].data.push({
x: Date.now(),
y: Number((state.value.process.memoryUsage.heapTotal / 1024 / 1024).toFixed(2)),
y: Number((data.process.memoryUsage.heapTotal / 1024 / 1024).toFixed(2)),
});
chartData.processMemory.datasets[2].data.push({
x: Date.now(),
y: Number((state.value.process.memoryUsage.heapUsed / 1024 / 1024).toFixed(2)),
y: Number((data.process.memoryUsage.heapUsed / 1024 / 1024).toFixed(2)),
});

chartData.systemCpu.datasets[0].data.push({
x: Date.now(),
y: Number(state.value.system.cpu.usage.toFixed(2)),
y: Number(data.system.cpu.usage.toFixed(2)),
});

chartData.systemMemory.datasets[0].data.push({
x: Date.now(),
y: Number(state.value.system.memory.usedMemPercentage.toFixed(2)),
y: Number(data.system.memory.usedMemPercentage.toFixed(2)),
});
}, 425);
});
}

return {
Expand Down
4 changes: 1 addition & 3 deletions src/views/SystemHealthView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ const uptime = computed(() => {
</v-list-item>
<v-list-item class="px-1">
<v-list-item-title>Operating System</v-list-item-title>
<v-list-item-subtitle>{{
`${state.system.os.name} (${state.system.os.type})`
}}</v-list-item-subtitle>
<v-list-item-subtitle>{{ state.system.os.type }}</v-list-item-subtitle>
</v-list-item>
<v-list-item class="px-1">
<v-list-item-title>IP address</v-list-item-title>
Expand Down
Loading