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.hbase.metrics.ExceptionTrackingSourceImpl;
25  import org.apache.hadoop.hbase.metrics.Interns;
26  import org.apache.hadoop.metrics2.MetricHistogram;
27  import org.apache.hadoop.metrics2.MetricsCollector;
28  import org.apache.hadoop.metrics2.MetricsRecordBuilder;
29  import org.apache.hadoop.metrics2.lib.MutableFastCounter;
30  
31  @InterfaceAudience.Private
32  public class MetricsHBaseServerSourceImpl extends ExceptionTrackingSourceImpl
33      implements MetricsHBaseServerSource {
34  
35  
36    private final MetricsHBaseServerWrapper wrapper;
37    private final MutableFastCounter authorizationSuccesses;
38    private final MutableFastCounter authorizationFailures;
39    private final MutableFastCounter authenticationSuccesses;
40    private final MutableFastCounter authenticationFailures;
41    private final MutableFastCounter authenticationFallbacks;
42    private final MutableFastCounter sentBytes;
43    private final MutableFastCounter receivedBytes;
44  
45  
46    private MetricHistogram queueCallTime;
47    private MetricHistogram processCallTime;
48    private MetricHistogram totalCallTime;
49    private MetricHistogram requestSize;
50    private MetricHistogram responseSize;
51  
52    public MetricsHBaseServerSourceImpl(String metricsName,
53                                        String metricsDescription,
54                                        String metricsContext,
55                                        String metricsJmxContext,
56                                        MetricsHBaseServerWrapper wrapper) {
57      super(metricsName, metricsDescription, metricsContext, metricsJmxContext);
58      this.wrapper = wrapper;
59  
60      this.authorizationSuccesses = this.getMetricsRegistry().newCounter(AUTHORIZATION_SUCCESSES_NAME,
61          AUTHORIZATION_SUCCESSES_DESC, 0L);
62      this.authorizationFailures = this.getMetricsRegistry().newCounter(AUTHORIZATION_FAILURES_NAME,
63          AUTHORIZATION_FAILURES_DESC, 0L);
64      this.authenticationSuccesses = this.getMetricsRegistry().newCounter(
65          AUTHENTICATION_SUCCESSES_NAME, AUTHENTICATION_SUCCESSES_DESC, 0L);
66      this.authenticationFailures = this.getMetricsRegistry().newCounter(AUTHENTICATION_FAILURES_NAME,
67          AUTHENTICATION_FAILURES_DESC, 0L);
68      this.authenticationFallbacks = this.getMetricsRegistry().newCounter(
69          AUTHENTICATION_FALLBACKS_NAME, AUTHENTICATION_FALLBACKS_DESC, 0L);
70      this.sentBytes = this.getMetricsRegistry().newCounter(SENT_BYTES_NAME,
71          SENT_BYTES_DESC, 0L);
72      this.receivedBytes = this.getMetricsRegistry().newCounter(RECEIVED_BYTES_NAME,
73          RECEIVED_BYTES_DESC, 0L);
74      this.queueCallTime = this.getMetricsRegistry().newTimeHistogram(QUEUE_CALL_TIME_NAME,
75          QUEUE_CALL_TIME_DESC);
76      this.processCallTime = this.getMetricsRegistry().newTimeHistogram(PROCESS_CALL_TIME_NAME,
77          PROCESS_CALL_TIME_DESC);
78      this.totalCallTime = this.getMetricsRegistry().newTimeHistogram(TOTAL_CALL_TIME_NAME,
79          TOTAL_CALL_TIME_DESC);
80      this.requestSize = this.getMetricsRegistry().newSizeHistogram(REQUEST_SIZE_NAME,
81          REQUEST_SIZE_DESC);
82      this.responseSize = this.getMetricsRegistry().newSizeHistogram(RESPONSE_SIZE_NAME,
83                RESPONSE_SIZE_DESC);
84    }
85  
86    @Override
87    public void authorizationSuccess() {
88      authorizationSuccesses.incr();
89    }
90  
91    @Override
92    public void authorizationFailure() {
93      authorizationFailures.incr();
94    }
95  
96    @Override
97    public void authenticationFailure() {
98      authenticationFailures.incr();
99    }
100 
101   @Override
102   public void authenticationFallback() {
103     authenticationFallbacks.incr();
104   }
105 
106   @Override
107   public void authenticationSuccess() {
108     authenticationSuccesses.incr();
109   }
110 
111   @Override
112   public void sentBytes(long count) {
113     this.sentBytes.incr(count);
114   }
115 
116   @Override
117   public void receivedBytes(int count) {
118     this.receivedBytes.incr(count);
119   }
120 
121   @Override
122   public void sentResponse(long count) { this.responseSize.add(count); }
123 
124   @Override
125   public void receivedRequest(long count) { this.requestSize.add(count); }
126 
127   @Override
128   public void dequeuedCall(int qTime) {
129     queueCallTime.add(qTime);
130   }
131 
132   @Override
133   public void processedCall(int processingTime) {
134     processCallTime.add(processingTime);
135   }
136 
137   @Override
138   public void queuedAndProcessedCall(int totalTime) {
139     totalCallTime.add(totalTime);
140   }
141 
142   @Override
143   public void getMetrics(MetricsCollector metricsCollector, boolean all) {
144     MetricsRecordBuilder mrb = metricsCollector.addRecord(metricsName);
145 
146     if (wrapper != null) {
147       mrb.addGauge(Interns.info(QUEUE_SIZE_NAME, QUEUE_SIZE_DESC), wrapper.getTotalQueueSize())
148           .addGauge(Interns.info(GENERAL_QUEUE_NAME, GENERAL_QUEUE_DESC),
149               wrapper.getGeneralQueueLength())
150           .addGauge(Interns.info(REPLICATION_QUEUE_NAME,
151               REPLICATION_QUEUE_DESC), wrapper.getReplicationQueueLength())
152           .addGauge(Interns.info(PRIORITY_QUEUE_NAME, PRIORITY_QUEUE_DESC),
153               wrapper.getPriorityQueueLength())
154           .addGauge(Interns.info(NUM_OPEN_CONNECTIONS_NAME,
155               NUM_OPEN_CONNECTIONS_DESC), wrapper.getNumOpenConnections())
156           .addGauge(Interns.info(NUM_ACTIVE_HANDLER_NAME,
157               NUM_ACTIVE_HANDLER_DESC), wrapper.getActiveRpcHandlerCount())
158           .addGauge(Interns.info(NUM_ACTIVE_GENERAL_HANDLER_NAME, NUM_ACTIVE_GENERAL_HANDLER_DESC),
159             wrapper.getActiveGeneralRpcHandlerCount())
160           .addGauge(
161             Interns.info(NUM_ACTIVE_PRIORITY_HANDLER_NAME, NUM_ACTIVE_PRIORITY_HANDLER_DESC),
162             wrapper.getActivePriorityRpcHandlerCount())
163           .addGauge(
164             Interns.info(NUM_ACTIVE_REPLICATION_HANDLER_NAME, NUM_ACTIVE_REPLICATION_HANDLER_DESC),
165             wrapper.getActiveReplicationRpcHandlerCount())
166           .addCounter(Interns.info(NUM_GENERAL_CALLS_DROPPED_NAME,
167               NUM_GENERAL_CALLS_DROPPED_DESC), wrapper.getNumGeneralCallsDropped())
168           .addCounter(Interns.info(NUM_LIFO_MODE_SWITCHES_NAME,
169               NUM_LIFO_MODE_SWITCHES_DESC), wrapper.getNumLifoModeSwitches())
170           .addGauge(Interns.info(WRITE_QUEUE_NAME, WRITE_QUEUE_DESC),
171               wrapper.getWriteQueueLength())
172           .addGauge(Interns.info(READ_QUEUE_NAME, READ_QUEUE_DESC),
173               wrapper.getReadQueueLength())
174           .addGauge(Interns.info(SCAN_QUEUE_NAME, SCAN_QUEUE_DESC),
175               wrapper.getScanQueueLength())
176           .addGauge(Interns.info(NUM_ACTIVE_WRITE_HANDLER_NAME, NUM_ACTIVE_WRITE_HANDLER_DESC),
177             wrapper.getActiveWriteRpcHandlerCount())
178           .addGauge(Interns.info(NUM_ACTIVE_READ_HANDLER_NAME, NUM_ACTIVE_READ_HANDLER_DESC),
179             wrapper.getActiveReadRpcHandlerCount())
180           .addGauge(Interns.info(NUM_ACTIVE_SCAN_HANDLER_NAME, NUM_ACTIVE_SCAN_HANDLER_DESC),
181             wrapper.getActiveScanRpcHandlerCount());
182     }
183 
184     metricsRegistry.snapshot(mrb, all);
185   }
186 }