001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.ipc;
019
020import org.apache.hadoop.hbase.util.DirectMemoryUtils;
021import org.apache.hadoop.hbase.util.Pair;
022import org.apache.yetus.audience.InterfaceAudience;
023
024@InterfaceAudience.Private
025public class MetricsHBaseServerWrapperImpl implements MetricsHBaseServerWrapper {
026
027  private RpcServer server;
028
029  MetricsHBaseServerWrapperImpl(RpcServer server) {
030    this.server = server;
031  }
032
033  private boolean isServerStarted() {
034    return this.server != null && this.server.isStarted();
035  }
036
037  @Override
038  public long getTotalQueueSize() {
039    if (!isServerStarted()) {
040      return 0;
041    }
042    return server.callQueueSizeInBytes.sum();
043  }
044
045  @Override
046  public int getGeneralQueueLength() {
047    if (!isServerStarted() || this.server.getScheduler() == null) {
048      return 0;
049    }
050    return server.getScheduler().getGeneralQueueLength();
051  }
052
053  @Override
054  public int getReplicationQueueLength() {
055    if (!isServerStarted() || this.server.getScheduler() == null) {
056      return 0;
057    }
058    return server.getScheduler().getReplicationQueueLength();
059  }
060
061  @Override
062  public int getBulkLoadQueueLength() {
063    if (!isServerStarted() || this.server.getScheduler() == null) {
064      return 0;
065    }
066    return server.getScheduler().getBulkLoadQueueLength();
067  }
068
069  @Override
070  public int getPriorityQueueLength() {
071    if (!isServerStarted() || this.server.getScheduler() == null) {
072      return 0;
073    }
074    return server.getScheduler().getPriorityQueueLength();
075  }
076
077  @Override
078  public int getMetaPriorityQueueLength() {
079    if (!isServerStarted() || this.server.getScheduler() == null) {
080      return 0;
081    }
082    return server.getScheduler().getMetaPriorityQueueLength();
083  }
084
085  @Override
086  public int getNumOpenConnections() {
087    if (!isServerStarted()) {
088      return 0;
089    }
090    return server.getNumOpenConnections();
091  }
092
093  @Override
094  public int getActiveRpcHandlerCount() {
095    if (!isServerStarted() || this.server.getScheduler() == null) {
096      return 0;
097    }
098    return server.getScheduler().getActiveRpcHandlerCount();
099  }
100
101  @Override
102  public int getActiveGeneralRpcHandlerCount() {
103    if (!isServerStarted() || this.server.getScheduler() == null) {
104      return 0;
105    }
106    return server.getScheduler().getActiveGeneralRpcHandlerCount();
107  }
108
109  @Override
110  public int getActivePriorityRpcHandlerCount() {
111    if (!isServerStarted() || this.server.getScheduler() == null) {
112      return 0;
113    }
114    return server.getScheduler().getActivePriorityRpcHandlerCount();
115  }
116
117  @Override
118  public int getActiveMetaPriorityRpcHandlerCount() {
119    if (!isServerStarted() || this.server.getScheduler() == null) {
120      return 0;
121    }
122    return server.getScheduler().getActiveMetaPriorityRpcHandlerCount();
123  }
124
125  @Override
126  public int getActiveReplicationRpcHandlerCount() {
127    if (!isServerStarted() || this.server.getScheduler() == null) {
128      return 0;
129    }
130    return server.getScheduler().getActiveReplicationRpcHandlerCount();
131  }
132
133  @Override
134  public int getActiveBulkLoadRpcHandlerCount() {
135    if (!isServerStarted() || this.server.getScheduler() == null) {
136      return 0;
137    }
138    return server.getScheduler().getActiveBulkLoadRpcHandlerCount();
139  }
140
141  @Override
142  public long getNumGeneralCallsDropped() {
143    if (!isServerStarted() || this.server.getScheduler() == null) {
144      return 0;
145    }
146    return server.getScheduler().getNumGeneralCallsDropped();
147  }
148
149  @Override
150  public long getNumLifoModeSwitches() {
151    if (!isServerStarted() || this.server.getScheduler() == null) {
152      return 0;
153    }
154    return server.getScheduler().getNumLifoModeSwitches();
155  }
156
157  @Override
158  public int getWriteQueueLength() {
159    if (!isServerStarted() || this.server.getScheduler() == null) {
160      return 0;
161    }
162    return server.getScheduler().getWriteQueueLength();
163  }
164
165  @Override
166  public int getReadQueueLength() {
167    if (!isServerStarted() || this.server.getScheduler() == null) {
168      return 0;
169    }
170    return server.getScheduler().getReadQueueLength();
171  }
172
173  @Override
174  public int getScanQueueLength() {
175    if (!isServerStarted() || this.server.getScheduler() == null) {
176      return 0;
177    }
178    return server.getScheduler().getScanQueueLength();
179  }
180
181  @Override
182  public int getActiveWriteRpcHandlerCount() {
183    if (!isServerStarted() || this.server.getScheduler() == null) {
184      return 0;
185    }
186    return server.getScheduler().getActiveWriteRpcHandlerCount();
187  }
188
189  @Override
190  public int getActiveReadRpcHandlerCount() {
191    if (!isServerStarted() || this.server.getScheduler() == null) {
192      return 0;
193    }
194    return server.getScheduler().getActiveReadRpcHandlerCount();
195  }
196
197  @Override
198  public int getActiveScanRpcHandlerCount() {
199    if (!isServerStarted() || this.server.getScheduler() == null) {
200      return 0;
201    }
202    return server.getScheduler().getActiveScanRpcHandlerCount();
203  }
204
205  @Override
206  public long getNettyDmUsage() {
207    if (!isServerStarted() || this.server.getScheduler() == null) {
208      return 0L;
209    }
210
211    return DirectMemoryUtils.getNettyDirectMemoryUsage();
212  }
213
214  @Override
215  public Pair<Long, Long> getTotalAndMaxNettyOutboundBytes() {
216    if (
217      !isServerStarted() || this.server.getScheduler() == null
218        || !(this.server instanceof NettyRpcServer)
219    ) {
220      return Pair.newPair(0L, 0L);
221    }
222
223    return ((NettyRpcServer) server).getTotalAndMaxNettyOutboundBytes();
224  }
225}