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 org.apache.hadoop.hbase.classification.InterfaceAudience;
21  import org.apache.hadoop.hbase.classification.InterfaceStability;
22  import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
23  
24  /**
25   * <p>
26   * This class is for maintaining the various regionserver statistics
27   * and publishing them through the metrics interfaces.
28   * </p>
29   * This class has a number of metrics variables that are publicly accessible;
30   * these variables (objects) have methods to update their values.
31   */
32  @InterfaceStability.Evolving
33  @InterfaceAudience.Private
34  public class MetricsRegionServer {
35    private MetricsRegionServerSource serverSource;
36    private MetricsRegionServerWrapper regionServerWrapper;
37  
38    public MetricsRegionServer(MetricsRegionServerWrapper regionServerWrapper) {
39      this(regionServerWrapper,
40          CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
41              .createServer(regionServerWrapper));
42  
43    }
44  
45    MetricsRegionServer(MetricsRegionServerWrapper regionServerWrapper,
46                        MetricsRegionServerSource serverSource) {
47      this.regionServerWrapper = regionServerWrapper;
48      this.serverSource = serverSource;
49    }
50  
51    // for unit-test usage
52    public MetricsRegionServerSource getMetricsSource() {
53      return serverSource;
54    }
55  
56    public MetricsRegionServerWrapper getRegionServerWrapper() {
57      return regionServerWrapper;
58    }
59  
60    public void updatePut(long t) {
61      if (t > 1000) {
62        serverSource.incrSlowPut();
63      }
64      serverSource.updatePut(t);
65    }
66  
67    public void updateDelete(long t) {
68      if (t > 1000) {
69        serverSource.incrSlowDelete();
70      }
71      serverSource.updateDelete(t);
72    }
73  
74    public void updateGet(long t) {
75      if (t > 1000) {
76        serverSource.incrSlowGet();
77      }
78      serverSource.updateGet(t);
79    }
80  
81    public void updateIncrement(long t) {
82      if (t > 1000) {
83        serverSource.incrSlowIncrement();
84      }
85      serverSource.updateIncrement(t);
86    }
87  
88    public void updateAppend(long t) {
89      if (t > 1000) {
90        serverSource.incrSlowAppend();
91      }
92      serverSource.updateAppend(t);
93    }
94  
95    public void updateReplay(long t){
96      serverSource.updateReplay(t);
97    }
98  
99    public void updateScannerNext(long scanSize){
100     serverSource.updateScannerNext(scanSize);
101   }
102 
103   public void updateSplitTime(long t) {
104     serverSource.updateSplitTime(t);
105   }
106 
107   public void incrSplitRequest() {
108     serverSource.incrSplitRequest();
109   }
110 
111   public void incrSplitSuccess() {
112     serverSource.incrSplitSuccess();
113   }
114 
115   public void updateFlushTime(long t) {
116     serverSource.updateFlushTime(t);
117   }
118 }