use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class JmxGetTest method testJmxGetStatsSingleSimilar.
@Test
public void testJmxGetStatsSingleSimilar() throws MalformedObjectNameException {
StatsEngine stats = new StatsEngineImpl();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
List<JmxMetric> metrics = new ArrayList<>();
metrics.add(JmxMetric.create("hello3", JmxType.SIMPLE));
metrics.add(JmxMetric.create("goodbye3", JmxType.SIMPLE));
JmxGet object = new JmxSingleMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
Map<ObjectName, Map<String, Float>> data = new HashMap<>();
Map<String, Float> values1 = new HashMap<>();
values1.put("hello3", 2f);
values1.put("goodbye3", 3f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
Map<String, Float> values2 = new HashMap<>();
values2.put("hello3", 4f);
values2.put("goodbye3", 5f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
Map<String, Float> values3 = new HashMap<>();
values3.put("hello3", 5f);
values3.put("goodbye3", 7f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
object.recordStats(stats, data, server);
Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getCallCount());
Assert.assertEquals(3, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getCallCount());
Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello3").getTotal(), .001);
Assert.assertEquals(15f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye3").getTotal(), .001);
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class JmxGetTest method testJmxGetStatsMultiSimilar.
@Test
public void testJmxGetStatsMultiSimilar() throws MalformedObjectNameException {
StatsEngine stats = new StatsEngineImpl();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
List<JmxMetric> metrics = new ArrayList<>();
metrics.add(JmxMetric.create("hello2", JmxType.SIMPLE));
metrics.add(JmxMetric.create("goodbye2", JmxType.MONOTONICALLY_INCREASING));
JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*,key2=*", "ThreadPool:type=rara,key1=*", "JmxBuiltIn/ThreadPool/{key1}", metrics, null, null);
Map<ObjectName, Map<String, Float>> data = new HashMap<>();
Map<String, Float> values1 = new HashMap<>();
values1.put("hello2", 2f);
values1.put("goodbye2", 4f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=b"), values1);
Map<String, Float> values2 = new HashMap<>();
values2.put("hello2", 4f);
values2.put("goodbye2", 5f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=c"), values2);
Map<String, Float> values3 = new HashMap<>();
values3.put("hello2", 5f);
values3.put("goodbye2", 7f);
data.put(new ObjectName("ThreadPool:type=rara,key1=a,key2=d"), values3);
object.recordStats(stats, data, server);
Assert.assertEquals(11f, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getTotal(), .001);
Assert.assertEquals(16f, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getTotal(), .001);
Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/hello2").getCallCount());
Assert.assertEquals(1, stats.getStats("JmxBuiltIn/ThreadPool/a/goodbye2").getCallCount());
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class CPUSamplerTest method test.
@Test
public void test() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("host", "localhost");
map.put("port", 3000);
map.put("ssl", false);
map.put("license_key", "bootstrap_newrelic_admin_license_key_000");
createServiceManager(map);
StatsEngine statsEngine = new StatsEngineImpl();
CPUHarvester harvester = new CPUHarvester();
for (int i = 0; i < 10000; i++) {
harvester.recordCPU(statsEngine);
statsEngine.getMetricNames();
}
List<MetricName> harvest = statsEngine.getMetricNames();
CountStats stats = null;
for (MetricName data : harvest) {
if (MetricNames.CPU.equals(data.getName())) {
stats = (CountStats) statsEngine.getStats(data);
break;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
stats.writeJSONString(writer);
writer.close();
System.err.println(out.toString());
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class AgentTest method ttSizeLimitExceeded.
/**
* If the transaction trace size limit is exceeded, a tracer should record metrics but not be part of the
* transaction trace.
*/
@Test
public void ttSizeLimitExceeded() throws ServletException, IOException {
TransactionDataList txs = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txs);
TestSizeLimitServlet servlet = new TestSizeLimitServlet();
String path = "/my/word";
AgentHelper.invokeServlet(servlet, "", APPLICATION_NAME_2, path);
StatsEngine statsEngine = AgentHelper.getDefaultStatsEngine();
MetricName metricName = MetricName.create("Custom/test.newrelic.test.agent.AgentTest$TestSizeLimitServlet/doNothing", "WebTransaction/Servlet/TestSizeLimitServlet");
ResponseTimeStats stats = statsEngine.getResponseTimeStats(metricName);
Assert.assertEquals(2, stats.getCallCount());
Assert.assertEquals(2, txs.size());
TransactionData transactionData = txs.get(1);
Collection<Tracer> tracers = AgentHelper.getTracers(transactionData.getRootTracer());
Assert.assertEquals(3, tracers.size());
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class ExpectedErrorsTest method expectedClassMessagesFallbackOverride.
@Test
public void expectedClassMessagesFallbackOverride() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("expected_class_messages_fallback_test");
try {
try {
// Doesn't matter what the message is, it will be expected
throwException(new ExpectedError("blah"));
fail("The expected exception was not thrown");
} catch (Throwable t) {
}
// Verify the transaction was created and finished
TransactionDataList transactionList = holder.getTransactionList();
ServiceFactory.getHarvestService().harvestNow();
assertEquals(1, transactionList.size());
TransactionData td = transactionList.get(0);
assertEquals("OtherTransaction/Custom/test.newrelic.test.agent.ExpectedErrorsTest/throwException", td.getPriorityTransactionName().getName());
StatsEngine statsEngine = holder.getStatsEngine();
assertEquals(0, statsEngine.getStats("Errors/all").getCallCount());
verifyExpectedErrorSupportabilityApiCalls(statsEngine, 0, 0, 1, 2);
verifyIgnoreErrorSupportabilityApiCalls(statsEngine, 0, 0, 1);
} finally {
holder.close();
}
}
Aggregations