取得hbase 0.94.x 的系統資訊(2)

(問題)
在hbase 0.94.x版本中,如何取得hbase叢集的現況?

(方法)
在hbase 0.94.x中,可以透過兩種方法取得hbase叢集的現狀.
第二個方法是透過java api的方式.

若要透過java api取得hbase叢集的資訊,
必須在java程式中,除了一般讀取hbase的必須匯入的hbase物件外,
還必須額外匯入(import)三個物件資源(class):

import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.HServerLoad;

其中,ClusterStatus是用來取得狀態,
而ServerName和HServerLoad則是承接狀態的物件.
讀取叢集狀態的程式如下:
HBaseAdmin admin = new HBaseAdmin(conf);
// 取得hbase的設定

ClusterStatus status = admin.getClusterStatus();
// 取得hbase叢集的狀態,並在下列程式輸出

String version = status.getHBaseVersion();
System.out.println("Version " + version);

int regioncounts = status.getRegionsCount();
System.out.println("Regioncounts :" + regioncounts);

int servers = status.getServersSize();
System.out.println("Servers :" + servers);

double averageload = status.getAverageLoad();
System.out.println("Average load: " + averageload);

int deadservers = status.getDeadServers();
System.out.println("Deadservers : " + deadservers);
System.out.println("");

// 這裡serverInfo將儲存仍在服務的RegionServer名稱,
// 根據名稱,再查詢進一步的資訊
for (ServerName serverInfo : status.getServerInfo()){
    System.out.println("Hostname " + serverInfo.getHostname());
    HServerLoad serverLoad = status.getLoad(serverInfo);
    // serverLoad中儲存的資訊,
    // 可以用getRegionLoad取得包含shell(status 'detailed')指令中Region的所有資訊
    System.out.println("Number of Regions: " + serverLoad.getNumberOfRegions());
    System.out.println("UsedHeap MB: " + serverLoad.getUsedHeapMB());
    System.out.println("MaxHeap MB: " + serverLoad.getMaxHeapMB());
}

透過java api,我們可以簡單地確認hbase中RegionServer的狀態,
並決定RegionServer的負載是否過重.
程式執行後輸出的結果為:
Version 0.94.2
Regioncounts :2
Servers :3
Average load: 0.6666666666666666
Deadservers : 0
Hostname 192.168.2.131
Number of Regions: 1
UsedHeap MB: 30
MaxHeap MB: 197
Hostname master.hbase.mbwcl.nctu.edu.tw
Number of Regions: 1
UsedHeap MB: 35
MaxHeap MB: 197
Hostname 192.168.2.132
Number of Regions: 0
UsedHeap MB: 34
MaxHeap MB: 197

若是要使用更多的功能,請參考:
http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/ClusterStatus.html http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/HServerInfo.html
http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/HServerLoad.html
http://hbase.apache.org/0.94/apidocs/org/apache/hadoop/hbase/HServerLoad.RegionLoad.html
https://linuxjunkies.wordpress.com/2011/12/03/hbase-administration-using-the-java-api-using-code-examples/


留言

熱門文章

LTE筆記: RSRP, RSSI and RSRQ

[WiFi] WiFi 網路的識別: BSS, ESS, SSID, ESSID, BSSID

LTE筆記: 5G NR Measurement Events