监控数据写入:通过 Linux 定时任务(crontab)调用脚本,采集 HBase 监控数据(hbase status/JMX),写入 MySQL:
crontab -e 配置每分钟采集一次
*/1 * * * * /usr/local/scripts/hbase_monitor.sh >> /var/log/hbase_monitor.log 2>&1
脚本示例(hbase_monitor.sh):
!/bin/bash
采集HBase RegionServer数量
RS_COUNT=$(hbase shell -n "status" | grep "RegionServers" | awk '{print $2}')
写入MySQL
mysql -h mysql-ip -u root -pMysql@123 -e "INSERT INTO hbase_monitor (rs_count, collect_time) VALUES ($RS_COUNT, NOW());"
MySQL 表设计:针对 HBase 监控数据设计宽表,字段包含指标名、指标值、采集时间、集群节点等。