refactored mbean name and properties to more comply with https://github.com/hawtio/hawtio/blob/master/doc/HealthMBeans.md#health-mbeans and make it a little more descriptive for users

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1422953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2012-12-17 14:42:44 +00:00
parent 757a2f1d32
commit 973909ab44
5 changed files with 46 additions and 37 deletions

View File

@ -58,6 +58,8 @@ import org.apache.activemq.broker.jmx.AnnotatedMBean;
import org.apache.activemq.broker.jmx.BrokerView; import org.apache.activemq.broker.jmx.BrokerView;
import org.apache.activemq.broker.jmx.ConnectorView; import org.apache.activemq.broker.jmx.ConnectorView;
import org.apache.activemq.broker.jmx.ConnectorViewMBean; import org.apache.activemq.broker.jmx.ConnectorViewMBean;
import org.apache.activemq.broker.jmx.HealthView;
import org.apache.activemq.broker.jmx.HealthViewMBean;
import org.apache.activemq.broker.jmx.JmsConnectorView; import org.apache.activemq.broker.jmx.JmsConnectorView;
import org.apache.activemq.broker.jmx.JobSchedulerView; import org.apache.activemq.broker.jmx.JobSchedulerView;
import org.apache.activemq.broker.jmx.JobSchedulerViewMBean; import org.apache.activemq.broker.jmx.JobSchedulerViewMBean;
@ -66,8 +68,6 @@ import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.broker.jmx.NetworkConnectorView; import org.apache.activemq.broker.jmx.NetworkConnectorView;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean; import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.apache.activemq.broker.jmx.ProxyConnectorView; import org.apache.activemq.broker.jmx.ProxyConnectorView;
import org.apache.activemq.broker.jmx.StatusView;
import org.apache.activemq.broker.jmx.StatusViewMBean;
import org.apache.activemq.broker.region.CompositeDestinationInterceptor; import org.apache.activemq.broker.region.CompositeDestinationInterceptor;
import org.apache.activemq.broker.region.Destination; import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.DestinationFactory; import org.apache.activemq.broker.region.DestinationFactory;
@ -2187,7 +2187,7 @@ public class BrokerService implements Service {
broker = sb; broker = sb;
} }
if (isUseJmx()) { if (isUseJmx()) {
StatusViewMBean statusView = new StatusView((ManagedRegionBroker)getRegionBroker()); HealthViewMBean statusView = new HealthView((ManagedRegionBroker)getRegionBroker());
try { try {
ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":" ObjectName objectName = new ObjectName(getManagementContext().getJmxDomainName() + ":"
+ "BrokerName=" + JMXSupport.encodeObjectNamePart(getBrokerName()) + "," + "BrokerName=" + JMXSupport.encodeObjectNamePart(getBrokerName()) + ","

View File

@ -18,29 +18,32 @@ package org.apache.activemq.broker.jmx;
import java.io.Serializable; import java.io.Serializable;
public class StatusEvent implements Serializable { public class HealthStatus implements Serializable {
private final String healthId;
private final String level;
private final String message;
private final String resource;
protected String id; public HealthStatus(String healthId, String level, String message, String resource) {
protected String resource; this.healthId = healthId;
this.level = level;
public StatusEvent(String id, String resource) { this.message = message;
this.id = id;
this.resource = resource; this.resource = resource;
} }
public String getId() { public String getHealthId() {
return id; return healthId;
} }
public void setId(String id) { public String getLevel() {
this.id = id; return level;
} }
public Object getResource() { public String getMessage() {
return message;
}
public String getResource() {
return resource; return resource;
} }
public void setResource(String resource) {
this.resource = resource;
}
} }

View File

@ -26,36 +26,38 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class StatusView implements StatusViewMBean { public class HealthView implements HealthViewMBean {
ManagedRegionBroker broker; ManagedRegionBroker broker;
public StatusView(ManagedRegionBroker broker) { public HealthView(ManagedRegionBroker broker) {
this.broker = broker; this.broker = broker;
} }
@Override @Override
public TabularData health() throws Exception { public TabularData health() throws Exception {
OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(StatusEvent.class); OpenTypeSupport.OpenTypeFactory factory = OpenTypeSupport.getFactory(HealthStatus.class);
CompositeType ct = factory.getCompositeType(); CompositeType ct = factory.getCompositeType();
TabularType tt = new TabularType("Status", "Status", ct, new String[]{"id", "resource"}); TabularType tt = new TabularType("HealthStatus", "HealthStatus", ct, new String[]{"healthId", "level", "message", "resource"});
TabularDataSupport rc = new TabularDataSupport(tt); TabularDataSupport rc = new TabularDataSupport(tt);
List<StatusEvent> list = healthList(); List<HealthStatus> list = healthList();
for (StatusEvent statusEvent : list) { for (HealthStatus healthStatus : list) {
rc.put(new CompositeDataSupport(ct, factory.getFields(statusEvent))); rc.put(new CompositeDataSupport(ct, factory.getFields(healthStatus)));
} }
return rc; return rc;
} }
@Override @Override
public List<StatusEvent> healthList() throws Exception { public List<HealthStatus> healthList() throws Exception {
List<StatusEvent> answer = new ArrayList<StatusEvent>(); List<HealthStatus> answer = new ArrayList<HealthStatus>();
Map<ObjectName, DestinationView> queueViews = broker.getQueueViews(); Map<ObjectName, DestinationView> queueViews = broker.getQueueViews();
for (Map.Entry<ObjectName, DestinationView> entry : queueViews.entrySet()) { for (Map.Entry<ObjectName, DestinationView> entry : queueViews.entrySet()) {
DestinationView queue = entry.getValue(); DestinationView queue = entry.getValue();
if (queue.getConsumerCount() == 0 && queue.getProducerCount() > 0) { if (queue.getConsumerCount() == 0 && queue.getProducerCount() > 0) {
answer.add(new StatusEvent("AMQ-NoConsumer", entry.getKey().toString())); ObjectName key = entry.getKey();
String message = "Queue " + queue.getName() + " has no consumers";
answer.add(new HealthStatus("org.apache.activemq.noConsumer", "WARNING", message, key.toString()));
} }
} }
return answer; return answer;

View File

@ -22,16 +22,16 @@ import java.util.List;
/** /**
* Returns the status events of the broker to indicate any warnings. * Returns the status events of the broker to indicate any warnings.
*/ */
public interface StatusViewMBean { public interface HealthViewMBean {
public TabularData health() throws Exception; public TabularData health() throws Exception;
/** /**
* Warning this method can only be invoked if you have the correct version * Warning this method can only be invoked if you have the correct version
* of {@link StatusEvent} on your classpath or you use something * of {@link HealthStatus} on your classpath or you use something
* like <a href="http://jolokia.org/">jolokia</a> to access JMX. * like <a href="http://jolokia.org/">jolokia</a> to access JMX.
* *
* If in doubt, please use the {@link #status()} method instead! * If in doubt, please use the {@link #status()} method instead!
*/ */
List<StatusEvent> healthList() throws Exception; List<HealthStatus> healthList() throws Exception;
} }

View File

@ -478,24 +478,28 @@ public final class OpenTypeSupport {
} }
} }
static class StatusEventOpenTypeFactory extends AbstractOpenTypeFactory { static class HealthStatusOpenTypeFactory extends AbstractOpenTypeFactory {
@Override @Override
protected String getTypeName() { protected String getTypeName() {
return StatusEvent.class.getName(); return HealthStatus.class.getName();
} }
@Override @Override
protected void init() throws OpenDataException { protected void init() throws OpenDataException {
super.init(); super.init();
addItem("id", "event id", SimpleType.STRING); addItem("healthId", "health check id", SimpleType.STRING);
addItem("level", "severity", SimpleType.STRING);
addItem("message", "severity", SimpleType.STRING);
addItem("resource", "event resource", SimpleType.STRING); addItem("resource", "event resource", SimpleType.STRING);
} }
@Override @Override
public Map<String, Object> getFields(Object o) throws OpenDataException { public Map<String, Object> getFields(Object o) throws OpenDataException {
StatusEvent event = (StatusEvent) o; HealthStatus event = (HealthStatus) o;
Map<String, Object> rc = super.getFields(o); Map<String, Object> rc = super.getFields(o);
rc.put("id", event.getId()); rc.put("healthId", event.getHealthId());
rc.put("level", event.getLevel());
rc.put("message", event.getMessage());
rc.put("resource", event.getResource()); rc.put("resource", event.getResource());
return rc; return rc;
} }
@ -511,7 +515,7 @@ public final class OpenTypeSupport {
OPEN_TYPE_FACTORIES.put(Job.class, new JobOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(Job.class, new JobOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(SlowConsumerEntry.class, new SlowConsumerEntryOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(SlowConsumerEntry.class, new SlowConsumerEntryOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(ActiveMQBlobMessage.class, new ActiveMQBlobMessageOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(ActiveMQBlobMessage.class, new ActiveMQBlobMessageOpenTypeFactory());
OPEN_TYPE_FACTORIES.put(StatusEvent.class, new StatusEventOpenTypeFactory()); OPEN_TYPE_FACTORIES.put(HealthStatus.class, new HealthStatusOpenTypeFactory());
} }
private OpenTypeSupport() { private OpenTypeSupport() {