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