use of javax.management.j2ee.statistics.JCAStats 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;
}
}
use of javax.management.j2ee.statistics.JCAStats in project newrelic-java-agent by newrelic.
the class J2EEStatsAttributeTest method addJcaValueJdbcTest.
@Test
public void addJcaValueJdbcTest() throws MalformedObjectNameException {
JCAStats count = new JCAStats() {
@Override
public JCAConnectionStats[] getConnections() {
return new JCAConnectionStats[0];
}
@Override
public JCAConnectionPoolStats[] getConnectionPools() {
return new JCAConnectionPoolStats[] { new TestJcaConnectionPool() };
}
@Override
public Statistic getStatistic(String statisticName) {
return null;
}
@Override
public String[] getStatisticNames() {
return null;
}
@Override
public Statistic[] getStatistics() {
return new Statistic[0];
}
};
Attribute att = new Attribute("stats", count);
J2EEStatsAttributeProcessor processor = new J2EEStatsAttributeProcessor();
StatsEngine engine = new StatsEngineImpl();
processor.process(engine, new ObjectInstance("tezt:type=2", "test"), att, "JMX/Test", new HashMap<String, Float>());
// check count stats
Assert.assertEquals(6, engine.getStats("JMX/Test/Create").getTotal(), .001);
Assert.assertEquals(1, engine.getStats("JMX/Test/Create").getCallCount(), .001);
Assert.assertEquals(99, engine.getStats("JMX/Test/Closed").getTotal(), .001);
Assert.assertEquals(1, engine.getStats("JMX/Test/Closed").getCallCount(), .001);
// check time stats
Assert.assertEquals(10, engine.getResponseTimeStats("JMX/Test/Wait").getMaxCallTime(), .001);
Assert.assertEquals(5, engine.getResponseTimeStats("JMX/Test/Wait").getMinCallTime(), .001);
Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/Wait").getCallCount(), .001);
Assert.assertEquals(6, engine.getResponseTimeStats("JMX/Test/User").getMaxCallTime(), .001);
Assert.assertEquals(4, engine.getResponseTimeStats("JMX/Test/User").getMinCallTime(), .001);
Assert.assertEquals(2, engine.getResponseTimeStats("JMX/Test/User").getCallCount(), .001);
}
Aggregations