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.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  
39  
40    final MetricsRegionServerWrapper rsWrap;
41    private final MetricHistogram putHisto;
42    private final MetricHistogram deleteHisto;
43    private final MetricHistogram getHisto;
44    private final MetricHistogram incrementHisto;
45    private final MetricHistogram appendHisto;
46    private final MetricHistogram replayHisto;
47  
48    private final MutableCounterLong slowPut;
49    private final MutableCounterLong slowDelete;
50    private final MutableCounterLong slowGet;
51    private final MutableCounterLong slowIncrement;
52    private final MutableCounterLong slowAppend;
53  
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  
85    @Override
86    public void updatePut(long t) {
87      putHisto.add(t);
88    }
89  
90    @Override
91    public void updateDelete(long t) {
92      deleteHisto.add(t);
93    }
94  
95    @Override
96    public void updateGet(long t) {
97      getHisto.add(t);
98    }
99  
100   @Override
101   public void updateIncrement(long t) {
102     incrementHisto.add(t);
103   }
104 
105   @Override
106   public void updateAppend(long t) {
107     appendHisto.add(t);
108   }
109 
110   @Override
111   public void updateReplay(long t) {
112     replayHisto.add(t);
113   }
114 
115   @Override
116   public void incrSlowPut() {
117    slowPut.incr();
118   }
119 
120   @Override
121   public void incrSlowDelete() {
122     slowDelete.incr();
123   }
124 
125   @Override
126   public void incrSlowGet() {
127     slowGet.incr();
128   }
129 
130   @Override
131   public void incrSlowIncrement() {
132     slowIncrement.incr();
133   }
134 
135   @Override
136   public void incrSlowAppend() {
137     slowAppend.incr();
138   }
139 
140   /**
141    * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
142    * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
143    * getMetrics to push the metrics into the collector.
144    *
145    * @param metricsCollector Collector to accept metrics
146    * @param all              push all or only changed?
147    */
148   @Override
149   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
150 
151     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
152         .setContext(metricsContext);
153 
154     // rsWrap can be null because this function is called inside of init.
155     if (rsWrap != null) {
156       mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
157           .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
158           .addGauge(Interns.info(HLOGFILE_COUNT, HLOGFILE_COUNT_DESC), rsWrap.getNumHLogFiles())
159           .addGauge(Interns.info(HLOGFILE_SIZE, HLOGFILE_SIZE_DESC), rsWrap.getHLogFileSize())
160           .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
161           .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
162           .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
163           .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
164               rsWrap.getStartCode())
165           .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
166               rsWrap.getTotalRequestCount())
167           .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
168               rsWrap.getReadRequestsCount())
169           .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
170               rsWrap.getWriteRequestsCount())
171           .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
172               rsWrap.getCheckAndMutateChecksFailed())
173           .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
174               rsWrap.getCheckAndMutateChecksPassed())
175           .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
176               rsWrap.getStoreFileIndexSize())
177           .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
178               rsWrap.getTotalStaticIndexSize())
179           .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
180             rsWrap.getTotalStaticBloomSize())
181           .addGauge(
182             Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
183               rsWrap.getNumMutationsWithoutWAL())
184           .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
185               rsWrap.getDataInMemoryWithoutWAL())
186           .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
187               rsWrap.getPercentFileLocal())
188           .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
189               rsWrap.getCompactionQueueSize())
190           .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
191               rsWrap.getFlushQueueSize())
192           .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
193               rsWrap.getBlockCacheFreeSize())
194           .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
195               rsWrap.getBlockCacheCount())
196           .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
197               rsWrap.getBlockCacheSize())
198           .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
199               rsWrap.getBlockCacheHitCount())
200           .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
201               rsWrap.getBlockCacheMissCount())
202           .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
203               rsWrap.getBlockCacheEvictedCount())
204           .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
205               rsWrap.getBlockCacheHitPercent())
206           .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
207               BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
208           .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
209               rsWrap.getUpdatesBlockedTime())
210           .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
211               rsWrap.getZookeeperQuorum())
212           .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
213           .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
214     }
215 
216     metricsRegistry.snapshot(mrb, all);
217   }
218 }