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.yetus.audience.InterfaceAudience;
022
023@InterfaceAudience.Private
024public class MetricsHBaseServerWrapperImpl implements MetricsHBaseServerWrapper {
025
026  private RpcServer server;
027
028  MetricsHBaseServerWrapperImpl(RpcServer server) {
029    this.server = server;
030  }
031
032  private boolean isServerStarted() {
033    return this.server != null && this.server.isStarted();
034  }
035
036  @Override
037  public long getTotalQueueSize() {
038    if (!isServerStarted()) {
039      return 0;
040    }
041    return server.callQueueSizeInBytes.sum();
042  }
043
044  @Override
045  public int getGeneralQueueLength() {
046    if (!isServerStarted() || this.server.getScheduler() == null) {
047      return 0;
048    }
049    return server.getScheduler().getGeneralQueueLength();
050  }
051
052  @Override
053  public int getReplicationQueueLength() {
054    if (!isServerStarted() || this.server.getScheduler() == null) {
055      return 0;
056    }
057    return server.getScheduler().getReplicationQueueLength();
058  }
059
060  @Override
061  public int getPriorityQueueLength() {
062    if (!isServerStarted() || this.server.getScheduler() == null) {
063      return 0;
064    }
065    return server.getScheduler().getPriorityQueueLength();
066  }
067
068  @Override
069  public int getMetaPriorityQueueLength() {
070    if (!isServerStarted() || this.server.getScheduler() == null) {
071      return 0;
072    }
073    return server.getScheduler().getMetaPriorityQueueLength();
074  }
075
076  @Override
077  public int getNumOpenConnections() {
078    if (!isServerStarted()) {
079      return 0;
080    }
081    return server.getNumOpenConnections();
082  }
083
084  @Override
085  public int getActiveRpcHandlerCount() {
086    if (!isServerStarted() || this.server.getScheduler() == null) {
087      return 0;
088    }
089    return server.getScheduler().getActiveRpcHandlerCount();
090  }
091
092  @Override
093  public int getActiveGeneralRpcHandlerCount() {
094    if (!isServerStarted() || this.server.getScheduler() == null) {
095      return 0;
096    }
097    return server.getScheduler().getActiveGeneralRpcHandlerCount();
098  }
099
100  @Override
101  public int getActivePriorityRpcHandlerCount() {
102    if (!isServerStarted() || this.server.getScheduler() == null) {
103      return 0;
104    }
105    return server.getScheduler().getActivePriorityRpcHandlerCount();
106  }
107
108  @Override
109  public int getActiveMetaPriorityRpcHandlerCount() {
110    if (!isServerStarted() || this.server.getScheduler() == null) {
111      return 0;
112    }
113    return server.getScheduler().getActiveMetaPriorityRpcHandlerCount();
114  }
115
116  @Override
117  public int getActiveReplicationRpcHandlerCount() {
118    if (!isServerStarted() || this.server.getScheduler() == null) {
119      return 0;
120    }
121    return server.getScheduler().getActiveReplicationRpcHandlerCount();
122  }
123
124  @Override
125  public long getNumGeneralCallsDropped() {
126    if (!isServerStarted() || this.server.getScheduler() == null) {
127      return 0;
128    }
129    return server.getScheduler().getNumGeneralCallsDropped();
130  }
131
132  @Override
133  public long getNumLifoModeSwitches() {
134    if (!isServerStarted() || this.server.getScheduler() == null) {
135      return 0;
136    }
137    return server.getScheduler().getNumLifoModeSwitches();
138  }
139
140  @Override
141  public int getWriteQueueLength() {
142    if (!isServerStarted() || this.server.getScheduler() == null) {
143      return 0;
144    }
145    return server.getScheduler().getWriteQueueLength();
146  }
147
148  @Override
149  public int getReadQueueLength() {
150    if (!isServerStarted() || this.server.getScheduler() == null) {
151      return 0;
152    }
153    return server.getScheduler().getReadQueueLength();
154  }
155
156  @Override
157  public int getScanQueueLength() {
158    if (!isServerStarted() || this.server.getScheduler() == null) {
159      return 0;
160    }
161    return server.getScheduler().getScanQueueLength();
162  }
163
164  @Override
165  public int getActiveWriteRpcHandlerCount() {
166    if (!isServerStarted() || this.server.getScheduler() == null) {
167      return 0;
168    }
169    return server.getScheduler().getActiveWriteRpcHandlerCount();
170  }
171
172  @Override
173  public int getActiveReadRpcHandlerCount() {
174    if (!isServerStarted() || this.server.getScheduler() == null) {
175      return 0;
176    }
177    return server.getScheduler().getActiveReadRpcHandlerCount();
178  }
179
180  @Override
181  public int getActiveScanRpcHandlerCount() {
182    if (!isServerStarted() || this.server.getScheduler() == null) {
183      return 0;
184    }
185    return server.getScheduler().getActiveScanRpcHandlerCount();
186  }
187
188  @Override
189  public long getNettyDmUsage() {
190    if (!isServerStarted() || this.server.getScheduler() == null) {
191      return 0L;
192    }
193
194    return DirectMemoryUtils.getNettyDirectMemoryUsage();
195  }
196}