View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.regionserver;
20  
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.MetricHistogram;
24  import org.apache.hadoop.metrics2.MetricsCollector;
25  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
26  import org.apache.hadoop.metrics2.lib.Interns;
27  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
28  
29  /**
30   * Hadoop2 implementation of MetricsRegionServerSource.
31   *
32   * Implements BaseSource through BaseSourceImpl, following the pattern
33   */
34  @InterfaceAudience.Private
35  public class MetricsRegionServerSourceImpl
36      extends BaseSourceImpl implements MetricsRegionServerSource {
37  
38    final MetricsRegionServerWrapper rsWrap;
39    private final MetricHistogram putHisto;
40    private final MetricHistogram deleteHisto;
41    private final MetricHistogram getHisto;
42    private final MetricHistogram incrementHisto;
43    private final MetricHistogram appendHisto;
44    private final MetricHistogram replayHisto;
45    private final MetricHistogram scanNextHisto;
46  
47    private final MutableCounterLong slowPut;
48    private final MutableCounterLong slowDelete;
49    private final MutableCounterLong slowGet;
50    private final MutableCounterLong slowIncrement;
51    private final MutableCounterLong slowAppend;
52    private final MutableCounterLong splitRequest;
53    private final MutableCounterLong splitSuccess;
54  
55    private final MetricHistogram splitTimeHisto;
56    private final MetricHistogram flushTimeHisto;
57  
58    public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
59      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
60    }
61  
62    public MetricsRegionServerSourceImpl(String metricsName,
63                                         String metricsDescription,
64                                         String metricsContext,
65                                         String metricsJmxContext,
66                                         MetricsRegionServerWrapper rsWrap) {
67      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
68      this.rsWrap = rsWrap;
69  
70      putHisto = getMetricsRegistry().newHistogram(MUTATE_KEY);
71      slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0l);
72  
73      deleteHisto = getMetricsRegistry().newHistogram(DELETE_KEY);
74      slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0l);
75  
76      getHisto = getMetricsRegistry().newHistogram(GET_KEY);
77      slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0l);
78  
79      incrementHisto = getMetricsRegistry().newHistogram(INCREMENT_KEY);
80      slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0L);
81  
82      appendHisto = getMetricsRegistry().newHistogram(APPEND_KEY);
83      slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l);
84      
85      replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY);
86      scanNextHisto = getMetricsRegistry().newHistogram(SCAN_NEXT_KEY);
87  
88      splitTimeHisto = getMetricsRegistry().newHistogram(SPLIT_KEY);
89      flushTimeHisto = getMetricsRegistry().newHistogram(FLUSH_KEY);
90  
91      splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0l);
92      splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0l);
93    }
94  
95    @Override
96    public void updatePut(long t) {
97      putHisto.add(t);
98    }
99  
100   @Override
101   public void updateDelete(long t) {
102     deleteHisto.add(t);
103   }
104 
105   @Override
106   public void updateGet(long t) {
107     getHisto.add(t);
108   }
109 
110   @Override
111   public void updateIncrement(long t) {
112     incrementHisto.add(t);
113   }
114 
115   @Override
116   public void updateAppend(long t) {
117     appendHisto.add(t);
118   }
119 
120   @Override
121   public void updateReplay(long t) {
122     replayHisto.add(t);
123   }
124 
125   @Override
126   public void updateScannerNext(long scanSize) {
127     scanNextHisto.add(scanSize);
128   }
129 
130   @Override
131   public void incrSlowPut() {
132    slowPut.incr();
133   }
134 
135   @Override
136   public void incrSlowDelete() {
137     slowDelete.incr();
138   }
139 
140   @Override
141   public void incrSlowGet() {
142     slowGet.incr();
143   }
144 
145   @Override
146   public void incrSlowIncrement() {
147     slowIncrement.incr();
148   }
149 
150   @Override
151   public void incrSlowAppend() {
152     slowAppend.incr();
153   }
154 
155   @Override
156   public void incrSplitRequest() {
157     splitRequest.incr();
158   }
159 
160   @Override
161   public void incrSplitSuccess() {
162     splitSuccess.incr();
163   }
164 
165   @Override
166   public void updateSplitTime(long t) {
167     splitTimeHisto.add(t);
168   }
169 
170   @Override
171   public void updateFlushTime(long t) {
172     flushTimeHisto.add(t);
173   }
174 
175   /**
176    * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
177    * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
178    * getMetrics to push the metrics into the collector.
179    *
180    * @param metricsCollector Collector to accept metrics
181    * @param all              push all or only changed?
182    */
183   @Override
184   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
185 
186     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
187 
188     // rsWrap can be null because this function is called inside of init.
189     if (rsWrap != null) {
190       mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
191           .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
192           .addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
193           .addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
194           .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
195           .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
196           .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
197           .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
198               rsWrap.getStartCode())
199           .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
200               rsWrap.getTotalRequestCount())
201           .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
202               rsWrap.getReadRequestsCount())
203           .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
204               rsWrap.getWriteRequestsCount())
205           .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
206               rsWrap.getCheckAndMutateChecksFailed())
207           .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
208               rsWrap.getCheckAndMutateChecksPassed())
209           .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
210               rsWrap.getStoreFileIndexSize())
211           .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
212               rsWrap.getTotalStaticIndexSize())
213           .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
214             rsWrap.getTotalStaticBloomSize())
215           .addGauge(
216             Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
217               rsWrap.getNumMutationsWithoutWAL())
218           .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
219               rsWrap.getDataInMemoryWithoutWAL())
220           .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
221               rsWrap.getPercentFileLocal())
222           .addGauge(Interns.info(PERCENT_FILES_LOCAL_SECONDARY_REGIONS,
223               PERCENT_FILES_LOCAL_SECONDARY_REGIONS_DESC),
224               rsWrap.getPercentFileLocalSecondaryRegions())
225           .addGauge(Interns.info(SPLIT_QUEUE_LENGTH, SPLIT_QUEUE_LENGTH_DESC),
226               rsWrap.getSplitQueueSize())
227           .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
228               rsWrap.getCompactionQueueSize())
229           .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
230               rsWrap.getFlushQueueSize())
231           .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
232               rsWrap.getBlockCacheFreeSize())
233           .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
234               rsWrap.getBlockCacheCount())
235           .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
236               rsWrap.getBlockCacheSize())
237           .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
238               rsWrap.getBlockCacheHitCount())
239           .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
240               rsWrap.getBlockCacheMissCount())
241           .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
242               rsWrap.getBlockCacheEvictedCount())
243           .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
244               rsWrap.getBlockCacheHitPercent())
245           .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
246               BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
247           .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
248               rsWrap.getUpdatesBlockedTime())
249           .addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
250               rsWrap.getFlushedCellsCount())
251           .addCounter(Interns.info(COMPACTED_CELLS, COMPACTED_CELLS_DESC),
252               rsWrap.getCompactedCellsCount())
253           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS, MAJOR_COMPACTED_CELLS_DESC),
254               rsWrap.getMajorCompactedCellsCount())
255           .addCounter(Interns.info(FLUSHED_CELLS_SIZE, FLUSHED_CELLS_SIZE_DESC),
256               rsWrap.getFlushedCellsSize())
257           .addCounter(Interns.info(COMPACTED_CELLS_SIZE, COMPACTED_CELLS_SIZE_DESC),
258               rsWrap.getCompactedCellsSize())
259           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS_SIZE, MAJOR_COMPACTED_CELLS_SIZE_DESC),
260               rsWrap.getMajorCompactedCellsSize())
261 
262           .addCounter(Interns.info(HEDGED_READS, HEDGED_READS_DESC), rsWrap.getHedgedReadOps())
263           .addCounter(Interns.info(HEDGED_READ_WINS, HEDGED_READ_WINS_DESC),
264               rsWrap.getHedgedReadWins())
265 
266           .addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
267             rsWrap.getBlockedRequestsCount())
268 
269           .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
270               rsWrap.getZookeeperQuorum())
271           .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
272           .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
273     }
274 
275     metricsRegistry.snapshot(mrb, all);
276   }
277 }