Search in sources :

Example 11 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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 12 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jmxtrans by jmxtrans.

the class TreeWalker method walkTree.

public void walkTree(MBeanServerConnection connection) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        String[] attrNames = new String[attrs.length];
        for (int i = 0; i < attrs.length; i++) {
            attrNames[i] = attrs[i].getName();
        }
        try {
            AttributeList attributes = connection.getAttributes(name, attrNames);
            for (Attribute attribute : attributes.asList()) {
                output(name.getCanonicalName() + "%" + attribute.getName(), attribute.getValue());
            }
        } catch (Exception e) {
            log.error("error getting " + name + ":" + e.getMessage(), e);
        }
    }
}
Also used : MBeanInfo(javax.management.MBeanInfo) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) IOException(java.io.IOException) ObjectName(javax.management.ObjectName)

Example 13 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project jmxtrans by jmxtrans.

the class TreeWalker3 method walkTree.

public void walkTree(MBeanServerConnection connection, Server server) throws Exception {
    // key here is null, null returns everything!
    Set<ObjectName> mbeans = connection.queryNames(null, null);
    Map<String, String> output = newHashMap();
    for (ObjectName name : mbeans) {
        MBeanInfo info = connection.getMBeanInfo(name);
        MBeanAttributeInfo[] attrs = info.getAttributes();
        Query.Builder queryBuilder = Query.builder().setObj(name.getCanonicalName());
        ResultCapture resultCapture = new ResultCapture();
        queryBuilder.addOutputWriterFactory(resultCapture);
        for (MBeanAttributeInfo attrInfo : attrs) {
            queryBuilder.addAttr(attrInfo.getName());
        }
        Query query = queryBuilder.build();
        try {
            Iterable<Result> results = server.execute(query);
            query.runOutputWritersForQuery(server, results);
        } catch (AttributeNotFoundException anfe) {
            log.error("Error", anfe);
        }
        for (Result result : resultCapture.results) {
            output.put(result.getTypeName(), query.getAttr().toString());
        }
    }
    for (Entry<String, String> entry : output.entrySet()) {
        log.debug(entry.getKey());
        log.debug(entry.getValue());
        log.debug("-----------------------------------------");
    }
}
Also used : AttributeNotFoundException(javax.management.AttributeNotFoundException) MBeanInfo(javax.management.MBeanInfo) Query(com.googlecode.jmxtrans.model.Query) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) ObjectName(javax.management.ObjectName) Result(com.googlecode.jmxtrans.model.Result)

Example 14 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo 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 15 with MBeanAttributeInfo

use of javax.management.MBeanAttributeInfo in project neo4j by neo4j.

the class Neo4jManager method getConfiguration.

public Map<String, Object> getConfiguration() {
    final String[] keys;
    final AttributeList attributes;
    try {
        MBeanAttributeInfo[] keyInfo = server.getMBeanInfo(config).getAttributes();
        keys = new String[keyInfo.length];
        for (int i = 0; i < keys.length; i++) {
            keys[i] = keyInfo[i].getName();
        }
        attributes = server.getAttributes(config, keys);
    } catch (Exception e) {
        throw new IllegalStateException("Could not access the configuration bean", e);
    }
    Map<String, Object> configuration = new HashMap<>();
    for (int i = 0; i < keys.length; i++) {
        configuration.put(keys[i], attributes.get(i));
    }
    return configuration;
}
Also used : HashMap(java.util.HashMap) AttributeList(javax.management.AttributeList) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) AttributeNotFoundException(javax.management.AttributeNotFoundException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Aggregations

MBeanAttributeInfo (javax.management.MBeanAttributeInfo)106 MBeanInfo (javax.management.MBeanInfo)75 ObjectName (javax.management.ObjectName)45 MBeanOperationInfo (javax.management.MBeanOperationInfo)24 Test (org.junit.Test)21 MBeanServer (javax.management.MBeanServer)15 ArrayList (java.util.ArrayList)13 AttributeNotFoundException (javax.management.AttributeNotFoundException)12 ReflectionException (javax.management.ReflectionException)12 ModelMBeanAttributeInfo (javax.management.modelmbean.ModelMBeanAttributeInfo)11 IOException (java.io.IOException)10 AttributeList (javax.management.AttributeList)10 Attribute (javax.management.Attribute)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 IntrospectionException (javax.management.IntrospectionException)9 MBeanParameterInfo (javax.management.MBeanParameterInfo)9 ModelMBeanInfo (javax.management.modelmbean.ModelMBeanInfo)9 HashMap (java.util.HashMap)8 MBeanConstructorInfo (javax.management.MBeanConstructorInfo)7 MBeanException (javax.management.MBeanException)7