Compare commits

...

4 Commits

Author SHA1 Message Date
shamoon
88089a8a11 Merge pull request #1174 from benphelps/fix-memory-calc
Fix memory display in v0.6.11
2023-04-03 23:29:12 -07:00
shamoon
2829f0b649 Update memory.jsx 2023-04-03 23:22:28 -07:00
shamoon
0d5856db1e Merge pull request #1172 from benphelps/cpu-temp-fixes
Fix glances cpu temp detection & fahrenheit conversion
2023-04-03 21:50:23 -07:00
shamoon
f3ec238a2c Fix glances cpu temp detection & fahrenheit conversion 2023-04-03 21:49:28 -07:00
3 changed files with 23 additions and 8 deletions

View File

@@ -6,6 +6,12 @@ import { useTranslation } from "next-i18next";
import UsageBar from "../resources/usage-bar"; import UsageBar from "../resources/usage-bar";
const cpuSensorLabels = ["cpu_thermal", "Core"];
function convertToFahrenheit(t) {
return t * 9/5 + 32
}
export default function Widget({ options }) { export default function Widget({ options }) {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
@@ -65,11 +71,20 @@ export default function Widget({ options }) {
} }
const unit = options.units === "imperial" ? "fahrenheit" : "celsius"; const unit = options.units === "imperial" ? "fahrenheit" : "celsius";
let mainTemp; let mainTemp = 0;
let maxTemp = 80; let maxTemp = 80;
if (options.cputemp && data.sensors) { const cpuSensors = data.sensors?.filter(s => cpuSensorLabels.some(label => s.label.startsWith(label)) && s.type === "temperature_core");
mainTemp = unit === "celsius" ? data.sensors.find(s => s.label.includes("cpu_thermal")).value : data.sensors.find(s => s.label.includes("cpu_thermal")).value * 5/9 + 32; if (options.cputemp && cpuSensors) {
if (data.sensors.warning) maxTemp = data.sensors.warning; try {
mainTemp = cpuSensors.reduce((acc, s) => acc + s.value, 0) / cpuSensors.length;
maxTemp = Math.max(cpuSensors.reduce((acc, s) => acc + s.warning, 0) / cpuSensors.length, maxTemp);
if (unit === "fahrenheit") {
mainTemp = convertToFahrenheit(mainTemp);
maxTemp = convertToFahrenheit(maxTemp);
}
} catch (e) {
// cpu sensor retrieval failed
}
} }
const tempPercent = Math.round((mainTemp / maxTemp) * 100); const tempPercent = Math.round((mainTemp / maxTemp) * 100);
@@ -110,7 +125,7 @@ export default function Widget({ options }) {
<UsageBar percent={data.quicklook.mem} /> <UsageBar percent={data.quicklook.mem} />
</div> </div>
</div> </div>
{options.cputemp && mainTemp && {options.cputemp && mainTemp > 0 &&
(<div className="flex-none flex flex-row items-center mr-3 py-1.5"> (<div className="flex-none flex flex-row items-center mr-3 py-1.5">
<FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" /> <FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" />
<div className="flex flex-col ml-3 text-left min-w-[85px]"> <div className="flex flex-col ml-3 text-left min-w-[85px]">

View File

@@ -6,7 +6,7 @@ import { useTranslation } from "next-i18next";
import UsageBar from "./usage-bar"; import UsageBar from "./usage-bar";
function convertToFahrenheit(t) { function convertToFahrenheit(t) {
return t * 5/9 + 32 return t * 9/5 + 32
} }
export default function CpuTemp({ expanded, units }) { export default function CpuTemp({ expanded, units }) {

View File

@@ -44,7 +44,7 @@ export default function Memory({ expanded }) {
); );
} }
const percent = Math.round((data.memory.used / data.memory.total) * 100); const percent = Math.round((data.memory.active / data.memory.total) * 100);
return ( return (
<div className="flex-none flex flex-row items-center mr-3 py-1.5"> <div className="flex-none flex flex-row items-center mr-3 py-1.5">
@@ -52,7 +52,7 @@ export default function Memory({ expanded }) {
<div className="flex flex-col ml-3 text-left min-w-[85px]"> <div className="flex flex-col ml-3 text-left min-w-[85px]">
<span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between"> <span className="text-theme-800 dark:text-theme-200 text-xs flex flex-row justify-between">
<div className="pl-0.5 pr-1"> <div className="pl-0.5 pr-1">
{t("common.bytes", { value: data.memory.free, maximumFractionDigits: 1, binary: true })} {t("common.bytes", { value: data.memory.available, maximumFractionDigits: 1, binary: true })}
</div> </div>
<div className="pr-1">{t("resources.free")}</div> <div className="pr-1">{t("resources.free")}</div>
</span> </span>