Search in sources :

Example 1 with JmxService

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);
        }
    }
}
Also used : ClassRetransformer(com.newrelic.agent.instrumentation.custom.ClassRetransformer) InstrumentationContextClassMatcherHelper(com.newrelic.agent.instrumentation.context.InstrumentationContextClassMatcherHelper) HashMap(java.util.HashMap) JmxService(com.newrelic.agent.jmx.JmxService) File(java.io.File) HashSet(java.util.HashSet) ReinstrumentResult(com.newrelic.agent.reinstrument.ReinstrumentResult)

Example 2 with JmxService

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
    }
}
Also used : ReservoirManager(com.newrelic.agent.interfaces.ReservoirManager) CommandParser(com.newrelic.agent.commands.CommandParser) Consumer(com.newrelic.agent.interfaces.backport.Consumer) ProfilerService(com.newrelic.agent.profile.ProfilerService) CircuitBreakerService(com.newrelic.agent.circuitbreaker.CircuitBreakerService) NormalizationServiceImpl(com.newrelic.agent.normalization.NormalizationServiceImpl) ExtensionService(com.newrelic.agent.extension.ExtensionService) RemoteInstrumentationServiceImpl(com.newrelic.agent.reinstrument.RemoteInstrumentationServiceImpl) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) JmxService(com.newrelic.agent.jmx.JmxService) AttributesService(com.newrelic.agent.attributes.AttributesService) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) DatabaseService(com.newrelic.agent.database.DatabaseService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) SpanEvent(com.newrelic.agent.model.SpanEvent) SourceLanguageService(com.newrelic.agent.language.SourceLanguageService)

Example 3 with JmxService

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);
}
Also used : JavaLangJmxMetrics(com.newrelic.agent.jmx.values.JavaLangJmxMetrics) JmxService(com.newrelic.agent.jmx.JmxService) JmxGet(com.newrelic.agent.jmx.create.JmxGet) Test(org.junit.Test)

Example 4 with JmxService

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);
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) JmxService(com.newrelic.agent.jmx.JmxService) StatsEngine(com.newrelic.agent.stats.StatsEngine) Test(org.junit.Test)

Example 5 with JmxService

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());
}
Also used : TomcatJmxValues(com.newrelic.agent.jmx.values.TomcatJmxValues) ResinJmxValues(com.newrelic.agent.jmx.values.ResinJmxValues) JettyJmxMetrics(com.newrelic.agent.jmx.values.JettyJmxMetrics) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) JmxService(com.newrelic.agent.jmx.JmxService) GlassfishJmxValues(com.newrelic.agent.jmx.values.GlassfishJmxValues) StatsEngine(com.newrelic.agent.stats.StatsEngine) JmxGet(com.newrelic.agent.jmx.create.JmxGet) Test(org.junit.Test)

Aggregations

JmxService (com.newrelic.agent.jmx.JmxService)8 AttributesService (com.newrelic.agent.attributes.AttributesService)3 CircuitBreakerService (com.newrelic.agent.circuitbreaker.CircuitBreakerService)3 DatabaseService (com.newrelic.agent.database.DatabaseService)3 ExtensionService (com.newrelic.agent.extension.ExtensionService)3 JmxGet (com.newrelic.agent.jmx.create.JmxGet)3 SourceLanguageService (com.newrelic.agent.language.SourceLanguageService)3 ProfilerService (com.newrelic.agent.profile.ProfilerService)3 AsyncTransactionService (com.newrelic.agent.service.async.AsyncTransactionService)3 Test (org.junit.Test)3 ExpirationService (com.newrelic.agent.ExpirationService)2 GCService (com.newrelic.agent.GCService)2 ThreadService (com.newrelic.agent.ThreadService)2 TracerService (com.newrelic.agent.TracerService)2 TransactionService (com.newrelic.agent.TransactionService)2 CacheService (com.newrelic.agent.cache.CacheService)2 CommandParser (com.newrelic.agent.commands.CommandParser)2 DeadlockDetectorService (com.newrelic.agent.deadlock.DeadlockDetectorService)2 EnvironmentServiceImpl (com.newrelic.agent.environment.EnvironmentServiceImpl)2 JfrService (com.newrelic.agent.jfr.JfrService)2