-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathshard_counter.sh
More file actions
executable file
·50 lines (37 loc) · 1.3 KB
/
shard_counter.sh
File metadata and controls
executable file
·50 lines (37 loc) · 1.3 KB
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
#!/bin/sh
# get total number of shards and size per instance from cat_shards.txt (GET _cat/shards?v)
#
#
# colors
red=`tput setaf 1`
green=`tput setaf 2`
blue=`tput setaf 14`
reset=`tput sgr0`
# help
if [ -z "${1}" ]; then
echo "${green}Usage :${reset} ${0} /path/cat_shards.txt"
exit
fi
sum_and_convert_to_gb() {
total_size_bytes=0
while read line; do
size=$(echo $line | sed -E 's/[^0-9.]//g')
unit=$(echo $line | sed -E 's/[^bkmg]//g')
case $unit in
"b") total_size_bytes=$(echo "$total_size_bytes + $size" | bc) ;;
"kb") total_size_bytes=$(echo "$total_size_bytes + ($size * 1024)" | bc) ;;
"mb") total_size_bytes=$(echo "$total_size_bytes + ($size * 1024 * 1024)" | bc) ;;
"gb") total_size_bytes=$(echo "$total_size_bytes + ($size * 1024 * 1024 * 1024)" | bc) ;;
esac
done
total_size_gb=$(echo "scale=2; $total_size_bytes / 1024 / 1024 / 1024" | bc)
echo $total_size_gb
}
fmt="%-40s%-10s%-12s\n"
printf "$fmt" "INSTANCE" "SHARDS" "SIZE(mb)"
for instance in `cat "${1}" | awk {' print $NF '} | grep -v "^node$" | sort |uniq`
do
shards=`cat "${1}" | grep -c "${instance}"`
size=`cat "${1}" | grep "${instance}" | awk {' print $7 '} | sum_and_convert_to_gb`
printf "$fmt" "${instance}" "${shards}" "${size}"
done