blob: db14d4012e06931f2fa57d6f9025b724c6a7c3a8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
|