Search in sources :

Example 6 with CountStatistic

use of javax.management.j2ee.statistics.CountStatistic in project newrelic-java-agent by newrelic.

the class J2EEStatsAttributeProcessor method addJmxValue.

/**
 * Return true if the metric was found, meaning we do not need to continue through the rest of the metrics.
 */
static boolean addJmxValue(Attribute attribute, Statistic statistic, Map<String, Float> values) {
    if (attribute.getName().contains(statistic.getName())) {
        Agent.LOG.finer(MessageFormat.format("Adding J2EE statistic to List: {0} class: {1}", attribute.getName(), statistic.getClass().getName()));
        if (statistic instanceof CountStatistic) {
            CountStatistic stat = (CountStatistic) statistic;
            values.put(attribute.getName(), (float) stat.getCount());
            return true;
        } else if (statistic instanceof RangeStatistic) {
            RangeStatistic stat = (RangeStatistic) statistic;
            values.put(attribute.getName(), (float) stat.getCurrent());
            return true;
        } else if (statistic instanceof BoundaryStatistic) {
            BoundaryStatistic stat = (BoundaryStatistic) statistic;
            values.put(attribute.getName(), (float) ((stat.getLowerBound() + stat.getUpperBound()) / 2));
            return true;
        } else if (statistic instanceof TimeStatistic) {
            TimeStatistic stat = (TimeStatistic) statistic;
            if (stat.getCount() == 0) {
                values.put(attribute.getName(), 0f);
            } else {
                values.put(attribute.getName(), (float) (stat.getTotalTime() / stat.getCount()));
            }
            return true;
        }
        Agent.LOG.finer(MessageFormat.format("Added J2EE statistic: {0}", attribute.getName()));
    } else {
        Agent.LOG.log(Level.FINEST, MessageFormat.format("Ignoring stat {0}. Looking for att name {1}.", statistic.getName(), attribute.getName()));
    }
    return false;
}
Also used : RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) CountStatistic(javax.management.j2ee.statistics.CountStatistic)

Aggregations

CountStatistic (javax.management.j2ee.statistics.CountStatistic)6 Attribute (javax.management.Attribute)3 Test (org.junit.Test)3 StatsEngine (com.newrelic.agent.stats.StatsEngine)2 BoundaryStatistic (javax.management.j2ee.statistics.BoundaryStatistic)2 RangeStatistic (javax.management.j2ee.statistics.RangeStatistic)2 TimeStatistic (javax.management.j2ee.statistics.TimeStatistic)2 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 StatsImpl (com.newrelic.agent.stats.StatsImpl)1 HashMap (java.util.HashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 BoundedRangeStatistic (javax.management.j2ee.statistics.BoundedRangeStatistic)1 Statistic (javax.management.j2ee.statistics.Statistic)1