View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.ipc;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
24  import org.apache.hadoop.metrics2.MetricsCollector;
25  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
26  import org.apache.hadoop.metrics2.lib.Interns;
27  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
28  import org.apache.hadoop.metrics2.lib.MutableHistogram;
29  
30  @InterfaceAudience.Private
31  public class MetricsHBaseServerSourceImpl extends BaseSourceImpl
32      implements MetricsHBaseServerSource {
33  
34    private final MetricsHBaseServerWrapper wrapper;
35    private final MutableCounterLong authorizationSuccesses;
36    private final MutableCounterLong authorizationFailures;
37    private final MutableCounterLong authenticationSuccesses;
38    private final MutableCounterLong authenticationFailures;
39    private final MutableCounterLong sentBytes;
40    private final MutableCounterLong receivedBytes;
41    private MutableHistogram queueCallTime;
42    private MutableHistogram processCallTime;
43  
44    public MetricsHBaseServerSourceImpl(String metricsName,
45                                        String metricsDescription,
46                                        String metricsContext,
47                                        String metricsJmxContext,
48                                        MetricsHBaseServerWrapper wrapper) {
49      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
50      this.wrapper = wrapper;
51  
52      this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
53          AUTHORIZATION_SUCCESSES_DESC, 0l);
54      this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
55          AUTHORIZATION_FAILURES_DESC, 0l);
56  
57      this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
58          AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0l);
59      this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
60          AUTHENTICATION_FAILURES_DESC, 0l);
61      this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
62          SENT_BYTES_DESC, 0l);
63      this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
64          RECEIVED_BYTES_DESC, 0l);
65      this.queueCallTime = this.getMetricsRegistry().newHistogram(QUEUE_CALL_TIME_NAME,
66          QUEUE_CALL_TIME_DESC);
67      this.processCallTime = this.getMetricsRegistry().newHistogram(PROCESS_CALL_TIME_NAME,
68          PROCESS_CALL_TIME_DESC);
69    }
70  
71    @Override
72    public void authorizationSuccess() {
73      authorizationSuccesses.incr();
74    }
75  
76    @Override
77    public void authorizationFailure() {
78      authorizationFailures.incr();
79    }
80  
81    @Override
82    public void authenticationFailure() {
83      authenticationFailures.incr();
84    }
85  
86    @Override
87    public void authenticationSuccess() {
88      authenticationSuccesses.incr();
89    }
90  
91    @Override
92    public void sentBytes(long count) {
93      this.sentBytes.incr(count);
94    }
95  
96    @Override
97    public void receivedBytes(int count) {
98      this.receivedBytes.incr(count);
99    }
100 
101   @Override
102   public void dequeuedCall(int qTime) {
103     queueCallTime.add(qTime);
104   }
105 
106   @Override
107   public void processedCall(int processingTime) {
108     processCallTime.add(processingTime);
109   }
110 
111   @Override
112   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
113     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName)
114         .setContext(metricsContext);
115 
116     if (wrapper != null) {
117       mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
118           .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
119               wrapper.getGeneralQueueLength())
120           .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
121               REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
122           .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
123               wrapper.getPriorityQueueLength())
124           .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
125               NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
126           .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
127               NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount());
128     }
129 
130     metricsRegistry.snapshot(mrb, all);
131   }
132 }