forked from HariSekhon/DevOps-Python-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbase_table_regions_by_regionserver.sh
executable file
·91 lines (77 loc) · 2.03 KB
/
hbase_table_regions_by_regionserver.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2018-08-24 19:34:33 +0100 (Fri, 24 Aug 2018)
#
# https://github.com/harisekhon/devops-python-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
regionservers=""
port="${HBASE_REGIONSERVER_PORT:-16030}"
metrics="metrics"
usage(){
if [ -n "$*" ]; then
echo "$@"
echo
fi
cat <<EOF
Quick script to output region counts per table across RegionServers using the RegionServers JMX API
Tested on HBase 1.3
usage: ${0##*/} [options] regionserver1 regionserver2 regionserver3 ...
${0##*/} [options] regionserver{1..100}
-T --table Table to filter (regex)
-p --port RegionServer HTTP JMX port
EOF
exit 1
}
table=".*"
until [ $# -lt 1 ]; do
case $1 in
-T|--table) table="${2:-}"
shift || :
;;
-p|--port) port="${2:-$port}"
shift || :
;;
-h|--help) usage
;;
*) regionservers="$regionservers $1"
;;
esac
shift || :
done
if [ -z "$regionservers" ]; then
usage "regionservers not defined, must supply arguments of regionservers hosts"
fi
check_bin(){
local bin="$1"
if ! which $bin &>/dev/null; then
echo "'$bin' command not found in \$PATH ($PATH)"
exit 1
fi
}
check_bin curl
curl_options=""
if [ -z "${DEBUG:-}" ]; then
curl_options="$curl_options -s"
fi
for regionserver in $(tr ' ' '\n' <<< "$regionservers" | sort -u); do
echo "$regionserver:"
curl $curl_options "$regionserver:$port/jmx" |
grep "_table_.*${table}.*_region_" |
sed 's/.*_table_//; s/_region_/ /; s/_.*$//' |
sort -u |
awk '{print $1}' |
uniq -c |
sort -k1nr ||
curl ${curl_options% -s} "$regionserver:$port/jmx"
echo
done