ARTEMIS-2636: Introduce Disk Usage Metrics
ARTEMIS-2636: This commit introduces metrics to publish the amount of disk used currently
This commit is contained in:
parent
965982410e
commit
405eb969c1
|
@ -2284,4 +2284,20 @@ public interface AuditLogger extends BasicLogger {
|
|||
@LogMessage(level = Logger.Level.INFO)
|
||||
@Message(id = 601503, value = "User {0} is getting retroactiveResource property on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
|
||||
void isRetroactiveResource(String user, Object source, Object... args);
|
||||
|
||||
static void getDiskStoreUsage(Object source) {
|
||||
LOGGER.getDiskStoreUsage(getCaller(), source);
|
||||
}
|
||||
|
||||
@LogMessage(level = Logger.Level.INFO)
|
||||
@Message(id = 601504, value = "User {0} is getting disk store usage on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
|
||||
void getDiskStoreUsage(String user, Object source, Object... args);
|
||||
|
||||
static void getDiskStoreUsagePercentage(Object source) {
|
||||
LOGGER.getDiskStoreUsagePercentage(getCaller(), source);
|
||||
}
|
||||
|
||||
@LogMessage(level = Logger.Level.INFO)
|
||||
@Message(id = 601505, value = "User {0} is getting disk store usage percentage on target resource: {1} {2}", format = Message.Format.MESSAGE_FORMAT)
|
||||
void getDiskStoreUsagePercentage(String user, Object source, Object... args);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@ import org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException
|
|||
public interface ActiveMQServerControl {
|
||||
String CONNECTION_COUNT_DESCRIPTION = "Number of clients connected to this server";
|
||||
String TOTAL_CONNECTION_COUNT_DESCRIPTION = "Number of clients which have connected to this server since it was started";
|
||||
String ADDRESS_MEMORY_USAGE_DESCRIPTION = "Memory used by all the addresses on broker for in-memory messages";
|
||||
String ADDRESS_MEMORY_USAGE_DESCRIPTION = "Bytes used by all the addresses on broker for in-memory messages";
|
||||
String DISK_STORE_USAGE_DESCRIPTION = "Memory used by the disk store";
|
||||
|
||||
/**
|
||||
* Returns this server's version.
|
||||
|
@ -442,12 +443,24 @@ public interface ActiveMQServerControl {
|
|||
@Attribute(desc = ADDRESS_MEMORY_USAGE_DESCRIPTION)
|
||||
long getAddressMemoryUsage();
|
||||
|
||||
/**
|
||||
* Returns the bytes used by the disk store
|
||||
*/
|
||||
@Attribute(desc = DISK_STORE_USAGE_DESCRIPTION)
|
||||
long getDiskStoreUsage();
|
||||
|
||||
/**
|
||||
* Returns the memory used by all the addresses on broker as a percentage of global maximum limit
|
||||
*/
|
||||
@Attribute(desc = "Memory used by all the addresses on broker as a percentage of global maximum limit")
|
||||
int getAddressMemoryUsagePercentage();
|
||||
|
||||
/**
|
||||
* Returns the storage used by disk store
|
||||
*/
|
||||
@Attribute(desc = "Memory used by the disk store")
|
||||
int getDiskStoreUsagePercentage();
|
||||
|
||||
// Operations ----------------------------------------------------
|
||||
@Operation(desc = "Isolate the broker", impact = MBeanOperationInfo.ACTION)
|
||||
boolean freezeReplication();
|
||||
|
|
|
@ -107,6 +107,7 @@ import org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy;
|
|||
import org.apache.activemq.artemis.core.server.cluster.ha.LiveOnlyPolicy;
|
||||
import org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy;
|
||||
import org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy;
|
||||
import org.apache.activemq.artemis.core.server.files.FileStoreMonitor;
|
||||
import org.apache.activemq.artemis.core.server.group.GroupingHandler;
|
||||
import org.apache.activemq.artemis.core.server.impl.Activation;
|
||||
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
|
||||
|
@ -131,6 +132,8 @@ import org.apache.activemq.artemis.utils.SecurityFormatter;
|
|||
import org.apache.activemq.artemis.utils.collections.TypedProperties;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.apache.activemq.artemis.core.server.files.FileStoreMonitor.calculateUsage;
|
||||
|
||||
public class ActiveMQServerControlImpl extends AbstractControl implements ActiveMQServerControl, NotificationEmitter, org.apache.activemq.artemis.core.server.management.NotificationListener {
|
||||
// Constants -----------------------------------------------------
|
||||
private static final Logger logger = Logger.getLogger(ActiveMQServerControlImpl.class);
|
||||
|
@ -707,6 +710,28 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDiskStoreUsage() {
|
||||
if (AuditLogger.isEnabled()) {
|
||||
AuditLogger.getDiskStoreUsage(this.server);
|
||||
}
|
||||
checkStarted();
|
||||
clearIO();
|
||||
try {
|
||||
//this should not happen but if it does, return -1 to highlight it is not working
|
||||
if (server.getPagingManager() == null) {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
long usableSpace = server.getPagingManager().getDiskUsableSpace();
|
||||
long totalSpace = server.getPagingManager().getDiskTotalSpace();
|
||||
|
||||
return (long) FileStoreMonitor.calculateUsage(usableSpace, totalSpace);
|
||||
} finally {
|
||||
blockOnIO();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAddressMemoryUsagePercentage() {
|
||||
if (AuditLogger.isEnabled()) {
|
||||
|
@ -726,6 +751,26 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
|
|||
return (int) result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDiskStoreUsagePercentage() {
|
||||
if (AuditLogger.isEnabled()) {
|
||||
AuditLogger.getDiskStoreUsagePercentage(this.server);
|
||||
}
|
||||
long globalMaxSize = getGlobalMaxSize();
|
||||
// no max size set implies 0% used
|
||||
if (globalMaxSize <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long diskUsed = getDiskStoreUsage();
|
||||
if (diskUsed <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
double result = 100 * calculateUsage(diskUsed, globalMaxSize);
|
||||
return (int) result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean freezeReplication() {
|
||||
if (AuditLogger.isEnabled()) {
|
||||
|
|
|
@ -2996,6 +2996,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
builder.register(BrokerMetricNames.CONNECTION_COUNT, this, metrics -> Double.valueOf(getConnectionCount()), ActiveMQServerControl.CONNECTION_COUNT_DESCRIPTION);
|
||||
builder.register(BrokerMetricNames.TOTAL_CONNECTION_COUNT, this, metrics -> Double.valueOf(getTotalConnectionCount()), ActiveMQServerControl.TOTAL_CONNECTION_COUNT_DESCRIPTION);
|
||||
builder.register(BrokerMetricNames.ADDRESS_MEMORY_USAGE, this, metrics -> Double.valueOf(getPagingManager().getGlobalSize()), ActiveMQServerControl.ADDRESS_MEMORY_USAGE_DESCRIPTION);
|
||||
builder.register(BrokerMetricNames.DISK_STORE_USAGE, this, metrics -> Double.valueOf(getPagingManager().getDiskTotalSpace() - getPagingManager().getDiskUsableSpace()), ActiveMQServerControl.DISK_STORE_USAGE_DESCRIPTION);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,5 +22,5 @@ public class BrokerMetricNames {
|
|||
public static final String CONNECTION_COUNT = "connection.count";
|
||||
public static final String TOTAL_CONNECTION_COUNT = "total.connection.count";
|
||||
public static final String ADDRESS_MEMORY_USAGE = "address.memory.usage";
|
||||
|
||||
public static final String DISK_STORE_USAGE = "disk.store.usage";
|
||||
}
|
||||
|
|
|
@ -741,6 +741,26 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDiskStoreUsage() {
|
||||
try {
|
||||
return (Long) proxy.invokeOperation("getDiskStoreUsage");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDiskStoreUsagePercentage() {
|
||||
try {
|
||||
return (Integer) proxy.invokeOperation(Integer.TYPE, "getDiskUseStorePercentage");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean freezeReplication() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue