Search in sources :

Example 1 with CountStatistic

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

the class J2EEStatsAttributeTest method processStatisticCountTest.

@Test
public void processStatisticCountTest() {
    CountStatistic count = new CountStatistic() {

        @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 getCount() {
            return 55;
        }
    };
    Attribute att = new Attribute("stats.LiveCount", count);
    StatsEngine statsEngine = new StatsEngineImpl();
    J2EEStatsAttributeProcessor.processStatistic(statsEngine, "Jmx/Test", att, count);
    Assert.assertEquals(55, statsEngine.getStats("Jmx/Test/LiveCount").getTotal(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) Test(org.junit.Test)

Example 2 with CountStatistic

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

the class J2EEStatsAttributeTest method processStatistic_count.

@Test
public void processStatistic_count() {
    CountStatistic statistic = Mockito.mock(CountStatistic.class);
    Mockito.when(statistic.getName()).thenReturn("CoolCount");
    Mockito.when(statistic.getCount()).thenReturn(66L);
    StatsImpl stat = new StatsImpl(0, 0, 0, 0, 0);
    StatsEngine statsEngine = Mockito.mock(StatsEngine.class);
    Mockito.when(statsEngine.getStats("Test/Metric/CoolCount")).thenReturn(stat);
    J2EEStatsAttributeProcessor.processStatistic(statsEngine, "Test/Metric", new Attribute("CoolCount", -32), statistic);
    Mockito.verify(statsEngine, times(1)).getStats("Test/Metric/CoolCount");
    Assert.assertEquals(66, stat.getTotal(), .0001);
}
Also used : StatsImpl(com.newrelic.agent.stats.StatsImpl) Attribute(javax.management.Attribute) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) Test(org.junit.Test)

Example 3 with CountStatistic

use of javax.management.j2ee.statistics.CountStatistic in project Payara by payara.

the class StatsImpl method statToString.

public String statToString() {
    StringBuilder sbuf = new StringBuilder();
    Statistic[] stats = getStatistics();
    int sz = stats.length;
    for (int i = 0; i < sz; i++) {
        if (stats[i] instanceof CountStatistic) {
            CountStatistic stat = (CountStatistic) stats[i];
            sbuf.append(stat.getName()).append("=").append(stat.getCount()).append("; ");
        } else if (stats[i] instanceof BoundedRangeStatistic) {
            BoundedRangeStatistic stat = (BoundedRangeStatistic) stats[i];
            sbuf.append(stat.getName()).append("=").append(stat.getCurrent()).append("; ");
        } else {
            sbuf.append(stats[i].getName()).append("=?");
        }
    }
    return sbuf.toString();
}
Also used : CountStatistic(javax.management.j2ee.statistics.CountStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) Statistic(javax.management.j2ee.statistics.Statistic) CountStatistic(javax.management.j2ee.statistics.CountStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic)

Example 4 with CountStatistic

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

the class J2EEStatsAttributeTest method addJmxValueCountTest.

@Test
public void addJmxValueCountTest() {
    CountStatistic count = new CountStatistic() {

        @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 getCount() {
            return 55;
        }
    };
    Map<String, Float> values = new HashMap<>();
    Attribute att = new Attribute("stats.LiveCount", count);
    J2EEStatsAttributeProcessor.addJmxValue(att, count, values);
    Assert.assertEquals(55, 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 : HashMap(java.util.HashMap) Attribute(javax.management.Attribute) CountStatistic(javax.management.j2ee.statistics.CountStatistic) Test(org.junit.Test)

Example 5 with CountStatistic

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

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