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  package org.apache.hadoop.hbase.regionserver;
19  
20  import com.google.common.annotations.VisibleForTesting;
21  import org.apache.hadoop.hbase.classification.InterfaceAudience;
22  import org.apache.hadoop.hbase.classification.InterfaceStability;
23  import org.apache.hadoop.conf.Configuration;
24  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
25  
26  /**
27   * This class is for maintaining the various regionserver statistics
28   * and publishing them through the metrics interfaces.
29   * <p/>
30   * This class has a number of metrics variables that are publicly accessible;
31   * these variables (objects) have methods to update their values.
32   */
33  @InterfaceStability.Evolving
34  @InterfaceAudience.Private
35  public class MetricsRegionServer {
36    private final MetricsRegionServerSource serverSource;
37    private final MetricsRegionServerWrapper regionServerWrapper;
38    private final MetricsTable metricsTable;
39  
40    private final MetricsUserAggregate userAggregate;
41  
42    public MetricsRegionServer(Configuration conf, MetricsRegionServerWrapper regionServerWrapper,
43                               MetricsTable metricsTable) {
44      this(conf, regionServerWrapper,
45          CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
46              .createServer(regionServerWrapper), metricsTable);
47  
48    }
49  
50    MetricsRegionServer(Configuration conf, MetricsRegionServerWrapper regionServerWrapper,
51                        MetricsRegionServerSource serverSource, MetricsTable metricsTable) {
52      this.regionServerWrapper = regionServerWrapper;
53      this.serverSource = serverSource;
54      this.userAggregate = new MetricsUserAggregate(conf);
55      this.metricsTable = metricsTable;
56    }
57  
58    // for unit-test usage
59    public MetricsRegionServerSource getMetricsSource() {
60      return serverSource;
61    }
62  
63    @VisibleForTesting
64    public MetricsUserAggregate getMetricsUserAggregate() {
65      return userAggregate;
66    }
67  
68    public MetricsRegionServerWrapper getRegionServerWrapper() {
69      return regionServerWrapper;
70    }
71  
72    public void updatePut(long t) {
73      if (t > 1000) {
74        serverSource.incrSlowPut();
75      }
76      serverSource.updatePut(t);
77      userAggregate.updatePut(t);
78    }
79  
80    public void updateDelete(long t) {
81      if (t > 1000) {
82        serverSource.incrSlowDelete();
83      }
84      serverSource.updateDelete(t);
85      userAggregate.updateDelete(t);
86    }
87  
88    public void updateGet(long t) {
89      if (t > 1000) {
90        serverSource.incrSlowGet();
91      }
92      serverSource.updateGet(t);
93      userAggregate.updateGet(t);
94    }
95  
96    public void updateIncrement(long t) {
97      if (t > 1000) {
98        serverSource.incrSlowIncrement();
99      }
100     serverSource.updateIncrement(t);
101     userAggregate.updateIncrement(t);
102   }
103 
104   public void updateAppend(long t) {
105     if (t > 1000) {
106       serverSource.incrSlowAppend();
107     }
108     serverSource.updateAppend(t);
109     userAggregate.updateAppend(t);
110   }
111 
112   public void updateReplay(long t){
113     serverSource.updateReplay(t);
114     userAggregate.updateReplay(t);
115   }
116 
117   public void updateScanSize(long scanSize){
118     serverSource.updateScanSize(scanSize);
119   }
120 
121   public void updateScanTime(long t) {
122     serverSource.updateScanTime(t);
123     userAggregate.updateScanTime(t);
124   }
125 
126   public void updateSplitTime(long t) {
127     serverSource.updateSplitTime(t);
128   }
129 
130   public void incrSplitRequest() {
131     serverSource.incrSplitRequest();
132   }
133 
134   public void incrSplitSuccess() {
135     serverSource.incrSplitSuccess();
136   }
137 
138   public void updateFlush(String table, long t, long memstoreSize, long fileSize) {
139     serverSource.updateFlushTime(t);
140     serverSource.updateFlushMemstoreSize(memstoreSize);
141     serverSource.updateFlushOutputSize(fileSize);
142 
143     if (table != null) {
144       metricsTable.updateFlushTime(table, memstoreSize);
145       metricsTable.updateFlushMemstoreSize(table, memstoreSize);
146       metricsTable.updateFlushOutputSize(table, fileSize);
147     }
148   }
149 
150   public void updateCompaction(String table, boolean isMajor, long t, int inputFileCount,
151       int outputFileCount, long inputBytes, long outputBytes) {
152     serverSource.updateCompactionTime(isMajor, t);
153     serverSource.updateCompactionInputFileCount(isMajor, inputFileCount);
154     serverSource.updateCompactionOutputFileCount(isMajor, outputFileCount);
155     serverSource.updateCompactionInputSize(isMajor, inputBytes);
156     serverSource.updateCompactionOutputSize(isMajor, outputBytes);
157 
158     if (table != null) {
159       metricsTable.updateCompactionTime(table, isMajor, t);
160       metricsTable.updateCompactionInputFileCount(table, isMajor, inputFileCount);
161       metricsTable.updateCompactionOutputFileCount(table, isMajor, outputFileCount);
162       metricsTable.updateCompactionInputSize(table, isMajor, inputBytes);
163       metricsTable.updateCompactionOutputSize(table, isMajor, outputBytes);
164     }
165   }
166 }