Enhancement: support custom labels for cpu temp sensors (#6595)

This commit is contained in:
shamoon
2026-04-24 10:20:15 -07:00
committed by GitHub
parent 7ed1260f0d
commit 44c1e8393e
3 changed files with 29 additions and 1 deletions

View File

@@ -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

View File

@@ -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",
);

View File

@@ -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(<Glances options={{ cputemp: true, cpuSensorLabel: "Package id", url: "http://glances" }} />, {
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: {