use of javax.management.MBeanInfo in project neo4j by neo4j.
the class JmxQueryProcedureTest method setup.
@Before
public void setup() throws Throwable {
jmxServer = mock(MBeanServer.class);
beanName = new ObjectName("org.neo4j:chevyMakesTheTruck=bobMcCoshMakesTheDifference");
attributeName = "name";
when(jmxServer.queryNames(new ObjectName("*:*"), null)).thenReturn(asSet(beanName));
when(jmxServer.getMBeanInfo(beanName)).thenReturn(new MBeanInfo("org.neo4j.SomeMBean", "This is a description", new MBeanAttributeInfo[] { new MBeanAttributeInfo(attributeName, "someType", "This is the attribute desc.", true, false, false) }, null, null, null));
}
use of javax.management.MBeanInfo in project jersey by jersey.
the class ExecutionStatisticsDynamicBean method initMBeanInfo.
private MBeanInfo initMBeanInfo(final ExecutionStatistics initialStatistics) {
final Map<Long, TimeWindowStatistics> statsMap = initialStatistics.getTimeWindowStatistics();
MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[statsMap.size() * 5];
int i = 0;
for (final TimeWindowStatistics stats : statsMap.values()) {
final long interval = stats.getTimeWindow();
final String postfix = convertIntervalToString((int) interval);
String name = "MinTime[ms]_" + postfix;
attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false);
attributeValues.put(name, new Value<Object>() {
@Override
public Object get() {
return executionStatistics.getTimeWindowStatistics().get(interval).getMinimumDuration();
}
});
name = "MaxTime[ms]_" + postfix;
attrs[i++] = new MBeanAttributeInfo(name, "long", "Minimum request processing time in milliseconds in last " + postfix + ".", true, false, false);
attributeValues.put(name, new Value<Object>() {
@Override
public Object get() {
return executionStatistics.getTimeWindowStatistics().get(interval).getMaximumDuration();
}
});
name = "AverageTime[ms]_" + postfix;
attrs[i++] = new MBeanAttributeInfo(name, "long", "Average request processing time in milliseconds in last " + postfix + ".", true, false, false);
attributeValues.put(name, new Value<Object>() {
@Override
public Object get() {
return executionStatistics.getTimeWindowStatistics().get(interval).getAverageDuration();
}
});
name = "RequestRate[requestsPerSeconds]_" + postfix;
attrs[i++] = new MBeanAttributeInfo(name, "double", "Average requests per second in last " + postfix + ".", true, false, false);
attributeValues.put(name, new Value<Object>() {
@Override
public Object get() {
return executionStatistics.getTimeWindowStatistics().get(interval).getRequestsPerSecond();
}
});
name = "RequestCount_" + postfix;
attrs[i++] = new MBeanAttributeInfo(name, "double", "Request count in last " + postfix + ".", true, false, false);
attributeValues.put(name, new Value<Object>() {
@Override
public Object get() {
return executionStatistics.getTimeWindowStatistics().get(interval).getRequestCount();
}
});
}
return new MBeanInfo(this.getClass().getName(), "Execution statistics", attrs, null, null, null);
}
use of javax.management.MBeanInfo in project twitter4j by yusuke.
the class MBeansTest method testAPIStatisticsOpenMBean.
/**
* Tests exposure of API statistics via a dynamic MBean
*/
public void testAPIStatisticsOpenMBean() throws Exception {
APIStatistics stats = new APIStatistics(5);
APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(stats);
// sanity check to ensure metadata accurately describes dynamic attributes
MBeanInfo info = openMBean.getMBeanInfo();
assertEquals(5, info.getAttributes().length);
assertEquals(1, info.getOperations().length);
List<String> attrNames = new ArrayList<String>();
for (MBeanAttributeInfo attr : info.getAttributes()) {
assertNotNull(openMBean.getAttribute(attr.getName()));
attrNames.add(attr.getName());
}
AttributeList attrList = openMBean.getAttributes(attrNames.toArray(new String[attrNames.size()]));
assertNotNull(attrList);
assertEquals(5, attrList.size());
// check stats (empty case)
Long callCount = (Long) openMBean.getAttribute("callCount");
assertEquals(0, callCount.longValue());
Long errorCount = (Long) openMBean.getAttribute("errorCount");
assertEquals(0, callCount.longValue());
Long totalTime = (Long) openMBean.getAttribute("totalTime");
assertEquals(0, totalTime.longValue());
Long averageTime = (Long) openMBean.getAttribute("averageTime");
assertEquals(0, averageTime.longValue());
// check table (empty case)
TabularData table = (TabularData) openMBean.getAttribute("statisticsTable");
assertTrue(table.isEmpty());
stats.methodCalled("foo", 100, true);
// check stats (populated case)
callCount = (Long) openMBean.getAttribute("callCount");
assertEquals(1, callCount.longValue());
errorCount = (Long) openMBean.getAttribute("errorCount");
assertEquals(0, errorCount.longValue());
totalTime = (Long) openMBean.getAttribute("totalTime");
assertEquals(100, totalTime.longValue());
averageTime = (Long) openMBean.getAttribute("averageTime");
assertEquals(100, averageTime.longValue());
// check table (populated case)
table = (TabularData) openMBean.getAttribute("statisticsTable");
assertFalse(table.isEmpty());
assertEquals(1, table.keySet().size());
CompositeData data = table.get(new Object[] { "foo" });
assertNotNull(data);
String[] columnNames = new String[] { "methodName", "callCount", "totalTime", "avgTime" };
Object[] columnValues = data.getAll(columnNames);
assertEquals(columnNames.length, columnValues.length);
assertEquals("foo", columnValues[0]);
assertEquals(1, ((Long) columnValues[1]).longValue());
assertEquals(100, ((Long) columnValues[2]).longValue());
assertEquals(100, ((Long) columnValues[3]).longValue());
// check reset
openMBean.invoke("reset", new Object[0], new String[0]);
checkCalculator(stats, 0, 0, 0, 0);
assertFalse(stats.getInvocationStatistics().iterator().hasNext());
}
use of javax.management.MBeanInfo in project pulsar by yahoo.
the class MBeanStatsGenerator method convert.
private Metrics convert(ObjectInstance instance) {
ObjectName objName = instance.getObjectName();
MBeanInfo info = null;
try {
info = mbs.getMBeanInfo(objName);
} catch (Exception e) {
// [Bug 6158364] skipping MBean if access failed
return null;
}
Metrics metrics = null;
// create a metrics instance by MBean dimension
metrics = createMetricsByDimension(objName);
// get each of attribute,value from the MBean
for (MBeanAttributeInfo attr : info.getAttributes()) {
Object value;
try {
value = mbs.getAttribute(instance.getObjectName(), attr.getName());
metrics.put(attr.getName(), value);
} catch (Exception e) {
// skip
}
}
return metrics;
}
use of javax.management.MBeanInfo in project tdi-studio-se by Talend.
the class AttributeContentProvider method refresh.
/**
* Refreshes the content provider.
*
* @param jvm The JVM
* @param objectName The object name
* @throws JvmCoreException
*/
protected void refresh(IActiveJvm jvm, ObjectName objectName) throws JvmCoreException {
MBeanInfo mBeanInfo = null;
List<AttributeNode> nodes = new ArrayList<AttributeNode>();
try {
mBeanInfo = jvm.getMBeanServer().getMBeanInfo(objectName);
} catch (JvmCoreException e) {
attributeRootNodes = nodes;
throw e;
}
if (mBeanInfo == null) {
attributeRootNodes = nodes;
return;
}
AttributeParser parser = new AttributeParser();
for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
String name = attributeInfo.getName();
Object value = getAttributeValue(jvm, objectName, name);
AttributeNode attributeNode = null;
for (AttributeNode node : attributeRootNodes) {
if (node.getName().equals(name)) {
attributeNode = node;
attributeNode.setValue(value);
break;
}
}
if (attributeNode == null) {
attributeNode = new AttributeNode(name, null, value);
}
parser.refreshAttribute(attributeNode);
attributeNode.setWritable(attributeInfo.isWritable());
nodes.add(attributeNode);
}
Collections.sort(nodes, new Comparator<AttributeNode>() {
@Override
public int compare(AttributeNode o1, AttributeNode o2) {
return o1.getName().compareTo(o2.getName());
}
});
attributeRootNodes = nodes;
}
Aggregations