3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 package org
.apache
.hadoop
.hbase
;
22 import edu
.umd
.cs
.findbugs
.annotations
.Nullable
;
23 import java
.util
.List
;
25 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
26 import org
.apache
.hadoop
.hbase
.client
.RegionStatesCount
;
27 import org
.apache
.hadoop
.hbase
.master
.RegionState
;
28 import org
.apache
.yetus
.audience
.InterfaceAudience
;
31 * Metrics information on the HBase cluster.
33 * <tt>ClusterMetrics</tt> provides clients with information such as:
35 * <li>The count and names of region servers in the cluster.</li>
36 * <li>The count and names of dead region servers in the cluster.</li>
37 * <li>The name of the active master for the cluster.</li>
38 * <li>The name(s) of the backup master(s) for the cluster, if they exist.</li>
39 * <li>The average cluster load.</li>
40 * <li>The number of regions deployed on the cluster.</li>
41 * <li>The number of requests since last report.</li>
42 * <li>Detailed region server loading and resource usage information,
43 * per server and per region.</li>
44 * <li>Regions in transition at master</li>
45 * <li>The unique cluster ID</li>
47 * <tt>{@link Option}</tt> provides a way to get desired ClusterStatus information.
48 * The following codes will get all the cluster information.
51 * // Original version still works
52 * Admin admin = connection.getAdmin();
53 * ClusterMetrics metrics = admin.getClusterStatus();
54 * // or below, a new version which has the same effects
55 * ClusterMetrics metrics = admin.getClusterStatus(EnumSet.allOf(Option.class));
58 * If information about live servers is the only wanted.
59 * then codes in the following way:
62 * Admin admin = connection.getAdmin();
63 * ClusterMetrics metrics = admin.getClusterStatus(EnumSet.of(Option.LIVE_SERVERS));
67 @InterfaceAudience.Public
68 public interface ClusterMetrics
{
71 * @return the HBase version string as reported by the HMaster
74 String
getHBaseVersion();
77 * @return the names of region servers on the dead list
79 List
<ServerName
> getDeadServerNames();
82 * @return the names of region servers on the live list
84 Map
<ServerName
, ServerMetrics
> getLiveServerMetrics();
87 * @return the number of regions deployed on the cluster
89 default int getRegionCount() {
90 return getLiveServerMetrics().entrySet().stream()
91 .mapToInt(v
-> v
.getValue().getRegionMetrics().size()).sum();
95 * @return the number of requests since last report
97 default long getRequestCount() {
98 return getLiveServerMetrics().entrySet().stream()
99 .flatMap(v
-> v
.getValue().getRegionMetrics().values().stream())
100 .mapToLong(RegionMetrics
::getRequestCount
).sum();
104 * Returns detailed information about the current master {@link ServerName}.
105 * @return current master information if it exists
108 ServerName
getMasterName();
111 * @return the names of backup masters
113 List
<ServerName
> getBackupMasterNames();
115 @InterfaceAudience.Private
116 List
<RegionState
> getRegionStatesInTransition();
119 String
getClusterId();
121 List
<String
> getMasterCoprocessorNames();
123 default long getLastMajorCompactionTimestamp(TableName table
) {
124 return getLiveServerMetrics().values().stream()
125 .flatMap(s
-> s
.getRegionMetrics().values().stream())
126 .filter(r
-> RegionInfo
.getTable(r
.getRegionName()).equals(table
))
127 .mapToLong(RegionMetrics
::getLastMajorCompactionTimestamp
).min().orElse(0);
130 default long getLastMajorCompactionTimestamp(byte[] regionName
) {
131 return getLiveServerMetrics().values().stream()
132 .filter(s
-> s
.getRegionMetrics().containsKey(regionName
))
134 .map(s
-> s
.getRegionMetrics().get(regionName
).getLastMajorCompactionTimestamp())
139 Boolean
getBalancerOn();
141 int getMasterInfoPort();
143 List
<ServerName
> getServersName();
146 * @return the average cluster load
148 default double getAverageLoad() {
149 int serverSize
= getLiveServerMetrics().size();
150 if (serverSize
== 0) {
153 return (double)getRegionCount() / (double)serverSize
;
157 * Provide region states count for given table.
158 * e.g howmany regions of give table are opened/closed/rit etc
160 * @return map of table to region states count
162 Map
<TableName
, RegionStatesCount
> getTableRegionStatesCount();
165 * Kinds of ClusterMetrics
169 * metrics about hbase version
173 * metrics about cluster id
177 * metrics about balancer is on or not
181 * metrics about live region servers
185 * metrics about dead region servers
189 * metrics about master name
193 * metrics about backup masters name
197 * metrics about master coprocessors
201 * metrics about regions in transition
203 REGIONS_IN_TRANSITION
,
209 * metrics about live region servers name
213 * metrics about table to no of regions status count
215 TABLE_TO_REGIONS_COUNT
,