ARTEMIS-2828 add addressSize metric
Adding this metric required moving the meter registration code from the AddressInfo class to the ManagementService in order to get clean access to both the AddressInfo and AddressControl classes.
This commit is contained in:
parent
73c4e399d9
commit
cb7cd729d7
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||
public interface AddressControl {
|
||||
String ROUTED_MESSAGE_COUNT_DESCRIPTION = "number of messages routed to one or more bindings";
|
||||
String UNROUTED_MESSAGE_COUNT_DESCRIPTION = "number of messages not routed to any bindings";
|
||||
String ADDRESS_SIZE_DESCRIPTION = "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking";
|
||||
|
||||
/**
|
||||
* Returns the managed address.
|
||||
|
@ -60,10 +61,10 @@ public interface AddressControl {
|
|||
String getRolesAsJSON() throws Exception;
|
||||
|
||||
/**
|
||||
* Returns the number of estimated bytes being used by the queue(s), used to control paging and blocking.
|
||||
* Returns the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking.
|
||||
*/
|
||||
@Attribute(desc = "the number of estimated bytes being used by the queue(s), used to control paging and blocking")
|
||||
long getAddressSize() throws Exception;
|
||||
@Attribute(desc = ADDRESS_SIZE_DESCRIPTION)
|
||||
long getAddressSize();
|
||||
|
||||
/**
|
||||
* Returns the sum of messages on queue(s), including messages in delivery.
|
||||
|
|
|
@ -263,7 +263,7 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getAddressSize() throws Exception {
|
||||
public long getAddressSize() {
|
||||
if (AuditLogger.isEnabled()) {
|
||||
AuditLogger.getAddressSize(this.addressInfo);
|
||||
}
|
||||
|
@ -274,6 +274,9 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
|
|||
return 0;
|
||||
}
|
||||
return pagingStore.getAddressSize();
|
||||
} catch (Exception e) {
|
||||
ActiveMQServerLogger.LOGGER.debug("Failed to get address size", e);
|
||||
return -1;
|
||||
} finally {
|
||||
blockOnIO();
|
||||
}
|
||||
|
|
|
@ -259,11 +259,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
|
||||
@Override
|
||||
public boolean reloadAddressInfo(AddressInfo addressInfo) {
|
||||
boolean added = addressInfoMap.putIfAbsent(addressInfo.getName(), addressInfo) == null;
|
||||
if (added) {
|
||||
addressInfo.registerMeters(metricsManager);
|
||||
}
|
||||
return added;
|
||||
return addressInfoMap.putIfAbsent(addressInfo.getName(), addressInfo) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -355,13 +351,7 @@ public class SimpleAddressManager implements AddressManager {
|
|||
|
||||
@Override
|
||||
public AddressInfo removeAddressInfo(SimpleString address) throws Exception {
|
||||
final AddressInfo removed = addressInfoMap.remove(CompositeAddress.extractAddressName(address));
|
||||
|
||||
if (removed != null) {
|
||||
removed.unregisterMeters(metricsManager);
|
||||
}
|
||||
|
||||
return removed;
|
||||
return addressInfoMap.remove(CompositeAddress.extractAddressName(address));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -160,7 +160,6 @@ public class WildcardAddressManager extends SimpleAddressManager {
|
|||
//Remove from mappings so removeAndUpdateAddressMap processes and cleanup
|
||||
mappings.remove(address);
|
||||
removeAndUpdateAddressMap(new AddressImpl(removed.getName(), wildcardConfiguration));
|
||||
removed.unregisterMeters(metricsManager);
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
|||
|
||||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||
import org.apache.activemq.artemis.api.core.management.ResourceNames;
|
||||
import org.apache.activemq.artemis.core.persistence.AddressQueueStatus;
|
||||
import org.apache.activemq.artemis.core.persistence.StorageManager;
|
||||
import org.apache.activemq.artemis.core.postoffice.Binding;
|
||||
|
@ -31,8 +29,6 @@ import org.apache.activemq.artemis.core.postoffice.Bindings;
|
|||
import org.apache.activemq.artemis.core.postoffice.PostOffice;
|
||||
import org.apache.activemq.artemis.core.postoffice.QueueBinding;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
|
||||
import org.apache.activemq.artemis.core.server.metrics.AddressMetricNames;
|
||||
import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
|
||||
import org.apache.activemq.artemis.core.settings.HierarchicalRepositoryChangeListener;
|
||||
import org.apache.activemq.artemis.utils.CompositeAddress;
|
||||
import org.apache.activemq.artemis.utils.PrefixUtil;
|
||||
|
@ -340,19 +336,4 @@ public class AddressInfo {
|
|||
this.repositoryChangeListener = repositoryChangeListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void registerMeters(MetricsManager metricsManager) {
|
||||
if (metricsManager != null) {
|
||||
metricsManager.registerAddressGauge(name.toString(), builder -> {
|
||||
builder.register(AddressMetricNames.ROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(getRoutedMessageCount()), AddressControl.ROUTED_MESSAGE_COUNT_DESCRIPTION);
|
||||
builder.register(AddressMetricNames.UNROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(getUnRoutedMessageCount()), AddressControl.UNROUTED_MESSAGE_COUNT_DESCRIPTION);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterMeters(MetricsManager metricsManager) {
|
||||
if (metricsManager != null) {
|
||||
metricsManager.remove(ResourceNames.ADDRESS + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.activemq.artemis.api.core.Message;
|
|||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.core.config.BridgeConfiguration;
|
||||
import org.apache.activemq.artemis.core.config.ClusterConnectionConfiguration;
|
||||
|
@ -93,6 +94,8 @@ public interface ManagementService extends NotificationService, ActiveMQComponen
|
|||
|
||||
void registerAddress(AddressInfo addressInfo) throws Exception;
|
||||
|
||||
void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) throws Exception;
|
||||
|
||||
void unregisterAddress(SimpleString address) throws Exception;
|
||||
|
||||
void registerQueue(Queue queue, SimpleString address, StorageManager storageManager) throws Exception;
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.activemq.artemis.api.core.SimpleString;
|
|||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
|
||||
import org.apache.activemq.artemis.api.core.management.AcceptorControl;
|
||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||
import org.apache.activemq.artemis.api.core.management.BaseBroadcastGroupControl;
|
||||
import org.apache.activemq.artemis.api.core.management.BridgeControl;
|
||||
import org.apache.activemq.artemis.api.core.management.ClusterConnectionControl;
|
||||
|
@ -93,6 +94,8 @@ import org.apache.activemq.artemis.core.server.impl.CleaningActivateCallback;
|
|||
import org.apache.activemq.artemis.core.server.management.ManagementService;
|
||||
import org.apache.activemq.artemis.core.server.management.Notification;
|
||||
import org.apache.activemq.artemis.core.server.management.NotificationListener;
|
||||
import org.apache.activemq.artemis.core.server.metrics.AddressMetricNames;
|
||||
import org.apache.activemq.artemis.core.server.metrics.MetricsManager;
|
||||
import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
|
||||
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
|
||||
import org.apache.activemq.artemis.core.transaction.ResourceManager;
|
||||
|
@ -232,17 +235,32 @@ public class ManagementServiceImpl implements ManagementService {
|
|||
|
||||
registerInRegistry(ResourceNames.ADDRESS + addressInfo.getName(), addressControl);
|
||||
|
||||
registerAddressMeters(addressInfo, addressControl);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("registered address " + objectName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) {
|
||||
MetricsManager metricsManager = messagingServer.getMetricsManager();
|
||||
if (metricsManager != null) {
|
||||
metricsManager.registerAddressGauge(addressInfo.getName().toString(), builder -> {
|
||||
builder.register(AddressMetricNames.ROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(addressInfo.getRoutedMessageCount()), AddressControl.ROUTED_MESSAGE_COUNT_DESCRIPTION);
|
||||
builder.register(AddressMetricNames.UNROUTED_MESSAGE_COUNT, this, metrics -> Double.valueOf(addressInfo.getUnRoutedMessageCount()), AddressControl.UNROUTED_MESSAGE_COUNT_DESCRIPTION);
|
||||
builder.register(AddressMetricNames.ADDRESS_SIZE, this, metrics -> Double.valueOf(addressControl.getAddressSize()), AddressControl.ADDRESS_SIZE_DESCRIPTION);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void unregisterAddress(final SimpleString address) throws Exception {
|
||||
ObjectName objectName = objectNameBuilder.getAddressObjectName(address);
|
||||
|
||||
unregisterFromJMX(objectName);
|
||||
unregisterFromRegistry(ResourceNames.ADDRESS + address);
|
||||
unregisterAddressMeters(address.toString());
|
||||
}
|
||||
|
||||
public synchronized void registerQueue(final Queue queue,
|
||||
|
@ -542,6 +560,13 @@ public class ManagementServiceImpl implements ManagementService {
|
|||
}
|
||||
}
|
||||
|
||||
public void unregisterAddressMeters(String address) {
|
||||
MetricsManager metricsManager = messagingServer.getMetricsManager();
|
||||
if (metricsManager != null) {
|
||||
metricsManager.remove(ResourceNames.ADDRESS + address);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNotificationListener(final NotificationListener listener) {
|
||||
listeners.add(listener);
|
||||
|
|
|
@ -21,5 +21,6 @@ public class AddressMetricNames {
|
|||
|
||||
public static final String ROUTED_MESSAGE_COUNT = "routed.message.count";
|
||||
public static final String UNROUTED_MESSAGE_COUNT = "unrouted.message.count";
|
||||
public static final String ADDRESS_SIZE = "address.size";
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.activemq.artemis.api.core.Message;
|
|||
import org.apache.activemq.artemis.api.core.RoutingType;
|
||||
import org.apache.activemq.artemis.api.core.SimpleString;
|
||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||
import org.apache.activemq.artemis.api.core.management.AddressControl;
|
||||
import org.apache.activemq.artemis.api.core.management.ManagementHelper;
|
||||
import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
|
||||
import org.apache.activemq.artemis.core.config.BridgeConfiguration;
|
||||
|
@ -251,6 +252,11 @@ public class ClusteredResetMockTest extends ActiveMQTestBase {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerAddressMeters(AddressInfo addressInfo, AddressControl addressControl) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterAddress(SimpleString address) throws Exception {
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class AddressControlUsingCoreTest extends AddressControlTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public long getAddressSize() throws Exception {
|
||||
public long getAddressSize() {
|
||||
return (long) proxy.retrieveAttributeValue("addressSize");
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,11 @@ import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
|
|||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
||||
import org.apache.activemq.artemis.core.config.MetricsConfiguration;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServer;
|
||||
import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
|
||||
import org.apache.activemq.artemis.core.server.Queue;
|
||||
import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
|
||||
import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
|
||||
import org.apache.activemq.artemis.tests.util.Wait;
|
||||
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
|
||||
import org.apache.activemq.artemis.tests.util.Wait;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -166,7 +165,9 @@ public class MetricsPluginTest extends ActiveMQTestBase {
|
|||
new Metric("artemis.scheduled.persistent.size", "persistent size of scheduled messages in this queue", 0.0),
|
||||
new Metric("artemis.total.connection.count", "Number of clients which have connected to this server since it was started", 1.0),
|
||||
new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 0.0),
|
||||
new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 2.0)
|
||||
new Metric("artemis.unrouted.message.count", "number of messages not routed to any bindings", 2.0),
|
||||
new Metric("artemis.address.size", "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking", 0.0),
|
||||
new Metric("artemis.address.size", "the number of estimated bytes being used by all the queue(s) bound to this address; used to control paging and blocking", 0.0)
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue