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  
46    private final MutableCounterLong slowPut;
47    private final MutableCounterLong slowDelete;
48    private final MutableCounterLong slowGet;
49    private final MutableCounterLong slowIncrement;
50    private final MutableCounterLong slowAppend;
51    private final MutableCounterLong splitRequest;
52    private final MutableCounterLong splitSuccess;
53  
54    private final MetricHistogram splitTimeHisto;
55    private final MetricHistogram flushTimeHisto;
56  
57    public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
58      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
59    }
60  
61    public MetricsRegionServerSourceImpl(String metricsName,
62                                         String metricsDescription,
63                                         String metricsContext,
64                                         String metricsJmxContext,
65                                         MetricsRegionServerWrapper rsWrap) {
66      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
67      this.rsWrap = rsWrap;
68  
69      putHisto = getMetricsRegistry().newHistogram(MUTATE_KEY);
70      slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0l);
71  
72      deleteHisto = getMetricsRegistry().newHistogram(DELETE_KEY);
73      slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0l);
74  
75      getHisto = getMetricsRegistry().newHistogram(GET_KEY);
76      slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0l);
77  
78      incrementHisto = getMetricsRegistry().newHistogram(INCREMENT_KEY);
79      slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0l);
80  
81      appendHisto = getMetricsRegistry().newHistogram(APPEND_KEY);
82      slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l);
83      
84      replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY);
85  
86      splitTimeHisto = getMetricsRegistry().newHistogram(SPLIT_KEY);
87      flushTimeHisto = getMetricsRegistry().newHistogram(FLUSH_KEY);
88  
89      splitRequest = getMetricsRegistry().newCounter(SPLIT_REQUEST_KEY, SPLIT_REQUEST_DESC, 0l);
90      splitSuccess = getMetricsRegistry().newCounter(SPLIT_SUCCESS_KEY, SPLIT_SUCCESS_DESC, 0l);
91    }
92  
93    @Override
94    public void updatePut(long t) {
95      putHisto.add(t);
96    }
97  
98    @Override
99    public void updateDelete(long t) {
100     deleteHisto.add(t);
101   }
102 
103   @Override
104   public void updateGet(long t) {
105     getHisto.add(t);
106   }
107 
108   @Override
109   public void updateIncrement(long t) {
110     incrementHisto.add(t);
111   }
112 
113   @Override
114   public void updateAppend(long t) {
115     appendHisto.add(t);
116   }
117 
118   @Override
119   public void updateReplay(long t) {
120     replayHisto.add(t);
121   }
122 
123   @Override
124   public void incrSlowPut() {
125    slowPut.incr();
126   }
127 
128   @Override
129   public void incrSlowDelete() {
130     slowDelete.incr();
131   }
132 
133   @Override
134   public void incrSlowGet() {
135     slowGet.incr();
136   }
137 
138   @Override
139   public void incrSlowIncrement() {
140     slowIncrement.incr();
141   }
142 
143   @Override
144   public void incrSlowAppend() {
145     slowAppend.incr();
146   }
147 
148   @Override
149   public void incrSplitRequest() {
150     splitRequest.incr();
151   }
152 
153   @Override
154   public void incrSplitSuccess() {
155     splitSuccess.incr();
156   }
157 
158   @Override
159   public void updateSplitTime(long t) {
160     splitTimeHisto.add(t);
161   }
162 
163   @Override
164   public void updateFlushTime(long t) {
165     flushTimeHisto.add(t);
166   }
167 
168   /**
169    * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
170    * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
171    * getMetrics to push the metrics into the collector.
172    *
173    * @param metricsCollector Collector to accept metrics
174    * @param all              push all or only changed?
175    */
176   @Override
177   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
178 
179     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
180         .setContext(metricsContext);
181 
182     // rsWrap can be null because this function is called inside of init.
183     if (rsWrap != null) {
184       mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
185           .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
186           .addGauge(Interns.info(WALFILE_COUNT, WALFILE_COUNT_DESC), rsWrap.getNumWALFiles())
187           .addGauge(Interns.info(WALFILE_SIZE, WALFILE_SIZE_DESC), rsWrap.getWALFileSize())
188           .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
189           .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
190           .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
191           .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
192               rsWrap.getStartCode())
193           .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
194               rsWrap.getTotalRequestCount())
195           .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
196               rsWrap.getReadRequestsCount())
197           .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
198               rsWrap.getWriteRequestsCount())
199           .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
200               rsWrap.getCheckAndMutateChecksFailed())
201           .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
202               rsWrap.getCheckAndMutateChecksPassed())
203           .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
204               rsWrap.getStoreFileIndexSize())
205           .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
206               rsWrap.getTotalStaticIndexSize())
207           .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
208             rsWrap.getTotalStaticBloomSize())
209           .addGauge(
210             Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
211               rsWrap.getNumMutationsWithoutWAL())
212           .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
213               rsWrap.getDataInMemoryWithoutWAL())
214           .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
215               rsWrap.getPercentFileLocal())
216           .addGauge(Interns.info(SPLIT_QUEUE_LENGTH, SPLIT_QUEUE_LENGTH_DESC),
217               rsWrap.getSplitQueueSize())
218           .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
219               rsWrap.getCompactionQueueSize())
220           .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
221               rsWrap.getFlushQueueSize())
222           .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
223               rsWrap.getBlockCacheFreeSize())
224           .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
225               rsWrap.getBlockCacheCount())
226           .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
227               rsWrap.getBlockCacheSize())
228           .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
229               rsWrap.getBlockCacheHitCount())
230           .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
231               rsWrap.getBlockCacheMissCount())
232           .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
233               rsWrap.getBlockCacheEvictedCount())
234           .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
235               rsWrap.getBlockCacheHitPercent())
236           .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
237               BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
238           .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
239               rsWrap.getUpdatesBlockedTime())
240           .addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
241               rsWrap.getFlushedCellsCount())
242           .addCounter(Interns.info(COMPACTED_CELLS, COMPACTED_CELLS_DESC),
243               rsWrap.getCompactedCellsCount())
244           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS, MAJOR_COMPACTED_CELLS_DESC),
245               rsWrap.getMajorCompactedCellsCount())
246           .addCounter(Interns.info(FLUSHED_CELLS_SIZE, FLUSHED_CELLS_SIZE_DESC),
247               rsWrap.getFlushedCellsSize())
248           .addCounter(Interns.info(COMPACTED_CELLS_SIZE, COMPACTED_CELLS_SIZE_DESC),
249               rsWrap.getCompactedCellsSize())
250           .addCounter(Interns.info(MAJOR_COMPACTED_CELLS_SIZE, MAJOR_COMPACTED_CELLS_SIZE_DESC),
251               rsWrap.getMajorCompactedCellsSize())
252 
253           .addCounter(Interns.info(HEDGED_READS, HEDGED_READS_DESC), rsWrap.getHedgedReadOps())
254           .addCounter(Interns.info(HEDGED_READ_WINS, HEDGED_READ_WINS_DESC),
255               rsWrap.getHedgedReadWins())
256 
257           .addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
258             rsWrap.getBlockedRequestsCount())
259 
260           .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
261               rsWrap.getZookeeperQuorum())
262           .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
263           .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
264     }
265 
266     metricsRegistry.snapshot(mrb, all);
267   }
268 }