summaryrefslogtreecommitdiffstats
path: root/.local/bin/status/sb-cpu
blob: e85f422cc9570cb81fb910d0a2727a504e88fadc (plain)
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
#!/bin/sh

# ncpu_file="/tmp/ncpu"
# if [ -f $ncpu_file ]; then
# 	ncpu=$(cat $ncpu_file)
# else
# 	ncpu=$(sysctl -n hw.ncpu | tee $ncpu_file)
# fi

printf " "
# for i in $(top -P -d 2 -s 0.2 | grep '^CPU' | tail -n$ncpu | sed '{s/% idle$//;s/.*[[:blank:]]//;s/\..*//;s/^/100 - /;}' | bc); do
case $(hostname -s) in
	mother|po-rbo)
		stats=$(uptime | head -n1)
		printf "%s" "$(echo "$stats" | sed 's/.*average: *//;s/,.*//')"
		return
		;;
	mars)
		stats=$(top -d 2 -s 0.2 | grep -E 'load averages:|^CPU')
		printf "%s " "$(echo "$stats" | sed '{1,2d;4d;s/.*averages: *//;s/,.*//;}')"
		;;
esac

case $(echo "$stats" | sed '{1,3d;s/% idle$//;s/.*[[:blank:]]//;s/\..*//;s/^/(100 - /;s/$/) \/ 12\.5/;}' | bc) in
		"0") printf "[        ]\n" ;;
		"1") printf "[=       ]\n" ;;
		"2") printf "[==      ]\n" ;;
		"3") printf "[===     ]\n" ;;
		"4") printf "[====    ]\n" ;;
		"5") printf "[=====   ]\n" ;;
		"6") printf "[======  ]\n" ;;
		"7") printf "[======= ]\n" ;;
		"8") printf "[========]\n" ;;
esac