HBASE-26481 Consider rolling upgrading from old region replication framework (#3880)
[hbase.git] / hbase-client / src / main / java / org / apache / hadoop / hbase / ClusterMetrics.java
blob497ab938856b5f90dcbab4c7395847219b272bab
1 /**
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;
24 import java.util.Map;
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;
30 /**
31 * Metrics information on the HBase cluster.
32 * <p>
33 * <tt>ClusterMetrics</tt> provides clients with information such as:
34 * <ul>
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>
46 * </ul>
47 * <tt>{@link Option}</tt> provides a way to get desired ClusterStatus information.
48 * The following codes will get all the cluster information.
49 * <pre>
50 * {@code
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));
56 * }
57 * </pre>
58 * If information about live servers is the only wanted.
59 * then codes in the following way:
60 * <pre>
61 * {@code
62 * Admin admin = connection.getAdmin();
63 * ClusterMetrics metrics = admin.getClusterStatus(EnumSet.of(Option.LIVE_SERVERS));
64 * }
65 * </pre>
67 @InterfaceAudience.Public
68 public interface ClusterMetrics {
70 /**
71 * @return the HBase version string as reported by the HMaster
73 @Nullable
74 String getHBaseVersion();
76 /**
77 * @return the names of region servers on the dead list
79 List<ServerName> getDeadServerNames();
81 /**
82 * @return the names of region servers on the live list
84 Map<ServerName, ServerMetrics> getLiveServerMetrics();
86 /**
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();
94 /**
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
107 @Nullable
108 ServerName getMasterName();
111 * @return the names of backup masters
113 List<ServerName> getBackupMasterNames();
115 @InterfaceAudience.Private
116 List<RegionState> getRegionStatesInTransition();
118 @Nullable
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))
133 .findAny()
134 .map(s -> s.getRegionMetrics().get(regionName).getLastMajorCompactionTimestamp())
135 .orElse(0L);
138 @Nullable
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) {
151 return 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
167 enum Option {
169 * metrics about hbase version
171 HBASE_VERSION,
173 * metrics about cluster id
175 CLUSTER_ID,
177 * metrics about balancer is on or not
179 BALANCER_ON,
181 * metrics about live region servers
183 LIVE_SERVERS,
185 * metrics about dead region servers
187 DEAD_SERVERS,
189 * metrics about master name
191 MASTER,
193 * metrics about backup masters name
195 BACKUP_MASTERS,
197 * metrics about master coprocessors
199 MASTER_COPROCESSORS,
201 * metrics about regions in transition
203 REGIONS_IN_TRANSITION,
205 * metrics info port
207 MASTER_INFO_PORT,
209 * metrics about live region servers name
211 SERVERS_NAME,
213 * metrics about table to no of regions status count
215 TABLE_TO_REGIONS_COUNT,