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 */ 018 019package org.apache.hadoop.hbase.master; 020 021import org.apache.hadoop.hbase.metrics.BaseSourceImpl; 022import org.apache.hadoop.hbase.metrics.OperationMetrics; 023import org.apache.hadoop.metrics2.MetricHistogram; 024import org.apache.hadoop.metrics2.MetricsCollector; 025import org.apache.hadoop.metrics2.MetricsRecordBuilder; 026import org.apache.hadoop.metrics2.lib.MutableFastCounter; 027import org.apache.hadoop.metrics2.lib.MutableGaugeLong; 028import org.apache.yetus.audience.InterfaceAudience; 029 030@InterfaceAudience.Private 031public class MetricsAssignmentManagerSourceImpl 032 extends BaseSourceImpl 033 implements MetricsAssignmentManagerSource { 034 035 private MutableGaugeLong ritGauge; 036 private MutableGaugeLong ritCountOverThresholdGauge; 037 private MutableGaugeLong ritOldestAgeGauge; 038 private MetricHistogram ritDurationHisto; 039 private MutableGaugeLong deadServerOpenRegions; 040 private MutableGaugeLong unknownServerOpenRegions; 041 042 private MutableFastCounter operationCounter; 043 044 private OperationMetrics assignMetrics; 045 private OperationMetrics unassignMetrics; 046 private OperationMetrics moveMetrics; 047 private OperationMetrics reopenMetrics; 048 private OperationMetrics openMetrics; 049 private OperationMetrics closeMetrics; 050 private OperationMetrics splitMetrics; 051 private OperationMetrics mergeMetrics; 052 053 public MetricsAssignmentManagerSourceImpl() { 054 this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT); 055 } 056 057 public MetricsAssignmentManagerSourceImpl(String metricsName, 058 String metricsDescription, 059 String metricsContext, String metricsJmxContext) { 060 super(metricsName, metricsDescription, metricsContext, metricsJmxContext); 061 } 062 063 public void init() { 064 ritGauge = metricsRegistry.newGauge(RIT_COUNT_NAME, RIT_COUNT_DESC, 0L); 065 ritCountOverThresholdGauge = metricsRegistry.newGauge(RIT_COUNT_OVER_THRESHOLD_NAME, 066 RIT_COUNT_OVER_THRESHOLD_DESC,0L); 067 ritOldestAgeGauge = metricsRegistry.newGauge(RIT_OLDEST_AGE_NAME, RIT_OLDEST_AGE_DESC, 0L); 068 ritDurationHisto = metricsRegistry.newTimeHistogram(RIT_DURATION_NAME, RIT_DURATION_DESC); 069 operationCounter = metricsRegistry.getCounter(OPERATION_COUNT_NAME, 0L); 070 deadServerOpenRegions = metricsRegistry.newGauge(DEAD_SERVER_OPEN_REGIONS, "", 0); 071 unknownServerOpenRegions = metricsRegistry.newGauge(UNKNOWN_SERVER_OPEN_REGIONS, "", 0); 072 073 /** 074 * NOTE: Please refer to HBASE-9774 and HBASE-14282. Based on these two issues, HBase is 075 * moving away from using Hadoop's metric2 to having independent HBase specific Metrics. Use 076 * {@link BaseSourceImpl#registry} to register the new metrics. 077 */ 078 assignMetrics = new OperationMetrics(registry, ASSIGN_METRIC_PREFIX); 079 unassignMetrics = new OperationMetrics(registry, UNASSIGN_METRIC_PREFIX); 080 moveMetrics = new OperationMetrics(registry, MOVE_METRIC_PREFIX); 081 reopenMetrics = new OperationMetrics(registry, REOPEN_METRIC_PREFIX); 082 openMetrics = new OperationMetrics(registry, OPEN_METRIC_PREFIX); 083 closeMetrics = new OperationMetrics(registry, CLOSE_METRIC_PREFIX); 084 splitMetrics = new OperationMetrics(registry, SPLIT_METRIC_PREFIX); 085 mergeMetrics = new OperationMetrics(registry, MERGE_METRIC_PREFIX); 086 } 087 088 @Override 089 public void setRIT(final int ritCount) { 090 ritGauge.set(ritCount); 091 } 092 093 @Override 094 public void setRITCountOverThreshold(final int ritCount) { 095 ritCountOverThresholdGauge.set(ritCount); 096 } 097 098 @Override 099 public void setRITOldestAge(final long ritCount) { 100 ritOldestAgeGauge.set(ritCount); 101 } 102 103 @Override 104 public void incrementOperationCounter() { 105 operationCounter.incr(); 106 } 107 108 @Override 109 public void updateRitDuration(long duration) { 110 ritDurationHisto.add(duration); 111 } 112 113 @Override 114 public void updateDeadServerOpenRegions(int deadRegions) { 115 deadServerOpenRegions.set(deadRegions); 116 } 117 118 @Override 119 public void updateUnknownServerOpenRegions(int unknownRegions) { 120 unknownServerOpenRegions.set(unknownRegions); 121 } 122 123 @Override 124 public OperationMetrics getAssignMetrics() { 125 return assignMetrics; 126 } 127 128 @Override 129 public OperationMetrics getUnassignMetrics() { 130 return unassignMetrics; 131 } 132 133 @Override 134 public OperationMetrics getSplitMetrics() { 135 return splitMetrics; 136 } 137 138 @Override 139 public OperationMetrics getMergeMetrics() { 140 return mergeMetrics; 141 } 142 143 @Override 144 public OperationMetrics getMoveMetrics() { 145 return moveMetrics; 146 } 147 148 @Override 149 public OperationMetrics getReopenMetrics() { 150 return reopenMetrics; 151 } 152 153 @Override 154 public OperationMetrics getOpenMetrics() { 155 return openMetrics; 156 } 157 158 @Override 159 public OperationMetrics getCloseMetrics() { 160 return closeMetrics; 161 } 162 163 @Override 164 public void getMetrics(MetricsCollector metricsCollector, boolean all) { 165 MetricsRecordBuilder metricsRecordBuilder = metricsCollector.addRecord(metricsName); 166 metricsRegistry.snapshot(metricsRecordBuilder, all); 167 if(metricsAdapter != null) { 168 metricsAdapter.snapshotAllMetrics(registry, metricsRecordBuilder); 169 } 170 } 171}