Search in sources :

Example 1 with RangeStatistic

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

the class J2EEStatsAttributeTest method addJmxValueRangeTest.

@Test
public void addJmxValueRangeTest() {
    RangeStatistic count = new RangeStatistic() {

        @Override
        public String getUnit() {
            return null;
        }

        @Override
        public long getStartTime() {
            return 0;
        }

        @Override
        public String getName() {
            return "LiveCount";
        }

        @Override
        public long getLastSampleTime() {
            return 0;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public long getLowWaterMark() {
            return 0;
        }

        @Override
        public long getHighWaterMark() {
            return 10;
        }

        @Override
        public long getCurrent() {
            return 9;
        }
    };
    Map<String, Float> values = new HashMap<>();
    Attribute att = new Attribute("stats.LiveCount", count);
    J2EEStatsAttributeProcessor.addJmxValue(att, count, values);
    Assert.assertEquals(9, values.get("stats.LiveCount"), .001);
    att = new Attribute("LiveCount", count);
    values.clear();
    J2EEStatsAttributeProcessor.addJmxValue(att, count, values);
    Assert.assertNull(values.get("stats.LiveCount"));
    att = new Attribute("stats.ActiveCount", count);
    values.clear();
    J2EEStatsAttributeProcessor.addJmxValue(att, count, values);
    Assert.assertNull(values.get("stats.LiveCount"));
    Assert.assertNull(values.get("stats.ActiveCount"));
}
Also used : RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) HashMap(java.util.HashMap) Attribute(javax.management.Attribute) Test(org.junit.Test)

Example 2 with RangeStatistic

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

the class J2EEStatsAttributeTest method processStatRangeTest.

@Test
public void processStatRangeTest() {
    RangeStatistic count = new RangeStatistic() {

        @Override
        public String getUnit() {
            return null;
        }

        @Override
        public long getStartTime() {
            return 0;
        }

        @Override
        public String getName() {
            return "LiveCount";
        }

        @Override
        public long getLastSampleTime() {
            return 0;
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public long getLowWaterMark() {
            return 0;
        }

        @Override
        public long getHighWaterMark() {
            return 10;
        }

        @Override
        public long getCurrent() {
            return 9;
        }
    };
    Attribute att = new Attribute("stats.LiveCount", count);
    StatsEngine statsEngine = new StatsEngineImpl();
    J2EEStatsAttributeProcessor.processStatistic(statsEngine, "Jmx/Test", att, count);
    Assert.assertEquals(9, statsEngine.getStats("Jmx/Test/LiveCount").getTotal(), .001);
}
Also used : RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 3 with RangeStatistic

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

the class J2EEStatsAttributeProcessor method processStatistic.

static void processStatistic(StatsEngine statsEngine, String metricName, Attribute attribute, Statistic statistic) {
    String fullMetricName = metricName + '/' + statistic.getName();
    Agent.LOG.finer(MessageFormat.format("Processing J2EE statistic: {0} class: {1}", statistic.getName(), statistic.getClass().getName()));
    if (statistic instanceof CountStatistic) {
        CountStatistic stat = (CountStatistic) statistic;
        statsEngine.getStats(fullMetricName).recordDataPoint(stat.getCount());
    } else if (statistic instanceof RangeStatistic) {
        RangeStatistic stat = (RangeStatistic) statistic;
        statsEngine.getStats(fullMetricName).recordDataPoint(stat.getCurrent());
    } else if (statistic instanceof BoundaryStatistic) {
        BoundaryStatistic stat = (BoundaryStatistic) statistic;
        statsEngine.getStats(fullMetricName).recordDataPoint(stat.getLowerBound());
        statsEngine.getStats(fullMetricName).recordDataPoint(stat.getUpperBound());
    } else if (statistic instanceof TimeStatistic) {
        TimeStatistic stat = (TimeStatistic) statistic;
        TimeUnit unit = getTimeUnit(stat.getUnit());
        statsEngine.getResponseTimeStats(fullMetricName).recordResponseTime((int) stat.getCount(), stat.getTotalTime(), stat.getMinTime(), stat.getMaxTime(), unit);
    } else {
        Agent.LOG.log(Level.FINEST, "Not supported: {0}", statistic.getClass().getName());
    }
    Agent.LOG.finer(MessageFormat.format("Processed J2EE statistic: {0} att: {1}", fullMetricName, statistic.getName()));
}
Also used : RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) TimeUnit(java.util.concurrent.TimeUnit) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) CountStatistic(javax.management.j2ee.statistics.CountStatistic)

Example 4 with RangeStatistic

use of javax.management.j2ee.statistics.RangeStatistic 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

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