Added an option to opt into tracking GPU stats in the dashboard. (#10)
* Added an option to opt in to GPU usage. * Catch and log error if exists during GPU stat monitoring. * Removed unimplemented category header for System Tray in options * Update the readme to indicate this change.
This commit is contained in:
@@ -145,3 +145,9 @@ Where each monitor is defined by its index (0, 1, 2 in this case) and each secti
|
||||
"systray"
|
||||
```
|
||||
Since the text-box in the options dialog isn't sufficient, it is recommended that you create this JSON configuration in a text editor elsewhere and paste it into the layout text-box under Configuration > Bar > "Bar Layouts for Monitors".
|
||||
|
||||
### Additional Configuration
|
||||
|
||||
#### GPU Tracking
|
||||
|
||||
If you have an NVidia GPU, you can track your GPU usage in your Dashboard by going to your `Settings > Configuration > Dashboard Menu > Track GPU` and turning it on.
|
||||
|
||||
@@ -2,6 +2,7 @@ import options from "options";
|
||||
import { GPU_Stat } from "lib/types/gpustat";
|
||||
|
||||
const { terminal } = options;
|
||||
const { enable_gpu } = options.menus.dashboard.stats;
|
||||
|
||||
const Stats = () => {
|
||||
const divide = ([total, free]) => free / total;
|
||||
@@ -61,32 +62,7 @@ const Stats = () => {
|
||||
},
|
||||
);
|
||||
|
||||
const gpu = Variable(0, {
|
||||
poll: [
|
||||
2000,
|
||||
"gpustat --json",
|
||||
(out) => {
|
||||
if (typeof out !== "string") {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(out);
|
||||
|
||||
const totalGpu = 100;
|
||||
const usedGpu =
|
||||
data.gpus.reduce((acc: number, gpu: GPU_Stat) => {
|
||||
|
||||
return acc + gpu["utilization.gpu"]
|
||||
}, 0) / data.gpus.length;
|
||||
|
||||
return divide([totalGpu, usedGpu]);
|
||||
} catch (e) {
|
||||
console.error("Error getting GPU stats:", e);
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
],
|
||||
});
|
||||
const gpu = Variable(0);
|
||||
|
||||
const storage = Variable(
|
||||
{ total: 0, used: 0, percentage: 0 },
|
||||
@@ -226,41 +202,91 @@ const Stats = () => {
|
||||
class_name: "stat gpu",
|
||||
hexpand: true,
|
||||
vpack: "center",
|
||||
children: [
|
||||
Widget.Button({
|
||||
on_primary_click: terminal.bind("value").as(term => {
|
||||
return () => {
|
||||
App.closeWindow("dashboardmenu");
|
||||
Utils.execAsync(`bash -c "${term} -e btop"`).catch(
|
||||
(err) => `Failed to open btop: ${err}`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
label: "",
|
||||
}),
|
||||
Widget.Button({
|
||||
on_primary_click: terminal.bind("value").as(term => {
|
||||
return () => {
|
||||
App.closeWindow("dashboardmenu");
|
||||
Utils.execAsync(`bash -c "${term} -e btop"`).catch(
|
||||
(err) => `Failed to open btop: ${err}`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
child: Widget.LevelBar({
|
||||
class_name: "stats-bar",
|
||||
hexpand: true,
|
||||
vpack: "center",
|
||||
value: gpu.bind("value"),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
setup: self => {
|
||||
const getGpuUsage = () => {
|
||||
if (!enable_gpu.value) {
|
||||
gpu.value = 0;
|
||||
return;
|
||||
}
|
||||
Utils.execAsync("gpustat --json")
|
||||
.then((out) => {
|
||||
if (typeof out !== "string") {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(out);
|
||||
|
||||
const totalGpu = 100;
|
||||
const usedGpu =
|
||||
data.gpus.reduce((acc: number, gpu: GPU_Stat) => {
|
||||
|
||||
return acc + gpu["utilization.gpu"]
|
||||
}, 0) / data.gpus.length;
|
||||
|
||||
gpu.value = divide([totalGpu, usedGpu]);
|
||||
} catch (e) {
|
||||
console.error("Error getting GPU stats:", e);
|
||||
gpu.value = 0;
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`An error occurred while fetching GPU stats: ${err}`)
|
||||
})
|
||||
}
|
||||
|
||||
self.poll(2000, getGpuUsage)
|
||||
|
||||
Utils.merge([gpu.bind("value"), enable_gpu.bind("value")], (gpu, enableGpu) => {
|
||||
if (!enableGpu) {
|
||||
return self.children = [];
|
||||
}
|
||||
|
||||
return self.children = [
|
||||
Widget.Button({
|
||||
on_primary_click: terminal.bind("value").as(term => {
|
||||
return () => {
|
||||
App.closeWindow("dashboardmenu");
|
||||
Utils.execAsync(`bash -c "${term} -e btop"`).catch(
|
||||
(err) => `Failed to open btop: ${err}`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
label: "",
|
||||
}),
|
||||
Widget.Button({
|
||||
on_primary_click: terminal.bind("value").as(term => {
|
||||
return () => {
|
||||
App.closeWindow("dashboardmenu");
|
||||
Utils.execAsync(`bash -c "${term} -e btop"`).catch(
|
||||
(err) => `Failed to open btop: ${err}`,
|
||||
);
|
||||
}
|
||||
}),
|
||||
child: Widget.LevelBar({
|
||||
class_name: "stats-bar",
|
||||
hexpand: true,
|
||||
vpack: "center",
|
||||
value: gpu,
|
||||
}),
|
||||
}),
|
||||
]
|
||||
})
|
||||
},
|
||||
}),
|
||||
Widget.Label({
|
||||
Widget.Box({
|
||||
hpack: "end",
|
||||
class_name: "stat-value gpu",
|
||||
label: gpu.bind("value").as((v) => `${Math.floor(v * 100)}%`),
|
||||
}),
|
||||
children: Utils.merge([gpu.bind("value"), enable_gpu.bind("value")], (gpuUsed, enableGpu) => {
|
||||
if (!enableGpu) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
Widget.Label({
|
||||
class_name: "stat-value gpu",
|
||||
label: `${Math.floor(gpuUsed * 100)}%`,
|
||||
})
|
||||
];
|
||||
})
|
||||
})
|
||||
],
|
||||
}),
|
||||
Widget.Box({
|
||||
|
||||
@@ -617,6 +617,9 @@ const options = mkOptions(OPTIONS, {
|
||||
name: opt<"system" | string>("system"),
|
||||
},
|
||||
},
|
||||
stats: {
|
||||
enable_gpu: opt(false),
|
||||
},
|
||||
shortcuts: {
|
||||
left: {
|
||||
shortcut1: {
|
||||
|
||||
@@ -37,8 +37,8 @@ export const BarSettings = () => {
|
||||
Header('Battery'),
|
||||
Option({ opt: options.bar.battery.label, title: 'Show Battery Percentage', type: 'boolean' }),
|
||||
|
||||
Header('System Tray'),
|
||||
// TODO: Figure out how to hand arrays
|
||||
// Header('System Tray'),
|
||||
// TODO: Figure out how to handle arrays
|
||||
// Option({ opt: options.bar.systray.ignore, title: 'Ignore', subtitle: 'Comma separated string of apps to ignore in the tray', type: 'string' }),
|
||||
|
||||
Header('Clock'),
|
||||
|
||||
@@ -22,6 +22,9 @@ export const DashboardMenuSettings = () => {
|
||||
Option({ opt: options.menus.dashboard.powermenu.logout, title: 'Logout Command', type: 'string' }),
|
||||
Option({ opt: options.menus.dashboard.powermenu.sleep, title: 'Sleep Command', type: 'string' }),
|
||||
|
||||
Header('Resource Usage Metrics'),
|
||||
Option({ opt: options.menus.dashboard.stats.enable_gpu, title: 'Track GPU', subtitle: 'NOTE: This is currently only available for NVidia GPUs and requires \'python-gpustat\'.', type: 'boolean' }),
|
||||
|
||||
Header('Shortcuts'),
|
||||
Option({ opt: options.menus.dashboard.shortcuts.left.shortcut1.icon, title: 'Left - Shortcut 1 (Icon)', type: 'string' }),
|
||||
Option({ opt: options.menus.dashboard.shortcuts.left.shortcut1.command, title: 'Left - Shortcut 1 (Command)', type: 'string' }),
|
||||
|
||||
Reference in New Issue
Block a user