mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-26 05:51:17 -07:00
Enhancement: support custom labels for cpu temp sensors (#6595)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
This commit is contained in:
@@ -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
|
cpu: true # optional, enabled by default, disable by setting to false
|
||||||
mem: 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
|
cputemp: true # disabled by default
|
||||||
|
cpuSensorLabel: Package id # optional additional cputemp sensor label prefix
|
||||||
unit: imperial # optional for temp, default is metric
|
unit: imperial # optional for temp, default is metric
|
||||||
uptime: true # disabled by default
|
uptime: true # disabled by default
|
||||||
disk: / # disabled by default, use mount point of disk(s) in glances. Can also be a list (see below)
|
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
|
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:
|
Multiple disks can be specified as:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -11,12 +11,16 @@ import Resource from "../widget/resource";
|
|||||||
import Resources from "../widget/resources";
|
import Resources from "../widget/resources";
|
||||||
import WidgetLabel from "../widget/widget_label";
|
import WidgetLabel from "../widget/widget_label";
|
||||||
|
|
||||||
const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl", "Temperature"];
|
const defaultCpuSensorLabels = ["cpu_thermal", "Core", "Tctl", "Temperature"];
|
||||||
|
|
||||||
function convertToFahrenheit(t) {
|
function convertToFahrenheit(t) {
|
||||||
return (t * 9) / 5 + 32;
|
return (t * 9) / 5 + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCpuSensorLabels(options) {
|
||||||
|
return [...defaultCpuSensorLabels, options.cpuSensorLabel].filter(Boolean);
|
||||||
|
}
|
||||||
|
|
||||||
export default function Widget({ options }) {
|
export default function Widget({ options }) {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const { settings } = useContext(SettingsContext);
|
const { settings } = useContext(SettingsContext);
|
||||||
@@ -56,6 +60,7 @@ export default function Widget({ options }) {
|
|||||||
const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
|
const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
|
||||||
let mainTemp = 0;
|
let mainTemp = 0;
|
||||||
let maxTemp = 80;
|
let maxTemp = 80;
|
||||||
|
const cpuSensorLabels = getCpuSensorLabels(options);
|
||||||
const cpuSensors = data.sensors?.filter(
|
const cpuSensors = data.sensors?.filter(
|
||||||
(s) => cpuSensorLabels.some((label) => s.label.startsWith(label)) && s.type === "temperature_core",
|
(s) => cpuSensorLabels.some((label) => s.label.startsWith(label)) && s.type === "temperature_core",
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -120,6 +120,26 @@ describe("components/widgets/glances", () => {
|
|||||||
expect(screen.getByRole("link")).toHaveClass("expanded");
|
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", () => {
|
it("renders disk resources for an array of mount points and filters missing mounts", () => {
|
||||||
useSWR.mockReturnValue({
|
useSWR.mockReturnValue({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
Reference in New Issue
Block a user