-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathload.sh
executable file
·54 lines (43 loc) · 928 Bytes
/
load.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/helpers.sh"
get_number_of_cores(){
if is_osx
then
sysctl -n hw.ncpu
else
nproc
fi
}
print_load() {
local num_cores=1
local output
case "$(get_tmux_option "@load_per_cpu_core")" in
true|1|yes)
num_cores=$(get_number_of_cores)
;;
esac
output=$(uptime | awk -v num_cores="$num_cores" '{
sub(/,$/, "", $(NF-2));
sub(/,$/, "", $(NF-1));
sub(/,$/, "", $NF);
printf "%.2f %.2f %.2f", $(NF-2)/num_cores, $(NF-1)/num_cores, $NF/num_cores
}')
case "$1" in
1)
output="$(awk '{ print $1 }' <<< "$output")"
;;
5)
output="$(awk '{ print $2 }' <<< "$output")"
;;
15)
output="$(awk '{ print $3 }' <<< "$output")"
;;
esac
# Replace commas with dots
echo -n "${output//,/.}"
}
main() {
print_load "$@"
}
main "$@"