aboutsummaryrefslogtreecommitdiffstats
path: root/modules/cpuload
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-02-26 20:31:12 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2022-02-26 20:31:12 +0530
commit85ae438fbc238fe56bcb1c10a12ec52365053cb6 (patch)
tree7aa2c802739657f22fd8de735207b27fc6e7e8a9 /modules/cpuload
downloaddwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.gz
dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.bz2
dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.zip
dwmbar dotfiles
Diffstat (limited to 'modules/cpuload')
-rwxr-xr-xmodules/cpuload32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/cpuload b/modules/cpuload
new file mode 100755
index 0000000..db14d40
--- /dev/null
+++ b/modules/cpuload
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# Prints out the CPU load percentage
+
+PREFIX='🧠 '
+
+get_load()
+{
+ # Get the first line with aggregate of all CPUs
+ cpu_last=($(head -n1 /proc/stat))
+ cpu_last_sum="${cpu_last[@]:1}"
+ cpu_last_sum=$((${cpu_last_sum// /+}))
+
+ sleep 0.05
+
+ cpu_now=($(head -n1 /proc/stat))
+ cpu_sum="${cpu_now[@]:1}"
+ cpu_sum=$((${cpu_sum// /+}))
+
+ cpu_delta=$((cpu_sum - cpu_last_sum))
+ cpu_idle=$((cpu_now[4]- cpu_last[4]))
+ cpu_used=$((cpu_delta - cpu_idle))
+ cpu_usage=$((100 * cpu_used / cpu_delta))
+
+ # Keep this as last for our next read
+ cpu_last=("${cpu_now[@]}")
+ cpu_last_sum=$cpu_sum
+
+ echo "$PREFIX $cpu_usage%"
+}
+
+get_load