From daa7ef2a3d7f9f820a55b83a5536afd7200e6345 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Wed, 2 Aug 2023 06:04:54 +0300 Subject: [PATCH] add pure info metric --- public/locales/en/common.json | 3 +- src/widgets/glances/component.jsx | 5 ++ src/widgets/glances/metrics/info.jsx | 115 +++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/widgets/glances/metrics/info.jsx diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 45402ce0d..7dbd53d67 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -376,7 +376,8 @@ "read": "Read", "write": "Write", "gpu": "GPU", - "mem": "Mem" + "mem": "Mem", + "swap": "Swap" }, "quicklaunch": { "bookmark": "Bookmark", diff --git a/src/widgets/glances/component.jsx b/src/widgets/glances/component.jsx index 310fae5ac..3abef0d42 100644 --- a/src/widgets/glances/component.jsx +++ b/src/widgets/glances/component.jsx @@ -5,10 +5,15 @@ import Net from "./metrics/net"; import Process from "./metrics/process"; import Disk from "./metrics/disk"; import GPU from "./metrics/gpu"; +import Info from "./metrics/info"; export default function Component({ service }) { const { widget } = service; + if (widget.metric === "info") { + return ; + } + if (widget.metric === "memory") { return ; } diff --git a/src/widgets/glances/metrics/info.jsx b/src/widgets/glances/metrics/info.jsx new file mode 100644 index 000000000..104130eec --- /dev/null +++ b/src/widgets/glances/metrics/info.jsx @@ -0,0 +1,115 @@ +import { useTranslation } from "next-i18next"; + +import Error from "../components/error"; +import Container from "../components/container"; +import Block from "../components/block"; + +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { t } = useTranslation(); + + const { data: quicklookData, errorL: quicklookError } = useWidgetAPI(service.widget, 'quicklook', { + refreshInterval: 1000, + }); + + const { data: systemData, errorL: systemError } = useWidgetAPI(service.widget, 'system', { + refreshInterval: 30000, + }); + + if (quicklookError) { + return ; + } + + if (systemError) { + return ; + } + + const dataCharts = []; + + if (quicklookData) { + quicklookData.percpu.forEach((cpu, index) => { + dataCharts.push({ + name: `CPU ${index}`, + cpu: cpu.total, + mem: quicklookData.mem, + swap: quicklookData.swap, + proc: quicklookData.cpu, + }); + }); + } + + + return ( + + + {quicklookData && quicklookData.cpu_name && ( +
+ {quicklookData.cpu_name} +
+ )} +
+ + {systemData && systemData.linux_distro && ( +
+ {systemData.linux_distro} +
+ )} + {systemData && systemData.os_version && ( +
+ {systemData.os_version} +
+ )} + {systemData && systemData.hostname && ( +
+ {systemData.hostname} +
+ )} +
+ + + {quicklookData && quicklookData.cpu && ( +
+
{t("glances.cpu")}
+
+ {t("common.number", { + value: quicklookData.cpu, + style: "unit", + unit: "percent", + maximumFractionDigits: 0, + })} +
+
+ )} + + {quicklookData && quicklookData.mem && ( +
+
{t("glances.mem")}
+
+ {t("common.number", { + value: quicklookData.mem, + style: "unit", + unit: "percent", + maximumFractionDigits: 0, + })} +
+
+ )} + + {quicklookData && quicklookData.swap && ( +
+
{t("glances.swap")}
+
+ {t("common.number", { + value: quicklookData.swap, + style: "unit", + unit: "percent", + maximumFractionDigits: 0, + })} +
+
+ )} +
+
+ ); +}