zk: Add ZooKeeper connection count

This commit is contained in:
Björn Busse 2021-03-05 01:01:03 +01:00
parent c7184beaeb
commit 68a34ef498
2 changed files with 22 additions and 3 deletions

View File

@ -72,6 +72,7 @@ prom_hbase_writeable = Gauge('hbase_is_writeable', 'HBase is writeable')
prom_zookeeper_num = Gauge('zookeeper_num', 'Known ZooKeeper Servers') prom_zookeeper_num = Gauge('zookeeper_num', 'Known ZooKeeper Servers')
prom_zookeeper_num_live = Gauge('zookeeper_num_live', 'Live ZooKeeper Servers') prom_zookeeper_num_live = Gauge('zookeeper_num_live', 'Live ZooKeeper Servers')
prom_zookeeper_has_leader = Gauge('zookeeper_has_leader', 'ZooKeeper cluster has a leader') prom_zookeeper_has_leader = Gauge('zookeeper_has_leader', 'ZooKeeper cluster has a leader')
prom_zookeeper_num_connections = Gauge('zookeeper_num_connections', 'ZooKeeper connection count for all ZooKeeper servers combined')
# HDFS/HBase # HDFS/HBase
hdfs_config_file = "/etc/hadoop/conf/hdfs-site.xml" hdfs_config_file = "/etc/hadoop/conf/hdfs-site.xml"
@ -153,7 +154,9 @@ class zk():
zk_has_leader = 0 zk_has_leader = 0
zk_leader_address = "" zk_leader_address = ""
num_active_servers = 0 num_active_servers = 0
num_zk_connections = 0
re_mode = re.compile(r'^Mode:\s*(.+?)\s*$') re_mode = re.compile(r'^Mode:\s*(.+?)\s*$')
re_connections = re.compile(r'^Connections:\s*(.+?)\s*$')
for address in address_list: for address in address_list:
logging.info("Probing zookeeper at address: " + address) logging.info("Probing zookeeper at address: " + address)
@ -175,9 +178,16 @@ class zk():
zk_leader_address = address zk_leader_address = address
prom_zookeeper_has_leader.set(zk_has_leader) prom_zookeeper_has_leader.set(zk_has_leader)
match = re_connections.match(line.decode('utf-8'))
if match:
nconns = match.group(1)
logging.info("zk: server has %s connections", nconns)
num_zk_connections += int(nconns)
for line in error: for line in error:
logging.info(line.decode('utf-8')) logging.info(line.decode('utf-8'))
prom_zookeeper_num_connections.set(num_zk_connections)
prom_zookeeper_num_live.set(num_active_servers) prom_zookeeper_num_live.set(num_active_servers)
logging.info("zk: %d active ZooKeeper servers", num_active_servers) logging.info("zk: %d active ZooKeeper servers", num_active_servers)
if zk_has_leader: if zk_has_leader:

View File

@ -23,10 +23,9 @@ setup_suite() {
# Run exporter # Run exporter
cd ../../ cd ../../
printf "Starting hbase-exporter\n" printf "Starting hbase-exporter\n"
#./hbase-exporter --zookeeper-server ${ZK_SERVER:-"127.0.0.1"} 2>&1 > /dev/null &
./hbase-exporter --zookeeper-server=${ZK_SERVER:-"127.0.0.1"} \ ./hbase-exporter --zookeeper-server=${ZK_SERVER:-"127.0.0.1"} \
--hbase-pseudo-distributed=True \ --hbase-pseudo-distributed=True \
--hbase-table="foo" & --hbase-table="foo" 2>&1 > /dev/null &
PID=$! PID=$!
} }
@ -53,6 +52,16 @@ test_hbase_exporter_export_zk_live() {
assert_not_equals "0.0" "$r" "Zookeeper not live" assert_not_equals "0.0" "$r" "Zookeeper not live"
} }
test_hbase_exporter_export_hbase_up() {
r=$(curl -s http://127.0.0.1:9010 | grep '^hbase_up' | cut -d " " -f2)
assert_not_equals "0.0" "$r" "HBase down"
}
test_hbase_exporter_export_zk_connection_count() {
r=$(curl -s http://127.0.0.1:9010 | grep '^zookeeper_num_connections' | cut -d " " -f2)
assert_not_equals "0.0" "$r" "Zookeeper has no connections"
}
teardown_suite() { teardown_suite() {
kill $PID kill $PID
} }