mirror of https://github.com/apache/activemq.git
Add some checks to prevent any chance of an ArithmaticException because of divide by zero.
This commit is contained in:
parent
53b12820c2
commit
541ed8cf0c
|
@ -27,6 +27,7 @@ import javax.management.openmbean.CompositeType;
|
|||
import javax.management.openmbean.TabularData;
|
||||
import javax.management.openmbean.TabularDataSupport;
|
||||
import javax.management.openmbean.TabularType;
|
||||
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.scheduler.JobSchedulerStore;
|
||||
import org.apache.activemq.store.PersistenceAdapter;
|
||||
|
@ -45,7 +46,7 @@ public class HealthView implements HealthViewMBean {
|
|||
public TabularData health() throws Exception {
|
||||
OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(HealthStatus.class);
|
||||
CompositeType ct = factory.getCompositeType();
|
||||
TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[]{"healthId", "level", "message", "resource"});
|
||||
TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[] { "healthId", "level", "message", "resource" });
|
||||
TabularDataSupport rc = new TabularDataSupport(tt);
|
||||
|
||||
List<HealthStatus> list = healthList();
|
||||
|
@ -70,7 +71,6 @@ public class HealthView implements HealthViewMBean {
|
|||
|
||||
/**
|
||||
* Check persistence store directory limits
|
||||
*
|
||||
*/
|
||||
BrokerService brokerService = broker.getBrokerService();
|
||||
if (brokerService != null && brokerService.getPersistenceAdapter() != null) {
|
||||
|
@ -84,7 +84,6 @@ public class HealthView implements HealthViewMBean {
|
|||
dir = new File(dirPath);
|
||||
}
|
||||
|
||||
|
||||
while (dir != null && !dir.isDirectory()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
|
@ -92,23 +91,21 @@ public class HealthView implements HealthViewMBean {
|
|||
long storeLimit = usage.getStoreUsage().getLimit();
|
||||
long dirFreeSpace = dir.getUsableSpace();
|
||||
|
||||
if (storeSize != 0) {
|
||||
if (storeSize != 0 && storeLimit != 0) {
|
||||
int val = (int) ((storeSize * 100) / storeLimit);
|
||||
if (val > 90) {
|
||||
answer.add(new HealthStatus("org.apache.activemq.StoreLimit", "WARNING", "Message Store size is within " + val + "% of its limit", adapter.toString()));
|
||||
answer.add(new HealthStatus("org.apache.activemq.StoreLimit", "WARNING", "Message Store size is within " + val + "% of its limit",
|
||||
adapter.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((storeLimit - storeSize) > dirFreeSpace) {
|
||||
String message = "Store limit is " + storeLimit / (1024 * 1024) +
|
||||
" mb, whilst the data directory: " + dir.getAbsolutePath() +
|
||||
" only has " + dirFreeSpace / (1024 * 1024) + " mb of usable space";
|
||||
String message = "Store limit is " + storeLimit / (1024 * 1024) + " mb, whilst the data directory: " + dir.getAbsolutePath()
|
||||
+ " only has " + dirFreeSpace / (1024 * 1024) + " mb of usable space";
|
||||
answer.add(new HealthStatus("org.apache.activemq.FreeDiskSpaceLeft", "WARNING", message, adapter.toString()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
File tmpDir = brokerService.getTmpDataDirectory();
|
||||
if (tmpDir != null) {
|
||||
|
||||
|
@ -123,15 +120,14 @@ public class HealthView implements HealthViewMBean {
|
|||
tmpDir = tmpDir.getParentFile();
|
||||
}
|
||||
|
||||
if (storeLimit != 0) {
|
||||
int val = (int) ((storeSize * 100) / storeLimit);
|
||||
if (val > 90) {
|
||||
answer.add(new HealthStatus("org.apache.activemq.TempStoreLimit", "WARNING", "TempMessage Store size is within " + val + "% of its limit", adapter.toString()));
|
||||
answer.add(new HealthStatus("org.apache.activemq.TempStoreLimit", "WARNING", "TempMessage Store size is within " + val
|
||||
+ "% of its limit", adapter.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,7 +142,6 @@ public class HealthView implements HealthViewMBean {
|
|||
dir = new File(dirPath);
|
||||
}
|
||||
|
||||
|
||||
while (dir != null && !dir.isDirectory()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
|
@ -154,33 +149,31 @@ public class HealthView implements HealthViewMBean {
|
|||
long storeLimit = usage.getJobSchedulerUsage().getLimit();
|
||||
long dirFreeSpace = dir.getUsableSpace();
|
||||
|
||||
if (storeSize != 0) {
|
||||
if (storeSize != 0 && storeLimit != 0) {
|
||||
int val = (int) ((storeSize * 100) / storeLimit);
|
||||
if (val > 90) {
|
||||
answer.add(new HealthStatus("org.apache.activemq.JobSchedulerLimit", "WARNING", "JobSchedulerMessage Store size is within " + val + "% of its limit", scheduler.toString()));
|
||||
answer.add(new HealthStatus("org.apache.activemq.JobSchedulerLimit", "WARNING", "JobSchedulerMessage Store size is within " + val
|
||||
+ "% of its limit", scheduler.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((storeLimit - storeSize) > dirFreeSpace) {
|
||||
String message = "JobSchedulerStore limit is " + storeLimit / (1024 * 1024) +
|
||||
" mb, whilst the data directory: " + dir.getAbsolutePath() +
|
||||
" only has " + dirFreeSpace / (1024 * 1024) + " mb of usable space";
|
||||
String message = "JobSchedulerStore limit is " + storeLimit / (1024 * 1024) + " mb, whilst the data directory: "
|
||||
+ dir.getAbsolutePath() + " only has " + dirFreeSpace / (1024 * 1024) + " mb of usable space";
|
||||
answer.add(new HealthStatus("org.apache.activemq.FreeDiskSpaceLeft", "WARNING", message, scheduler.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (answer != null && !answer.isEmpty()){
|
||||
if (answer != null && !answer.isEmpty()) {
|
||||
this.currentState = "Getting Worried {";
|
||||
for (HealthStatus hs: answer){
|
||||
for (HealthStatus hs : answer) {
|
||||
currentState += hs + " , ";
|
||||
}
|
||||
currentState += " }";
|
||||
} else{
|
||||
this.currentState="Good";
|
||||
} else {
|
||||
this.currentState = "Good";
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
@ -192,5 +185,4 @@ public class HealthView implements HealthViewMBean {
|
|||
public String getCurrentStatus() {
|
||||
return this.currentState;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.management.MBeanServer;
|
|||
import javax.management.MBeanServerInvocationHandler;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.EmbeddedBrokerTestSupport;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
|
@ -39,6 +40,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
|||
protected MBeanServer mbeanServer;
|
||||
protected String domain = "org.apache.activemq";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
bindAddress = "tcp://localhost:0";
|
||||
useTopic = false;
|
||||
|
@ -46,6 +48,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
|||
mbeanServer = broker.getManagementContext().getMBeanServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
@ -55,6 +58,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
|||
return new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getPublishableConnectString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BrokerService createBroker() throws Exception {
|
||||
BrokerService answer = new BrokerService();
|
||||
answer.setPersistent(true);
|
||||
|
@ -63,6 +67,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
|||
answer.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 64);
|
||||
answer.getSystemUsage().getStoreUsage().setLimit(1024 * 1024 * 64);
|
||||
answer.setUseJmx(true);
|
||||
answer.setSchedulerSupport(true);
|
||||
|
||||
// allow options to be visible via jmx
|
||||
|
||||
|
@ -84,6 +89,7 @@ public class HealthViewMBeanTest extends EmbeddedBrokerTestSupport {
|
|||
message.writeBytes(new byte[1024 *1024]);
|
||||
producer.send(message);
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
String objectNameStr = broker.getBrokerObjectName().toString();
|
||||
|
|
Loading…
Reference in New Issue