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.metrics.BaseSourceImpl;
22  import org.apache.hadoop.metrics2.MetricHistogram;
23  import org.apache.hadoop.metrics2.MetricsCollector;
24  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
25  import org.apache.hadoop.metrics2.lib.Interns;
26  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
27  
28  /**
29   * Hadoop2 implementation of MetricsRegionServerSource.
30   *
31   * Implements BaseSource through BaseSourceImpl, following the pattern
32   */
33  public class MetricsRegionServerSourceImpl
34      extends BaseSourceImpl implements MetricsRegionServerSource {
35  
36  
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  
53    public MetricsRegionServerSourceImpl(MetricsRegionServerWrapper rsWrap) {
54      this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT, METRICS_JMX_CONTEXT, rsWrap);
55    }
56  
57    public MetricsRegionServerSourceImpl(String metricsName,
58                                         String metricsDescription,
59                                         String metricsContext,
60                                         String metricsJmxContext,
61                                         MetricsRegionServerWrapper rsWrap) {
62      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
63      this.rsWrap = rsWrap;
64  
65      putHisto = getMetricsRegistry().newHistogram(MUTATE_KEY);
66      slowPut = getMetricsRegistry().newCounter(SLOW_MUTATE_KEY, SLOW_MUTATE_DESC, 0l);
67  
68      deleteHisto = getMetricsRegistry().newHistogram(DELETE_KEY);
69      slowDelete = getMetricsRegistry().newCounter(SLOW_DELETE_KEY, SLOW_DELETE_DESC, 0l);
70  
71      getHisto = getMetricsRegistry().newHistogram(GET_KEY);
72      slowGet = getMetricsRegistry().newCounter(SLOW_GET_KEY, SLOW_GET_DESC, 0l);
73  
74      incrementHisto = getMetricsRegistry().newHistogram(INCREMENT_KEY);
75      slowIncrement = getMetricsRegistry().newCounter(SLOW_INCREMENT_KEY, SLOW_INCREMENT_DESC, 0l);
76  
77      appendHisto = getMetricsRegistry().newHistogram(APPEND_KEY);
78      slowAppend = getMetricsRegistry().newCounter(SLOW_APPEND_KEY, SLOW_APPEND_DESC, 0l);
79      
80      replayHisto = getMetricsRegistry().newHistogram(REPLAY_KEY);
81    }
82  
83    @Override
84    public void updatePut(long t) {
85      putHisto.add(t);
86    }
87  
88    @Override
89    public void updateDelete(long t) {
90      deleteHisto.add(t);
91    }
92  
93    @Override
94    public void updateGet(long t) {
95      getHisto.add(t);
96    }
97  
98    @Override
99    public void updateIncrement(long t) {
100     incrementHisto.add(t);
101   }
102 
103   @Override
104   public void updateAppend(long t) {
105     appendHisto.add(t);
106   }
107 
108   @Override
109   public void updateReplay(long t) {
110     replayHisto.add(t);
111   }
112 
113   @Override
114   public void incrSlowPut() {
115    slowPut.incr();
116   }
117 
118   @Override
119   public void incrSlowDelete() {
120     slowDelete.incr();
121   }
122 
123   @Override
124   public void incrSlowGet() {
125     slowGet.incr();
126   }
127 
128   @Override
129   public void incrSlowIncrement() {
130     slowIncrement.incr();
131   }
132 
133   @Override
134   public void incrSlowAppend() {
135     slowAppend.incr();
136   }
137 
138   /**
139    * Yes this is a get function that doesn't return anything.  Thanks Hadoop for breaking all
140    * expectations of java programmers.  Instead of returning anything Hadoop metrics expects
141    * getMetrics to push the metrics into the collector.
142    *
143    * @param metricsCollector Collector to accept metrics
144    * @param all              push all or only changed?
145    */
146   @Override
147   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
148 
149     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
150         .setContext(metricsContext);
151 
152     // rsWrap can be null because this function is called inside of init.
153     if (rsWrap != null) {
154       mrb.addGauge(Interns.info(REGION_COUNT, REGION_COUNT_DESC), rsWrap.getNumOnlineRegions())
155           .addGauge(Interns.info(STORE_COUNT, STORE_COUNT_DESC), rsWrap.getNumStores())
156           .addGauge(Interns.info(STOREFILE_COUNT, STOREFILE_COUNT_DESC), rsWrap.getNumStoreFiles())
157           .addGauge(Interns.info(MEMSTORE_SIZE, MEMSTORE_SIZE_DESC), rsWrap.getMemstoreSize())
158           .addGauge(Interns.info(STOREFILE_SIZE, STOREFILE_SIZE_DESC), rsWrap.getStoreFileSize())
159           .addGauge(Interns.info(RS_START_TIME_NAME, RS_START_TIME_DESC),
160               rsWrap.getStartCode())
161           .addCounter(Interns.info(TOTAL_REQUEST_COUNT, TOTAL_REQUEST_COUNT_DESC),
162               rsWrap.getTotalRequestCount())
163           .addCounter(Interns.info(READ_REQUEST_COUNT, READ_REQUEST_COUNT_DESC),
164               rsWrap.getReadRequestsCount())
165           .addCounter(Interns.info(WRITE_REQUEST_COUNT, WRITE_REQUEST_COUNT_DESC),
166               rsWrap.getWriteRequestsCount())
167           .addCounter(Interns.info(CHECK_MUTATE_FAILED_COUNT, CHECK_MUTATE_FAILED_COUNT_DESC),
168               rsWrap.getCheckAndMutateChecksFailed())
169           .addCounter(Interns.info(CHECK_MUTATE_PASSED_COUNT, CHECK_MUTATE_PASSED_COUNT_DESC),
170               rsWrap.getCheckAndMutateChecksPassed())
171           .addGauge(Interns.info(STOREFILE_INDEX_SIZE, STOREFILE_INDEX_SIZE_DESC),
172               rsWrap.getStoreFileIndexSize())
173           .addGauge(Interns.info(STATIC_INDEX_SIZE, STATIC_INDEX_SIZE_DESC),
174               rsWrap.getTotalStaticIndexSize())
175           .addGauge(Interns.info(STATIC_BLOOM_SIZE, STATIC_BLOOM_SIZE_DESC),
176             rsWrap.getTotalStaticBloomSize())
177           .addGauge(
178             Interns.info(NUMBER_OF_MUTATIONS_WITHOUT_WAL, NUMBER_OF_MUTATIONS_WITHOUT_WAL_DESC),
179               rsWrap.getNumMutationsWithoutWAL())
180           .addGauge(Interns.info(DATA_SIZE_WITHOUT_WAL, DATA_SIZE_WITHOUT_WAL_DESC),
181               rsWrap.getDataInMemoryWithoutWAL())
182           .addGauge(Interns.info(PERCENT_FILES_LOCAL, PERCENT_FILES_LOCAL_DESC),
183               rsWrap.getPercentFileLocal())
184           .addGauge(Interns.info(COMPACTION_QUEUE_LENGTH, COMPACTION_QUEUE_LENGTH_DESC),
185               rsWrap.getCompactionQueueSize())
186           .addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
187               rsWrap.getFlushQueueSize())
188           .addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
189               rsWrap.getBlockCacheFreeSize())
190           .addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
191               rsWrap.getBlockCacheCount())
192           .addGauge(Interns.info(BLOCK_CACHE_SIZE, BLOCK_CACHE_SIZE_DESC),
193               rsWrap.getBlockCacheSize())
194           .addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
195               rsWrap.getBlockCacheHitCount())
196           .addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
197               rsWrap.getBlockCacheMissCount())
198           .addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
199               rsWrap.getBlockCacheEvictedCount())
200           .addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
201               rsWrap.getBlockCacheHitPercent())
202           .addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
203               BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
204           .addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
205               rsWrap.getUpdatesBlockedTime())
206           .tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
207               rsWrap.getZookeeperQuorum())
208           .tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())
209           .tag(Interns.info(CLUSTER_ID_NAME, CLUSTER_ID_DESC), rsWrap.getClusterId());
210     }
211 
212     metricsRegistry.snapshot(mrb, all);
213   }
214 }