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