use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class RPMConnectionServiceTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
AgentHelper.initializeConfig();
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> settings = AgentConfigFactoryTest.createStagingMap();
AgentConfig config = AgentConfigFactory.createAgentConfig(settings, null, null);
Environment env = new Environment(config, "c:\\test\\log");
EnvironmentService envService = Mockito.mock(EnvironmentService.class, new Returns(env));
serviceManager.setEnvironmentService(envService);
ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(settings);
serviceManager.setConfigService(configService);
ThreadService threadService = new ThreadService();
serviceManager.setThreadService(threadService);
rpmConnectionService = new TestRPMConnectionService();
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class RPMService method getStartOptions.
/**
* Returns a map of startup options to be sent to RPM when the RPM service connects.
*/
protected Map<String, Object> getStartOptions() {
AgentConfig agentConfig = ServiceFactory.getConfigService().getAgentConfig(appName);
int pid = ServiceFactory.getEnvironmentService().getProcessPID();
Map<String, Object> options = new HashMap<>();
// options.add(System.getProperty("user.dir"));
options.put("pid", pid);
String language = agentConfig.getLanguage();
options.put("language", language);
String defaultHost = Hostname.getHostname(agentConfig, true);
options.put("host", defaultHost);
String displayHost = Hostname.getDisplayHostname(agentConfig, defaultHost);
options.put("display_host", displayHost);
Agent.LOG.log(Level.INFO, "Host name is {0}, display host {1} for application {2}", defaultHost, displayHost, appName);
options.put("high_security", getAndLogHighSecurity(agentConfig));
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
options.put("environment", environment);
options.put("settings", getSettings(agentConfig.getProperty("send_environment_info", true)));
UtilizationData utilizationData = ServiceFactory.getUtilizationService().updateUtilizationData();
options.put("utilization", utilizationData.map());
options.put(AgentConfigFactory.EVENT_HARVEST_CONFIG, ServiceFactory.getHarvestService().getEventDataHarvestLimits());
String instanceName = environment.getAgentIdentity().getInstanceName();
if (instanceName != null) {
options.put("instance_name", instanceName);
}
// options.put("framework", "java"); // this belongs in the environment
// options.put("launch_time",
// JSON.serializeNumber(TimeConversion.convertMillisToSeconds(System.currentTimeMillis())));
options.put("agent_version", Agent.getVersion());
options.put("app_name", appNames);
StringBuilder identifier = new StringBuilder(language);
identifier.append(':').append(appName);
Integer serverPort = environment.getAgentIdentity().getServerPort();
if (serverPort != null) {
identifier.append(':').append(serverPort);
}
options.put("identifier", identifier.toString());
options.put("labels", agentConfig.getLabelsConfig());
return options;
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method multipleRPMServices.
@Test
public void multipleRPMServices() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final CountDownLatch latch = new CountDownLatch(2);
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch.countDown();
}
};
final CountDownLatch latch2 = new CountDownLatch(2);
MyRPMService rpmService2 = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch2.countDown();
}
};
TestHarvestService harvestService = new TestHarvestService();
harvestService.setReportingPeriod(500L);
harvestService.start();
harvestService.startHarvest(rpmService);
harvestService.startHarvest(rpmService2);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
harvestService.stop();
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method harvestNowWhenHarvestNotRunning.
@Test
public void harvestNowWhenHarvestNotRunning() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final AtomicInteger harvestCount = new AtomicInteger();
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
harvestCount.incrementAndGet();
}
};
TestHarvestService harvestService = new TestHarvestService(666000L);
harvestService.setReportingPeriod(1000000L);
harvestService.start();
harvestService.startHarvest(rpmService);
// try to do an immediate harvest
harvestService.harvestNow();
// should run harvest
Assert.assertEquals(1, harvestCount.get());
harvestService.stop();
}
use of com.newrelic.agent.environment.Environment in project newrelic-java-agent by newrelic.
the class HarvestServiceTest method harvestListener.
@Test
public void harvestListener() throws Exception {
Environment environment = ServiceFactory.getEnvironmentService().getEnvironment();
environment.setServerPort(null);
final CountDownLatch latch = new CountDownLatch(1);
MyRPMService rpmService = new MyRPMService() {
@Override
public void harvest(StatsEngine statsEngine) {
latch.countDown();
}
};
final CountDownLatch latch2 = new CountDownLatch(1);
HarvestListener harvestListener = new HarvestListener() {
@Override
public void beforeHarvest(String appName, StatsEngine statsEngine) {
latch2.countDown();
}
@Override
public void afterHarvest(String appName) {
}
};
TestHarvestService harvestService = new TestHarvestService();
harvestService.setReportingPeriod(500L);
harvestService.addHarvestListener(harvestListener);
harvestService.start();
harvestService.startHarvest(rpmService);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(latch2.await(5, TimeUnit.SECONDS));
harvestService.stop();
}
Aggregations