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.MetricsBuilder;
24  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
25  import org.apache.hadoop.metrics2.lib.MetricMutableCounterLong;
26  import org.apache.hadoop.metrics2.lib.MetricMutableHistogram;
27  
28  public class MetricsHBaseServerSourceImpl extends BaseSourceImpl
29      implements MetricsHBaseServerSource {
30  
31    private final MetricsHBaseServerWrapper wrapper;
32    private final MetricMutableCounterLong authorizationSuccesses;
33    private final MetricMutableCounterLong authorizationFailures;
34    private final MetricMutableCounterLong authenticationSuccesses;
35    private final MetricMutableCounterLong authenticationFailures;
36    private final MetricMutableCounterLong sentBytes;
37    private final MetricMutableCounterLong receivedBytes;
38    private MetricMutableHistogram queueCallTime;
39    private MetricMutableHistogram processCallTime;
40  
41    public MetricsHBaseServerSourceImpl(String metricsName,
42                                        String metricsDescription,
43                                        String metricsContext,
44                                        String metricsJmxContext,
45                                        MetricsHBaseServerWrapper wrapper) {
46      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
47      this.wrapper = wrapper;
48  
49      this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
50          AUTHORIZATION_SUCCESSES_DESC, 0l);
51      this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
52          AUTHORIZATION_FAILURES_DESC, 0l);
53  
54      this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
55          AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0l);
56      this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
57          AUTHENTICATION_FAILURES_DESC, 0l);
58      this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
59          SENT_BYTES_DESC, 0l);
60      this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
61          RECEIVED_BYTES_DESC, 0l);
62      this.queueCallTime = this.getMetricsRegistry().newHistogram(QUEUE_CALL_TIME_NAME,
63          QUEUE_CALL_TIME_DESC);
64      this.processCallTime = this.getMetricsRegistry().newHistogram(PROCESS_CALL_TIME_NAME,
65          PROCESS_CALL_TIME_DESC);
66    }
67  
68    @Override
69    public void authorizationSuccess() {
70      authorizationSuccesses.incr();
71    }
72  
73    @Override
74    public void authorizationFailure() {
75      authorizationFailures.incr();
76    }
77  
78    @Override
79    public void authenticationFailure() {
80      authenticationFailures.incr();
81    }
82  
83    @Override
84    public void authenticationSuccess() {
85      authenticationSuccesses.incr();
86    }
87  
88    @Override
89    public void sentBytes(long count) {
90      this.sentBytes.incr(count);
91    }
92  
93    @Override
94    public void receivedBytes(int count) {
95      this.receivedBytes.incr(count);
96    }
97  
98    @Override
99    public void dequeuedCall(int qTime) {
100     queueCallTime.add(qTime);
101   }
102 
103   @Override
104   public void processedCall(int processingTime) {
105     processCallTime.add(processingTime);
106   }
107 
108   @Override
109   public void getMetrics(MetricsBuilder metricsBuilder, boolean all) {
110     MetricsRecordBuilder mrb = metricsBuilder.addRecord(metricsName)
111         .setContext(metricsContext);
112     if (wrapper != null) {
113       mrb.addGauge(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC, wrapper.getTotalQueueSize())
114           .addGauge(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC, wrapper.getGeneralQueueLength())
115           .addGauge(REPLICATION_QUEUE_NAME,
116               REPLICATION_QUEUE_DESC, wrapper.getReplicationQueueLength())
117           .addGauge(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC, wrapper.getPriorityQueueLength())
118           .addGauge(NUM_OPEN_CONNECTIONS_NAME,
119               NUM_OPEN_CONNECTIONS_DESC, wrapper.getNumOpenConnections())
120           .addGauge(NUM_ACTIVE_HANDLER_NAME,
121               NUM_ACTIVE_HANDLER_DESC, wrapper.getActiveRpcHandlerCount());
122     }
123 
124     metricsRegistry.snapshot(mrb, all);
125   }
126 }