Search in sources :

Example 31 with StatsService

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;
}
Also used : MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) DatabaseService(com.newrelic.agent.database.DatabaseService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) MockHarvestService(com.newrelic.agent.MockHarvestService) MockCoreService(com.newrelic.agent.MockCoreService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 32 with StatsService

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;
}
Also used : MockHarvestService(com.newrelic.agent.MockHarvestService) HarvestService(com.newrelic.agent.HarvestService) TransactionService(com.newrelic.agent.TransactionService) ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) StatsService(com.newrelic.agent.stats.StatsService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) DatabaseService(com.newrelic.agent.database.DatabaseService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) AgentConfig(com.newrelic.agent.config.AgentConfig) ThreadService(com.newrelic.agent.ThreadService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) ClassTransformerService(com.newrelic.agent.instrumentation.ClassTransformerService) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) MockHarvestService(com.newrelic.agent.MockHarvestService) MockCoreService(com.newrelic.agent.MockCoreService) EnvironmentService(com.newrelic.agent.environment.EnvironmentService) MockRPMService(com.newrelic.agent.MockRPMService)

Example 33 with StatsService

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);
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) StatsService(com.newrelic.agent.stats.StatsService) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Aggregations

StatsService (com.newrelic.agent.stats.StatsService)33 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)24 MockServiceManager (com.newrelic.agent.MockServiceManager)18 ConfigService (com.newrelic.agent.config.ConfigService)17 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)16 MockRPMService (com.newrelic.agent.MockRPMService)14 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)13 TransactionService (com.newrelic.agent.TransactionService)13 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)13 HarvestService (com.newrelic.agent.HarvestService)11 MockCoreService (com.newrelic.agent.MockCoreService)11 MockHarvestService (com.newrelic.agent.MockHarvestService)11 ThreadService (com.newrelic.agent.ThreadService)11 AgentConfig (com.newrelic.agent.config.AgentConfig)11 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)10 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)10 AttributesService (com.newrelic.agent.attributes.AttributesService)9 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)8 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)7 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)7