You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2025-05-10-cpu-usage.md
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,9 +49,23 @@ script: |
49
49
usagePercent = 0;
50
50
}
51
51
52
-
return usagePercent + '%';
52
+
let icon;
53
+
if (usagePercent < 33) {
54
+
icon = 'gauge.with.dots.needle.0percent';
55
+
} else if (usagePercent < 50) {
56
+
icon = 'gauge.with.dots.needle.33percent';
57
+
} else if (usagePercent < 67) {
58
+
icon = 'gauge.with.dots.needle.50percent';
59
+
} else if (usagePercent < 80) {
60
+
icon = 'gauge.with.dots.needle.67percent';
61
+
} else {
62
+
icon = 'gauge.with.dots.needle.100percent';
63
+
}
64
+
65
+
return { label: usagePercent + '%', icon };
53
66
})();
54
67
---
55
68
56
-
This script retrieves the current CPU usage (percent) of the system.
69
+
This script retrieves the current CPU usage (percent) of the system by reading the `/proc/stat` file. It calculates the CPU usage based on the difference between the current and previous CPU times. The script uses a simple algorithm to determine the CPU usage percentage and returns it as a label with an appropriate icon.
70
+
57
71
Hope to be a cross-platform script in the future. Currently only Linux is supported.
0 commit comments