fix glances weirdness
This commit is contained in:
parent
f06214a295
commit
2dc10624d1
@ -19,6 +19,9 @@ widget:
|
||||
password: pass # optional if auth enabled in Glances
|
||||
metric: cpu
|
||||
diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk
|
||||
tempUnits: imperial # optional, metric (default) or imperial. Only applies to cpu
|
||||
refreshInterval: 5000 # optional - in milliseconds, defaults to 1000 or more, depending on the metric
|
||||
pointsLimit: 15 # optional, defaults to 15
|
||||
```
|
||||
|
||||
_Please note, this widget does not need an `href`, `icon` or `description` on its parent service. To achieve the same effect as the examples above, see as an example:_
|
||||
|
||||
@ -398,6 +398,7 @@ export function cleanServiceGroups(groups) {
|
||||
metric,
|
||||
pointsLimit,
|
||||
diskUnits,
|
||||
tempUnits,
|
||||
|
||||
// glances, customapi, iframe
|
||||
refreshInterval,
|
||||
@ -537,6 +538,7 @@ export function cleanServiceGroups(groups) {
|
||||
if (refreshInterval) cleanedService.widget.refreshInterval = refreshInterval;
|
||||
if (pointsLimit) cleanedService.widget.pointsLimit = pointsLimit;
|
||||
if (diskUnits) cleanedService.widget.diskUnits = diskUnits;
|
||||
if (tempUnits) cleanedService.widget.tempUnits = tempUnits;
|
||||
}
|
||||
if (type === "mjpeg") {
|
||||
if (stream) cleanedService.widget.stream = stream;
|
||||
|
||||
@ -12,6 +12,11 @@ const Chart = dynamic(() => import("../components/chart"), { ssr: false });
|
||||
|
||||
const defaultPointsLimit = 15;
|
||||
const defaultInterval = 1000;
|
||||
const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl"];
|
||||
|
||||
function convertToFahrenheit(t) {
|
||||
return (t * 9) / 5 + 32;
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
@ -24,7 +29,34 @@ export default function Component({ service }) {
|
||||
refreshInterval: Math.max(defaultInterval, refreshInterval),
|
||||
});
|
||||
|
||||
const { data: systemData, error: systemError } = useWidgetAPI(service.widget, "system");
|
||||
const { data: sensorData, error: sensorError } = useWidgetAPI(service.widget, "sensors", {
|
||||
refreshInterval: Math.max(defaultInterval, refreshInterval),
|
||||
});
|
||||
|
||||
const { data: quicklookData, error: quicklookError } = useWidgetAPI(service.widget, "quicklook");
|
||||
|
||||
const unit = widget.tempUnits === "imperial" ? "fahrenheit" : "celsius";
|
||||
let mainTemp = 0;
|
||||
let maxTemp = 80;
|
||||
const cpuSensors = sensorData?.filter(
|
||||
(s) => cpuSensorLabels.some((label) => s.label.startsWith(label)) && s.type === "temperature_core",
|
||||
);
|
||||
|
||||
if (cpuSensors) {
|
||||
try {
|
||||
mainTemp = cpuSensors.reduce((acc, s) => acc + s.value, 0) / cpuSensors.length;
|
||||
maxTemp = Math.max(
|
||||
cpuSensors.reduce((acc, s) => acc + (s.warning > 0 ? s.warning : 0), 0) / cpuSensors.length,
|
||||
maxTemp,
|
||||
);
|
||||
if (unit === "fahrenheit") {
|
||||
mainTemp = convertToFahrenheit(mainTemp);
|
||||
maxTemp = convertToFahrenheit(maxTemp);
|
||||
}
|
||||
} catch (e) {
|
||||
// cpu sensor retrieval failed
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
@ -71,22 +103,34 @@ export default function Component({ service }) {
|
||||
/>
|
||||
)}
|
||||
|
||||
{!chart && systemData && !systemError && (
|
||||
{!chart && quicklookData && !quicklookError && (
|
||||
<Block position="top-3 right-3">
|
||||
<div className="text-xs opacity-50">
|
||||
{systemData.linux_distro && `${systemData.linux_distro} - `}
|
||||
{systemData.os_version && systemData.os_version}
|
||||
<div className="text-[0.6rem] opacity-50">
|
||||
{quicklookData.cpu_name && quicklookData.cpu_name}
|
||||
</div>
|
||||
</Block>
|
||||
)}
|
||||
|
||||
{systemData && !systemError && (
|
||||
{quicklookData && !quicklookError && (
|
||||
<Block position="bottom-3 left-3">
|
||||
{systemData.linux_distro && chart && <div className="text-xs opacity-50">{systemData.linux_distro}</div>}
|
||||
{mainTemp > 0 && (
|
||||
<div className="text-xs opacity-50">
|
||||
{t("common.number", {
|
||||
value: mainTemp,
|
||||
maximumFractionDigits: 1,
|
||||
style: "unit",
|
||||
unit,
|
||||
})} ({t("glances.warn")} @
|
||||
{t("common.number", {
|
||||
value: maxTemp,
|
||||
maximumFractionDigits: 1,
|
||||
style: "unit",
|
||||
unit,
|
||||
})})
|
||||
</div>
|
||||
)}
|
||||
|
||||
{systemData.os_version && chart && <div className="text-xs opacity-50">{systemData.os_version}</div>}
|
||||
|
||||
{systemData.hostname && <div className="text-xs opacity-50">{systemData.hostname}</div>}
|
||||
{quicklookData.cpu_name && chart && <div className="text-xs opacity-50">{quicklookData.cpu_name}</div>}
|
||||
</Block>
|
||||
)}
|
||||
|
||||
|
||||
@ -122,7 +122,10 @@ export default function Component({ service }) {
|
||||
)}
|
||||
|
||||
{!chart && quicklookData?.swap === 0 && (
|
||||
<div className="text-[0.6rem] opacity-50">{quicklookData.cpu_name}</div>
|
||||
<div className="text-[0.6rem] opacity-50">
|
||||
{systemData.linux_distro && `${systemData.linux_distro} - `}
|
||||
{systemData.os_version && systemData.os_version}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="w-[4rem]">{!chart && <Swap quicklookData={quicklookData} className="opacity-25" />}</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user