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.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.classification.InterfaceAudience;
23  import org.apache.hadoop.classification.InterfaceStability;
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 Log LOG = LogFactory.getLog(this.getClass());
37    private MetricsRegionServerSource serverSource;
38    private MetricsRegionServerWrapper regionServerWrapper;
39  
40    public MetricsRegionServer(MetricsRegionServerWrapper regionServerWrapper) {
41      this.regionServerWrapper = regionServerWrapper;
42      serverSource =
43              CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
44              .createServer(regionServerWrapper);
45    }
46  
47    // for unit-test usage
48    public MetricsRegionServerSource getMetricsSource() {
49      return serverSource;
50    }
51  
52    public MetricsRegionServerWrapper getRegionServerWrapper() {
53      return regionServerWrapper;
54    }
55  
56    public void updatePut(long t){
57      if (t > 1000) {
58        serverSource.incrSlowPut();
59      }
60      serverSource.updatePut(t);
61    }
62  
63    public void updateDelete(long t){
64      if (t > 1000) {
65        serverSource.incrSlowDelete();
66      }
67      serverSource.updateDelete(t);
68    }
69  
70    public void updateGet(long t){
71      if (t > 1000) {
72        serverSource.incrSlowGet();
73      }
74      serverSource.updateGet(t);
75    }
76  
77    public void updateIncrement(long t){
78      if (t > 1000) {
79        serverSource.incrSlowIncrement();
80      }
81      serverSource.updateIncrement(t);
82    }
83  
84    public void updateAppend(long t){
85      if (t > 1000) {
86        serverSource.incrSlowAppend();
87      }
88      serverSource.updateAppend(t);
89    }
90  }