diff --git a/docs/widgets/info/glances.md b/docs/widgets/info/glances.md index 77c6a0ef3..fac0592e5 100644 --- a/docs/widgets/info/glances.md +++ b/docs/widgets/info/glances.md @@ -16,6 +16,7 @@ The Glances widget allows you to monitor the resources (CPU, memory, storage, te cpu: true # optional, enabled by default, disable by setting to false mem: true # optional, enabled by default, disable by setting to false cputemp: true # disabled by default + cpuSensorLabel: Package id # optional additional cputemp sensor label prefix unit: imperial # optional for temp, default is metric uptime: true # disabled by default disk: / # disabled by default, use mount point of disk(s) in glances. Can also be a list (see below) @@ -24,6 +25,8 @@ The Glances widget allows you to monitor the resources (CPU, memory, storage, te label: MyMachine # optional ``` +The built-in `cputemp` sensor matching already checks common prefixes such as `cpu_thermal`, `Core`, `Tctl`, and `Temperature`. Use `cpuSensorLabel` to add your own Glances sensor label prefix when your system reports CPU temperatures under a different name. + Multiple disks can be specified as: ```yaml diff --git a/src/components/widgets/glances/glances.jsx b/src/components/widgets/glances/glances.jsx index 567a73de1..569091e1d 100644 --- a/src/components/widgets/glances/glances.jsx +++ b/src/components/widgets/glances/glances.jsx @@ -11,12 +11,16 @@ import Resource from "../widget/resource"; import Resources from "../widget/resources"; import WidgetLabel from "../widget/widget_label"; -const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl", "Temperature"]; +const defaultCpuSensorLabels = ["cpu_thermal", "Core", "Tctl", "Temperature"]; function convertToFahrenheit(t) { return (t * 9) / 5 + 32; } +function getCpuSensorLabels(options) { + return [...defaultCpuSensorLabels, options.cpuSensorLabel].filter(Boolean); +} + export default function Widget({ options }) { const { t, i18n } = useTranslation(); const { settings } = useContext(SettingsContext); @@ -56,6 +60,7 @@ export default function Widget({ options }) { const unit = options.units === "imperial" ? "fahrenheit" : "celsius"; let mainTemp = 0; let maxTemp = 80; + const cpuSensorLabels = getCpuSensorLabels(options); const cpuSensors = data.sensors?.filter( (s) => cpuSensorLabels.some((label) => s.label.startsWith(label)) && s.type === "temperature_core", ); diff --git a/src/components/widgets/glances/glances.test.jsx b/src/components/widgets/glances/glances.test.jsx index a72fff0df..8c68f9853 100644 --- a/src/components/widgets/glances/glances.test.jsx +++ b/src/components/widgets/glances/glances.test.jsx @@ -120,6 +120,26 @@ describe("components/widgets/glances", () => { expect(screen.getByRole("link")).toHaveClass("expanded"); }); + it("renders temperature for custom cpu sensor labels", () => { + useSWR.mockReturnValue({ + data: { + cpu: { total: 1 }, + load: { min15: 1 }, + mem: { available: 1, total: 1, percent: 1 }, + fs: [], + sensors: [{ label: "Package id 0", type: "temperature_core", value: 42, warning: 90 }], + }, + error: undefined, + }); + + renderWithProviders(, { + settings: { target: "_self" }, + }); + + expect(screen.getByText("42")).toBeInTheDocument(); + expect(screen.getByText("glances.temp")).toBeInTheDocument(); + }); + it("renders disk resources for an array of mount points and filters missing mounts", () => { useSWR.mockReturnValue({ data: {