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