Search in sources :

Example 1 with JmxAttributeGauge

use of com.codahale.metrics.JmxAttributeGauge in project metrics by dropwizard.

the class JCacheGaugeSet method getMetrics.

@Override
public Map<String, Metric> getMetrics() {
    Set<ObjectInstance> cacheBeans = getCacheBeans();
    List<String> availableStatsNames = retrieveStatsNames();
    Map<String, Metric> gauges = new HashMap<String, Metric>(cacheBeans.size() * availableStatsNames.size());
    for (ObjectInstance cacheBean : cacheBeans) {
        ObjectName objectName = cacheBean.getObjectName();
        String cacheName = objectName.getKeyProperty("Cache");
        for (String statsName : availableStatsNames) {
            JmxAttributeGauge jmxAttributeGauge = new JmxAttributeGauge(objectName, statsName);
            gauges.put(name(cacheName, toSpinalCase(statsName)), jmxAttributeGauge);
        }
    }
    return Collections.unmodifiableMap(gauges);
}
Also used : JmxAttributeGauge(com.codahale.metrics.JmxAttributeGauge) HashMap(java.util.HashMap) ObjectInstance(javax.management.ObjectInstance) Metric(com.codahale.metrics.Metric) ObjectName(javax.management.ObjectName)

Example 2 with JmxAttributeGauge

use of com.codahale.metrics.JmxAttributeGauge in project metrics by dropwizard.

the class BufferPoolMetricSet method getMetrics.

@Override
public Map<String, Metric> getMetrics() {
    final Map<String, Metric> gauges = new HashMap<String, Metric>();
    for (String pool : POOLS) {
        for (int i = 0; i < ATTRIBUTES.length; i++) {
            final String attribute = ATTRIBUTES[i];
            final String name = NAMES[i];
            try {
                final ObjectName on = new ObjectName("java.nio:type=BufferPool,name=" + pool);
                mBeanServer.getMBeanInfo(on);
                gauges.put(name(pool, name), new JmxAttributeGauge(mBeanServer, on, attribute));
            } catch (JMException ignored) {
                LOGGER.debug("Unable to load buffer pool MBeans, possibly running on Java 6");
            }
        }
    }
    return Collections.unmodifiableMap(gauges);
}
Also used : JmxAttributeGauge(com.codahale.metrics.JmxAttributeGauge) HashMap(java.util.HashMap) JMException(javax.management.JMException) Metric(com.codahale.metrics.Metric) ObjectName(javax.management.ObjectName)

Aggregations

JmxAttributeGauge (com.codahale.metrics.JmxAttributeGauge)2 Metric (com.codahale.metrics.Metric)2 HashMap (java.util.HashMap)2 ObjectName (javax.management.ObjectName)2 JMException (javax.management.JMException)1 ObjectInstance (javax.management.ObjectInstance)1