use of com.newrelic.agent.jmx.JmxService in project newrelic-java-agent by newrelic.
the class ExtensionService method reloadCustomExtensionsIfModified.
private void reloadCustomExtensionsIfModified() {
File[] xmlFiles = getExtensionFiles(ExtensionFileTypes.XML.getFilter());
File[] ymlFiles = getExtensionFiles(ExtensionFileTypes.YML.getFilter());
// element count start at -1 to ensure fileModified is true the first time
boolean fileModified = (xmlFiles.length + ymlFiles.length) != elementCount;
if (!fileModified) {
for (File file : xmlFiles) {
fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
}
for (File file : ymlFiles) {
fileModified |= (file.lastModified() <= System.currentTimeMillis() && lastReloaded < file.lastModified());
}
}
// if you are changing be sure to test without an extensions directory
if (fileModified) {
lastReloaded = System.currentTimeMillis();
elementCount = xmlFiles.length + ymlFiles.length;
pointCuts.clear();
HashMap<String, Extension> allExtensions = new HashMap<>(internalExtensions);
loadValidExtensions(xmlFiles, extensionParsers.getXmlParser(), allExtensions);
loadValidExtensions(ymlFiles, extensionParsers.getYamlParser(), allExtensions);
Set<Extension> externalExtensions = new HashSet<>(allExtensions.values());
externalExtensions.removeAll(internalExtensions.values());
Set<Extension> oldExtensions = extensions;
extensions = Collections.unmodifiableSet(externalExtensions);
JmxService jmxService = ServiceFactory.getJmxService();
if (jmxService != null) {
jmxService.reloadExtensions(oldExtensions, extensions);
}
for (Extension extension : allExtensions.values()) {
pointCuts.addAll(extension.getInstrumentationMatchers());
}
ClassRetransformer retransformer = ServiceFactory.getClassTransformerService().getLocalRetransformer();
if (retransformer != null) {
Class<?>[] allLoadedClasses = ServiceFactory.getCoreService().getInstrumentation().getAllLoadedClasses();
retransformer.setClassMethodMatchers(pointCuts);
InstrumentationContextClassMatcherHelper matcherHelper = new InstrumentationContextClassMatcherHelper();
Set<Class<?>> classesToRetransform = ClassesMatcher.getMatchingClasses(retransformer.getMatchers(), matcherHelper, allLoadedClasses);
ReinstrumentUtils.checkClassExistsAndRetransformClasses(new ReinstrumentResult(), Collections.<ExtensionClassAndMethodMatcher>emptyList(), null, classesToRetransform);
}
}
}
use of com.newrelic.agent.jmx.JmxService in project newrelic-java-agent by newrelic.
the class IntrospectorServiceManager method setup.
private void setup(Map<String, Object> config) {
configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), Collections.<String, Object>emptyMap());
ServiceFactory.setServiceManager(this);
coreService = new IntrospectorCoreService();
threadService = new ThreadService();
environmentService = new EnvironmentServiceImpl();
transactionService = new TransactionService();
rpmConnectionService = new IntrospectorRPMConnectService();
rpmServiceManager = new IntrospectorRPMServiceManager();
transactionTraceService = new IntrospectorTransactionTraceService();
asyncTxService = new AsyncTransactionService();
profilerService = new ProfilerService();
statsService = new IntrospectorStatsService();
harvestService = new IntrospectorHarvestService();
sqlTraceService = new SqlTraceServiceImpl();
insightsService = new IntrospectorInsightsService();
logSenderService = new IntrospectorLogSenderService();
expirationService = new ExpirationService();
dbService = new DatabaseService();
jarCollectorService = new IgnoringJarCollectorService();
distributedTraceService = new DistributedTraceServiceImpl();
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
transactionEventsService = new TransactionEventsService(transactionDataToDistributedTraceIntrinsics);
normalizationService = new NormalizationServiceImpl();
extensionService = new ExtensionService(configService, ExtensionsLoadedListener.NOOP);
tracerService = new TracerService();
commandParser = new CommandParser();
remoteInstrumentationService = new RemoteInstrumentationServiceImpl();
sourceLanguageService = new SourceLanguageService();
classTransformerService = new NoOpClassTransformerService();
jmxService = new JmxService(configService.getDefaultAgentConfig().getJmxConfig());
attributesService = new AttributesService();
circuitBreakerService = new CircuitBreakerService();
AgentConfig agentConfig = createAgentConfig(config, (Map) config.get("distributed_tracing"));
distributedTraceService.connected(null, agentConfig);
ReservoirManager<SpanEvent> reservoirManager = new CollectorSpanEventReservoirManager(configService);
ReservoirManager.EventSender<SpanEvent> collectorSender = new CollectorSpanEventSender(rpmServiceManager);
Consumer<SpanEvent> infiniteTracing = new Consumer<SpanEvent>() {
@Override
public void accept(SpanEvent spanEvent) {
}
};
SpanEventCreationDecider spanEventCreationDecider = new SpanEventCreationDecider(configService);
spanEventsService = new IntrospectorSpanEventService(agentConfig, reservoirManager, collectorSender, infiniteTracing, spanEventCreationDecider, environmentService, transactionDataToDistributedTraceIntrinsics);
configService.addIAgentConfigListener((IntrospectorSpanEventService) spanEventsService);
transactionService.addTransactionListener((IntrospectorSpanEventService) spanEventsService);
try {
transactionTraceService.start();
transactionEventsService.start();
transactionService.start();
} catch (Exception e) {
// fall through
}
}
use of com.newrelic.agent.jmx.JmxService in project newrelic-java-agent by newrelic.
the class JmxServiceStartTest method testStartConfig.
@Test
public void testStartConfig() {
JmxService jmxService = ServiceFactory.getJmxService();
List<JmxGet> configurations = jmxService.getConfigurations();
JavaLangJmxMetrics metrics = new JavaLangJmxMetrics();
int extCountInJmxYml = 3;
Assert.assertEquals(configurations.toString(), configurations.size(), metrics.getFrameworkMetrics().size() + extCountInJmxYml);
// verify two of the java lang object names are present
boolean isObjectNameIndex0 = false;
boolean isObjectNameIndex1 = false;
for (JmxGet current : configurations) {
if (metrics.getFrameworkMetrics().get(0).getObjectNameString().equals(current.getObjectNameString())) {
isObjectNameIndex0 = true;
} else if (metrics.getFrameworkMetrics().get(1).getObjectNameString().equals(current.getObjectNameString())) {
isObjectNameIndex1 = true;
}
}
Assert.assertTrue("Some of the java lang metrics are missing from the start up.", isObjectNameIndex0);
Assert.assertTrue("Some of the java lang metrics are missing from the start up.", isObjectNameIndex1);
}
use of com.newrelic.agent.jmx.JmxService in project newrelic-java-agent by newrelic.
the class JmxServiceTest method process.
@Test
public void process() {
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
StatsEngine statsEngine = new StatsEngineImpl();
JmxService jmxService = ServiceFactory.getJmxService();
jmxService.beforeHarvest(appName, statsEngine);
}
use of com.newrelic.agent.jmx.JmxService in project newrelic-java-agent by newrelic.
the class JmxServiceTest method testAddingToConfig.
@Test
public void testAddingToConfig() {
JmxService jmxService = ServiceFactory.getJmxService();
List<JmxGet> configurations = jmxService.getConfigurations();
int startupsize = configurations.size();
TomcatJmxValues tomcat = new TomcatJmxValues();
ResinJmxValues resin = new ResinJmxValues();
jmxService.addJmxFrameworkValues(tomcat);
jmxService.addJmxFrameworkValues(resin);
String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
StatsEngine statsEngine = new StatsEngineImpl();
jmxService.beforeHarvest(appName, statsEngine);
int expectedSize = startupsize + tomcat.getFrameworkMetrics().size() + resin.getFrameworkMetrics().size();
Assert.assertEquals("Failed on initial check: " + configurations.toString(), expectedSize, configurations.size());
GlassfishJmxValues glassfish = new GlassfishJmxValues();
jmxService.addJmxFrameworkValues(glassfish);
jmxService.beforeHarvest(appName, statsEngine);
int newExpectedSize = expectedSize + glassfish.getFrameworkMetrics().size();
Assert.assertEquals("Failed on second check: " + configurations.toString(), newExpectedSize, configurations.size());
JettyJmxMetrics jetty = new JettyJmxMetrics();
jmxService.addJmxFrameworkValues(jetty);
jmxService.beforeHarvest(appName, statsEngine);
int thirdExpectedSize = newExpectedSize + jetty.getFrameworkMetrics().size();
Assert.assertEquals("Failed on third check: " + configurations.toString(), thirdExpectedSize, configurations.size());
}
Aggregations