use of com.newrelic.agent.stats.StatsService in project newrelic-java-agent by newrelic.
the class SlowQueryAggregatorImplTest method createServiceManager.
private MockServiceManager createServiceManager(Map<String, Object> configMap) throws Exception {
AgentConfig config = AgentConfigFactory.createAgentConfig(configMap, null, null);
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
DatabaseService dbService = new DatabaseService();
serviceManager.setDatabaseService(dbService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
serviceManager.setDistributedTraceService(new DistributedTraceServiceImpl());
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceManager.setRPMService(rpmService);
configService.start();
serviceManager.start();
sqlTraceService.start();
sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
serviceManager.setAttributesService(new AttributesService());
return serviceManager;
}
use of com.newrelic.agent.stats.StatsService in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method createServiceManager.
private MockServiceManager createServiceManager(Map<String, Object> configMap) throws Exception {
AgentConfig config = AgentConfigImpl.createAgentConfig(configMap);
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
ConfigService configService = ConfigServiceFactory.createConfigService(config, configMap);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
ClassTransformerService classTransformerService = Mockito.mock(ClassTransformerService.class);
serviceManager.setClassTransformerService(classTransformerService);
HarvestService harvestService = new MockHarvestService();
serviceManager.setHarvestService(harvestService);
TransactionService transactionService = new TransactionService();
serviceManager.setTransactionService(transactionService);
StatsService statsService = new StatsServiceImpl();
serviceManager.setStatsService(statsService);
DatabaseService dbService = new DatabaseService();
serviceManager.setDatabaseService(dbService);
EnvironmentService envService = new EnvironmentServiceImpl();
serviceManager.setEnvironmentService(envService);
SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
serviceManager.setSqlTraceService(sqlTraceService);
MockCoreService agent = new MockCoreService();
serviceManager.setCoreService(agent);
serviceManager.setAttributesService(new AttributesService());
TransactionTraceService transactionTraceService = new TransactionTraceService();
serviceManager.setTransactionTraceService(transactionTraceService);
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
serviceManager.setRPMServiceManager(rpmServiceManager);
MockRPMService rpmService = new MockRPMService();
rpmService.setApplicationName(APP_NAME);
rpmService.setEverConnected(true);
rpmService.setErrorService(new ErrorServiceImpl(APP_NAME));
rpmServiceManager.setRPMService(rpmService);
configService.start();
serviceManager.start();
sqlTraceService.start();
return serviceManager;
}
use of com.newrelic.agent.stats.StatsService in project newrelic-java-agent by newrelic.
the class ThreadStateSamplerTest method testCpuTimeMetrics.
@Test
public void testCpuTimeMetrics() {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.setStatsService(new StatsServiceImpl());
StatsService statsService = ServiceFactory.getStatsService();
ThreadStateSampler threadStateSampler = new ThreadStateSampler(ManagementFactory.getThreadMXBean(), ThreadNameNormalizerTest.getThreadNameNormalizer());
CpuCalculationThread cpuCalculation = new CpuCalculationThread(threadStateSampler);
cpuCalculation.start();
try {
cpuCalculation.join();
} catch (InterruptedException e) {
}
StatsEngine engine = statsService.getStatsEngineForHarvest(null);
ResponseTimeStats systemTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/SystemTime");
ResponseTimeStats userTimeStats = engine.getResponseTimeStats("Threads/Time/CPU/CALCULATE_CPU/UserTime");
ResponseTimeStats totalTimeStats = engine.getResponseTimeStats("Threads/TotalTime/CALCULATE_CPU/CpuTime");
// these are approximate times
float systemTimeSeconds = systemTimeStats.getTotal();
float userTimeSeconds = userTimeStats.getTotal();
float totalTimeSeconds = totalTimeStats.getTotal();
float cpuCalculationTimeSeconds = (float) ((double) cpuCalculation.getCpuTime() / 1000000000) * 10;
assertTrue("CpuTime: " + cpuCalculationTimeSeconds + ", TotalTime: " + totalTimeSeconds, cpuCalculationTimeSeconds >= totalTimeSeconds);
assertTrue("UserTime: " + userTimeSeconds + ", SystemTime: " + systemTimeSeconds, userTimeSeconds > systemTimeSeconds);
// This test is prone to flickering due to high load scenarios and rounding errors, hence the modifier added to totalTimeSeconds
assertTrue("TotalTime: " + totalTimeSeconds + ", SystemTime: " + systemTimeSeconds + ", UserTime: " + userTimeSeconds, // account for rounding error
totalTimeSeconds + 4.0 >= systemTimeSeconds + userTimeSeconds);
// Since we can't guarantee the exact total time, it should be
// between 1 and 5 (since we had a busywork loop for ~5000ms)
assertTrue(totalTimeSeconds > 1.0f);
assertTrue(totalTimeSeconds < 6.0f);
}
Aggregations