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