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.hbase.CompatibilitySingletonFactory;
24  
25  /**
26   * <p>
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 MetricsRegionServerSource serverSource;
37    private MetricsRegionServerWrapper regionServerWrapper;
38  
39    public MetricsRegionServer(MetricsRegionServerWrapper regionServerWrapper) {
40      this(regionServerWrapper,
41          CompatibilitySingletonFactory.getInstance(MetricsRegionServerSourceFactory.class)
42              .createServer(regionServerWrapper));
43  
44    }
45  
46    MetricsRegionServer(MetricsRegionServerWrapper regionServerWrapper,
47                        MetricsRegionServerSource serverSource) {
48      this.regionServerWrapper = regionServerWrapper;
49      this.serverSource = serverSource;
50    }
51  
52    @VisibleForTesting
53    public MetricsRegionServerSource getMetricsSource() {
54      return serverSource;
55    }
56  
57    public MetricsRegionServerWrapper getRegionServerWrapper() {
58      return regionServerWrapper;
59    }
60  
61    public void updatePut(long t) {
62      if (t > 1000) {
63        serverSource.incrSlowPut();
64      }
65      serverSource.updatePut(t);
66    }
67  
68    public void updateDelete(long t) {
69      if (t > 1000) {
70        serverSource.incrSlowDelete();
71      }
72      serverSource.updateDelete(t);
73    }
74  
75    public void updateGet(long t) {
76      if (t > 1000) {
77        serverSource.incrSlowGet();
78      }
79      serverSource.updateGet(t);
80    }
81  
82    public void updateIncrement(long t) {
83      if (t > 1000) {
84        serverSource.incrSlowIncrement();
85      }
86      serverSource.updateIncrement(t);
87    }
88  
89    public void updateAppend(long t) {
90      if (t > 1000) {
91        serverSource.incrSlowAppend();
92      }
93      serverSource.updateAppend(t);
94    }
95  
96    public void updateReplay(long t){
97      serverSource.updateReplay(t);
98    }
99  
100   public void updateScanSize(long scanSize){
101     serverSource.updateScanSize(scanSize);
102   }
103 
104   public void updateScanTime(long t) {
105     serverSource.updateScanTime(t);
106   }
107 
108   public void updateSplitTime(long t) {
109     serverSource.updateSplitTime(t);
110   }
111 
112   public void incrSplitRequest() {
113     serverSource.incrSplitRequest();
114   }
115 
116   public void incrSplitSuccess() {
117     serverSource.incrSplitSuccess();
118   }
119 
120   public void updateFlush(long t, long memstoreSize, long fileSize) {
121     serverSource.updateFlushTime(t);
122     serverSource.updateFlushMemstoreSize(memstoreSize);
123     serverSource.updateFlushOutputSize(fileSize);
124   }
125 
126   public void updateCompaction(boolean isMajor, long t, int inputFileCount, int outputFileCount,
127       long inputBytes, long outputBytes) {
128     serverSource.updateCompactionTime(isMajor, t);
129     serverSource.updateCompactionInputFileCount(isMajor, inputFileCount);
130     serverSource.updateCompactionOutputFileCount(isMajor, outputFileCount);
131     serverSource.updateCompactionInputSize(isMajor, inputBytes);
132     serverSource.updateCompactionOutputSize(isMajor, outputBytes);
133   }
134 }