001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import org.apache.hadoop.hbase.metrics.BaseSourceImpl; 021import org.apache.hadoop.hbase.metrics.OperationMetrics; 022import org.apache.hadoop.metrics2.MetricHistogram; 023import org.apache.hadoop.metrics2.MetricsCollector; 024import org.apache.hadoop.metrics2.MetricsRecordBuilder; 025import org.apache.hadoop.metrics2.lib.MutableFastCounter; 026import org.apache.hadoop.metrics2.lib.MutableGaugeLong; 027import org.apache.yetus.audience.InterfaceAudience; 028 029@InterfaceAudience.Private 030public class MetricsAssignmentManagerSourceImpl extends BaseSourceImpl 031 implements MetricsAssignmentManagerSource { 032 033 private MutableGaugeLong ritGauge; 034 private MutableGaugeLong ritCountOverThresholdGauge; 035 private MutableGaugeLong ritOldestAgeGauge; 036 private MetricHistogram ritDurationHisto; 037 private MutableGaugeLong deadServerOpenRegions; 038 private MutableGaugeLong unknownServerOpenRegions; 039 040 private MutableGaugeLong orphanRegionsOnRsGauge; 041 private MutableGaugeLong orphanRegionsOnFsGauge; 042 private MutableGaugeLong inconsistentRegionsGauge; 043 044 private MutableGaugeLong holesGauge; 045 private MutableGaugeLong overlapsGauge; 046 private MutableGaugeLong unknownServerRegionsGauge; 047 private MutableGaugeLong emptyRegionInfoRegionsGauge; 048 049 private MutableFastCounter operationCounter; 050 051 private OperationMetrics assignMetrics; 052 private OperationMetrics unassignMetrics; 053 private OperationMetrics moveMetrics; 054 private OperationMetrics reopenMetrics; 055 private OperationMetrics openMetrics; 056 private OperationMetrics closeMetrics; 057 private OperationMetrics splitMetrics; 058 private OperationMetrics mergeMetrics; 059 060 public MetricsAssignmentManagerSourceImpl() { 061 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); 062 } 063 064 public MetricsAssignmentManagerSourceImpl(String metricsName, String metricsDescription, 065 String metricsContext, String metricsJmxContext) { 066 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 067 } 068 069 @Override 070 public void init() { 071 ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, RIT_COUNT_DESC, 0L); 072 ritCountOverThresholdGauge = 073 metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, RIT_COUNT_OVER_THRESHOLD_DESC, 0L); 074 ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, RIT_OLDEST_AGE_DESC, 0L); 075 ritDurationHisto = metricsRegistry.newTimeHistogram(RIT_DURATION_NAME, RIT_DURATION_DESC); 076 operationCounter = metricsRegistry.getCounter(OPERATION_COUNT_NAME, 0L); 077 deadServerOpenRegions = metricsRegistry.newGauge(DEAD_SERVER_OPEN_REGIONS, "", 0); 078 unknownServerOpenRegions = metricsRegistry.newGauge(UNKNOWN_SERVER_OPEN_REGIONS, "", 0); 079 080 orphanRegionsOnRsGauge = 081 metricsRegistry.newGauge(ORPHAN_REGIONS_ON_RS, ORPHAN_REGIONS_ON_RS_DESC, 0L); 082 orphanRegionsOnFsGauge = 083 metricsRegistry.newGauge(ORPHAN_REGIONS_ON_FS, ORPHAN_REGIONS_ON_FS_DESC, 0L); 084 inconsistentRegionsGauge = 085 metricsRegistry.newGauge(INCONSISTENT_REGIONS, INCONSISTENT_REGIONS_DESC, 0L); 086 087 holesGauge = metricsRegistry.newGauge(HOLES, HOLES_DESC, 0L); 088 overlapsGauge = metricsRegistry.newGauge(OVERLAPS, OVERLAPS_DESC, 0L); 089 unknownServerRegionsGauge = 090 metricsRegistry.newGauge(UNKNOWN_SERVER_REGIONS, UNKNOWN_SERVER_REGIONS_DESC, 0L); 091 emptyRegionInfoRegionsGauge = 092 metricsRegistry.newGauge(EMPTY_REGION_INFO_REGIONS, EMPTY_REGION_INFO_REGIONS_DESC, 0L); 093 094 /** 095 * NOTE: Please refer to HBASE-9774 and HBASE-14282. Based on these two issues, HBase is moving 096 * away from using Hadoop's metric2 to having independent HBase specific Metrics. Use 097 * {@link BaseSourceImpl#registry} to register the new metrics. 098 */ 099 assignMetrics = new OperationMetrics(registry, ASSIGN_METRIC_PREFIX); 100 unassignMetrics = new OperationMetrics(registry, UNASSIGN_METRIC_PREFIX); 101 moveMetrics = new OperationMetrics(registry, MOVE_METRIC_PREFIX); 102 reopenMetrics = new OperationMetrics(registry, REOPEN_METRIC_PREFIX); 103 openMetrics = new OperationMetrics(registry, OPEN_METRIC_PREFIX); 104 closeMetrics = new OperationMetrics(registry, CLOSE_METRIC_PREFIX); 105 splitMetrics = new OperationMetrics(registry, SPLIT_METRIC_PREFIX); 106 mergeMetrics = new OperationMetrics(registry, MERGE_METRIC_PREFIX); 107 } 108 109 @Override 110 public void setRIT(final int ritCount) { 111 ritGauge.set(ritCount); 112 } 113 114 @Override 115 public void setRITCountOverThreshold(final int ritCount) { 116 ritCountOverThresholdGauge.set(ritCount); 117 } 118 119 @Override 120 public void setRITOldestAge(final long ritOldestAge) { 121 ritOldestAgeGauge.set(ritOldestAge); 122 } 123 124 @Override 125 public void incrementOperationCounter() { 126 operationCounter.incr(); 127 } 128 129 @Override 130 public void updateRitDuration(long duration) { 131 ritDurationHisto.add(duration); 132 } 133 134 @Override 135 public void updateDeadServerOpenRegions(int deadRegions) { 136 deadServerOpenRegions.set(deadRegions); 137 } 138 139 @Override 140 public void updateUnknownServerOpenRegions(int unknownRegions) { 141 unknownServerOpenRegions.set(unknownRegions); 142 } 143 144 @Override 145 public void setOrphanRegionsOnRs(int orphanRegionsOnRs) { 146 orphanRegionsOnRsGauge.set(orphanRegionsOnRs); 147 } 148 149 @Override 150 public void setOrphanRegionsOnFs(int orphanRegionsOnFs) { 151 orphanRegionsOnFsGauge.set(orphanRegionsOnFs); 152 } 153 154 @Override 155 public void setInconsistentRegions(int inconsistentRegions) { 156 inconsistentRegionsGauge.set(inconsistentRegions); 157 } 158 159 @Override 160 public void setHoles(int holes) { 161 holesGauge.set(holes); 162 } 163 164 @Override 165 public void setOverlaps(int overlaps) { 166 overlapsGauge.set(overlaps); 167 } 168 169 @Override 170 public void setUnknownServerRegions(int unknownServerRegions) { 171 unknownServerRegionsGauge.set(unknownServerRegions); 172 } 173 174 @Override 175 public void setEmptyRegionInfoRegions(int emptyRegionInfoRegions) { 176 emptyRegionInfoRegionsGauge.set(emptyRegionInfoRegions); 177 } 178 179 @Override 180 public OperationMetrics getAssignMetrics() { 181 return assignMetrics; 182 } 183 184 @Override 185 public OperationMetrics getUnassignMetrics() { 186 return unassignMetrics; 187 } 188 189 @Override 190 public OperationMetrics getSplitMetrics() { 191 return splitMetrics; 192 } 193 194 @Override 195 public OperationMetrics getMergeMetrics() { 196 return mergeMetrics; 197 } 198 199 @Override 200 public OperationMetrics getMoveMetrics() { 201 return moveMetrics; 202 } 203 204 @Override 205 public OperationMetrics getReopenMetrics() { 206 return reopenMetrics; 207 } 208 209 @Override 210 public OperationMetrics getOpenMetrics() { 211 return openMetrics; 212 } 213 214 @Override 215 public OperationMetrics getCloseMetrics() { 216 return closeMetrics; 217 } 218 219 @Override 220 public void getMetrics(MetricsCollector metricsCollector, boolean all) { 221 MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName); 222 metricsRegistry.snapshot(metricsRecordBuilder, all); 223 if (metricsAdapter != null) { 224 metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder); 225 } 226 } 227}