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.metrics.BaseSourceImpl;
23  import org.apache.hadoop.metrics2.MetricsCollector;
24  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
25  import org.apache.hadoop.metrics2.lib.Interns;
26  import org.apache.hadoop.metrics2.lib.MutableCounterLong;
27  import org.apache.hadoop.metrics2.lib.MutableHistogram;
28  
29  public class MetricsHBaseServerSourceImpl extends BaseSourceImpl
30      implements MetricsHBaseServerSource {
31  
32    private final MetricsHBaseServerWrapper wrapper;
33    private final MutableCounterLong authorizationSuccesses;
34    private final MutableCounterLong authorizationFailures;
35    private final MutableCounterLong authenticationSuccesses;
36    private final MutableCounterLong authenticationFailures;
37    private final MutableCounterLong sentBytes;
38    private final MutableCounterLong receivedBytes;
39    private MutableHistogram queueCallTime;
40    private MutableHistogram processCallTime;
41  
42    public MetricsHBaseServerSourceImpl(String metricsName,
43                                        String metricsDescription,
44                                        String metricsContext,
45                                        String metricsJmxContext,
46                                        MetricsHBaseServerWrapper wrapper) {
47      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
48      this.wrapper = wrapper;
49  
50      this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
51          AUTHORIZATION_SUCCESSES_DESC, 0l);
52      this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
53          AUTHORIZATION_FAILURES_DESC, 0l);
54  
55      this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
56          AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0l);
57      this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
58          AUTHENTICATION_FAILURES_DESC, 0l);
59      this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
60          SENT_BYTES_DESC, 0l);
61      this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
62          RECEIVED_BYTES_DESC, 0l);
63      this.queueCallTime = this.getMetricsRegistry().newHistogram(QUEUE_CALL_TIME_NAME,
64          QUEUE_CALL_TIME_DESC);
65      this.processCallTime = this.getMetricsRegistry().newHistogram(PROCESS_CALL_TIME_NAME,
66          PROCESS_CALL_TIME_DESC);
67    }
68  
69    @Override
70    public void authorizationSuccess() {
71      authorizationSuccesses.incr();
72    }
73  
74    @Override
75    public void authorizationFailure() {
76      authorizationFailures.incr();
77    }
78  
79    @Override
80    public void authenticationFailure() {
81      authenticationFailures.incr();
82    }
83  
84    @Override
85    public void authenticationSuccess() {
86      authenticationSuccesses.incr();
87    }
88  
89    @Override
90    public void sentBytes(int count) {
91      this.sentBytes.incr(count);
92    }
93  
94    @Override
95    public void receivedBytes(int count) {
96      this.receivedBytes.incr(count);
97    }
98  
99    @Override
100   public void dequeuedCall(int qTime) {
101     queueCallTime.add(qTime);
102   }
103 
104   @Override
105   public void processedCall(int processingTime) {
106     processCallTime.add(processingTime);
107   }
108 
109   @Override
110   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
111     metricsRegistry.snapshot(metricsCollector.addRecord(metricsRegistry.info()), all);
112 
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     }
127 
128     metricsRegistry.snapshot(mrb, all);
129   }
130 }