Search in sources :

Example 1 with JDBCStats

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

the class J2EEStatsAttributeProcessor method process.

@Override
public boolean process(StatsEngine statsEngine, ObjectInstance instance, Attribute attribute, String metricName, Map<String, Float> values) {
    Object value = attribute.getValue();
    if (value instanceof Stats) {
        boolean isBuiltInMetric = isBuiltInMetric(metricName);
        if (value instanceof JDBCStats) {
            pullJDBCStats(statsEngine, (JDBCStats) value, attribute, metricName, values, isBuiltInMetric);
        } else if (value instanceof JCAStats) {
            pullJCAStats(statsEngine, (JCAStats) value, attribute, metricName, values, isBuiltInMetric);
        } else if (value instanceof JMSStats) {
            pullJMSStats(statsEngine, (JMSStats) value, attribute, metricName, values, isBuiltInMetric);
        } else {
            Stats jmxStats = (Stats) value;
            grabBaseStats(statsEngine, jmxStats, attribute, metricName, values, isBuiltInMetric);
        }
        return true;
    } else {
        Agent.LOG.finer(MessageFormat.format("Attribute value is not a javax.management.j2ee.statistics.Stats: {0}", value.getClass().getName()));
        return false;
    }
}
Also used : JMSConnectionStats(javax.management.j2ee.statistics.JMSConnectionStats) JCAConnectionPoolStats(javax.management.j2ee.statistics.JCAConnectionPoolStats) JMSSessionStats(javax.management.j2ee.statistics.JMSSessionStats) JCAStats(javax.management.j2ee.statistics.JCAStats) JMSStats(javax.management.j2ee.statistics.JMSStats) JCAConnectionStats(javax.management.j2ee.statistics.JCAConnectionStats) JDBCConnectionStats(javax.management.j2ee.statistics.JDBCConnectionStats) JDBCStats(javax.management.j2ee.statistics.JDBCStats) Stats(javax.management.j2ee.statistics.Stats) JDBCConnectionPoolStats(javax.management.j2ee.statistics.JDBCConnectionPoolStats) JDBCStats(javax.management.j2ee.statistics.JDBCStats) JCAStats(javax.management.j2ee.statistics.JCAStats) JMSStats(javax.management.j2ee.statistics.JMSStats)

Example 2 with JDBCStats

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

the class J2EEStatsAttributeTest method addJmxValueJdbcTest.

@Test
public void addJmxValueJdbcTest() throws MalformedObjectNameException {
    JDBCStats count = new JDBCStats() {

        @Override
        public Statistic[] getStatistics() {
            return new Statistic[0];
        }

        @Override
        public String[] getStatisticNames() {
            return null;
        }

        @Override
        public Statistic getStatistic(String statisticName) {
            return null;
        }

        @Override
        public JDBCConnectionStats[] getConnections() {
            return new JDBCConnectionStats[0];
        }

        @Override
        public JDBCConnectionPoolStats[] getConnectionPools() {
            return new JDBCConnectionPoolStats[] { new TestJdbcConnectionPool() };
        }
    };
    Attribute att = new Attribute("stats", count);
    J2EEStatsAttributeProcessor processor = new J2EEStatsAttributeProcessor();
    StatsEngine engine = new StatsEngineImpl();
    processor.process(engine, new ObjectInstance("tezt:type=1", "test"), att, "JMX/Test", new HashMap<String, Float>());
    // check count stats
    Assert.assertEquals(77, engine.getStats("JMX/Test/Create").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Create").getCallCount(), .001);
    Assert.assertEquals(9, engine.getStats("JMX/Test/Close").getTotal(), .001);
    Assert.assertEquals(1, engine.getStats("JMX/Test/Close").getCallCount(), .001);
    // check time stats
    Assert.assertEquals(12, engine.getResponseTimeStats("JMX/Test/WaitTime").getMaxCallTime(), .001);
    Assert.assertEquals(8, engine.getResponseTimeStats("JMX/Test/WaitTime").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/WaitTime").getCallCount(), .001);
    Assert.assertEquals(6, engine.getResponseTimeStats("JMX/Test/UserTime").getMaxCallTime(), .001);
    Assert.assertEquals(4, engine.getResponseTimeStats("JMX/Test/UserTime").getMinCallTime(), .001);
    Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/UserTime").getCallCount(), .001);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) Attribute(javax.management.Attribute) JDBCConnectionStats(javax.management.j2ee.statistics.JDBCConnectionStats) ObjectInstance(javax.management.ObjectInstance) JDBCStats(javax.management.j2ee.statistics.JDBCStats) StatsEngine(com.newrelic.agent.stats.StatsEngine) CountStatistic(javax.management.j2ee.statistics.CountStatistic) RangeStatistic(javax.management.j2ee.statistics.RangeStatistic) TimeStatistic(javax.management.j2ee.statistics.TimeStatistic) BoundedRangeStatistic(javax.management.j2ee.statistics.BoundedRangeStatistic) BoundaryStatistic(javax.management.j2ee.statistics.BoundaryStatistic) Statistic(javax.management.j2ee.statistics.Statistic) JDBCConnectionPoolStats(javax.management.j2ee.statistics.JDBCConnectionPoolStats) Test(org.junit.Test)

Aggregations

JDBCConnectionPoolStats (javax.management.j2ee.statistics.JDBCConnectionPoolStats)2 JDBCConnectionStats (javax.management.j2ee.statistics.JDBCConnectionStats)2 JDBCStats (javax.management.j2ee.statistics.JDBCStats)2 StatsEngine (com.newrelic.agent.stats.StatsEngine)1 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)1 Attribute (javax.management.Attribute)1 ObjectInstance (javax.management.ObjectInstance)1 BoundaryStatistic (javax.management.j2ee.statistics.BoundaryStatistic)1 BoundedRangeStatistic (javax.management.j2ee.statistics.BoundedRangeStatistic)1 CountStatistic (javax.management.j2ee.statistics.CountStatistic)1 JCAConnectionPoolStats (javax.management.j2ee.statistics.JCAConnectionPoolStats)1 JCAConnectionStats (javax.management.j2ee.statistics.JCAConnectionStats)1 JCAStats (javax.management.j2ee.statistics.JCAStats)1 JMSConnectionStats (javax.management.j2ee.statistics.JMSConnectionStats)1 JMSSessionStats (javax.management.j2ee.statistics.JMSSessionStats)1 JMSStats (javax.management.j2ee.statistics.JMSStats)1 RangeStatistic (javax.management.j2ee.statistics.RangeStatistic)1 Statistic (javax.management.j2ee.statistics.Statistic)1 Stats (javax.management.j2ee.statistics.Stats)1 TimeStatistic (javax.management.j2ee.statistics.TimeStatistic)1