Search in sources :

Example 16 with MBeanInfo

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));
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Example 17 with MBeanInfo

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);
}
Also used : MBeanInfo(javax.management.MBeanInfo) TimeWindowStatistics(org.glassfish.jersey.server.monitoring.TimeWindowStatistics) MBeanAttributeInfo(javax.management.MBeanAttributeInfo)

Example 18 with MBeanInfo

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());
}
Also used : MBeanInfo(javax.management.MBeanInfo) AttributeList(javax.management.AttributeList) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) TabularData(javax.management.openmbean.TabularData)

Example 19 with MBeanInfo

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;
}
Also used : MBeanInfo(javax.management.MBeanInfo) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName)

Example 20 with MBeanInfo

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;
}
Also used : MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Aggregations

MBeanInfo (javax.management.MBeanInfo)154 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)87 ObjectName (javax.management.ObjectName)79 MBeanOperationInfo (javax.management.MBeanOperationInfo)38 MBeanServer (javax.management.MBeanServer)27 Test (org.junit.Test)27 Attribute (javax.management.Attribute)19 ArrayList (java.util.ArrayList)17 IntrospectionException (javax.management.IntrospectionException)16 ReflectionException (javax.management.ReflectionException)16 HashMap (java.util.HashMap)15 InstanceNotFoundException (javax.management.InstanceNotFoundException)15 IOException (java.io.IOException)12 MBeanNotificationInfo (javax.management.MBeanNotificationInfo)12 MBeanParameterInfo (javax.management.MBeanParameterInfo)12 MBeanServerConnection (javax.management.MBeanServerConnection)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)10 AttributeList (javax.management.AttributeList)9 AttributeNotFoundException (javax.management.AttributeNotFoundException)9 Descriptor (javax.management.Descriptor)8