Search in sources :

Example 16 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class CommandParser method beforeHarvest.

/**
 * Gets the agent commands from the rpm service, processes them, and returns the command results.
 *
 * @see RPMService#getAgentCommands()
 * @see RPMService#sendCommandResults(Map)
 */
@Override
public void beforeHarvest(String appName, StatsEngine statsEngine) {
    IRPMService rpmService = ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName);
    for (Iterator<Map<Long, Object>> iterator = unsentCommandData.iterator(); iterator.hasNext(); ) {
        Map<Long, Object> result = iterator.next();
        try {
            rpmService.sendCommandResults(result);
            iterator.remove();
        } catch (HttpError e) {
            if (e.discardHarvestData()) {
                iterator.remove();
            } else {
                String msg = MessageFormat.format("Unable to send agent command feedback. Data will be retried " + "on the next harvest. Command results: {0}", result.toString());
                getLogger().fine(msg);
            }
        } catch (Exception e) {
            iterator.remove();
            String msg = MessageFormat.format("Unable to send agent command feedback. Data will be dropped. " + "Command results: {0}", result.toString());
            getLogger().fine(msg);
        }
    }
    List<List<?>> commands;
    try {
        commands = rpmService.getAgentCommands();
    } catch (Exception e) {
        getLogger().log(Level.FINE, "Unable to get agent commands - {0}", e.toString());
        getLogger().log(Level.FINEST, e, e.toString());
        return;
    }
    Map<Long, Object> commandResults = processCommands(rpmService, commands);
    try {
        rpmService.sendCommandResults(commandResults);
    } catch (HttpError e) {
        if (!e.discardHarvestData()) {
            unsentCommandData.add(commandResults);
            String msg = MessageFormat.format("Unable to send agent command feedback. Data will be retried on the next harvest. Command results: {0}", commandResults.toString());
            getLogger().fine(msg);
        }
    } catch (Exception e) {
        String msg = MessageFormat.format("Unable to send agent command feedback. Command results: {0}", commandResults.toString());
        getLogger().fine(msg);
    }
}
Also used : IRPMService(com.newrelic.agent.IRPMService) ArrayList(java.util.ArrayList) List(java.util.List) HttpError(com.newrelic.agent.transport.HttpError) HashMap(java.util.HashMap) Map(java.util.Map) JSONException(com.newrelic.agent.util.JSONException)

Example 17 with IRPMService

use of com.newrelic.agent.IRPMService in project newrelic-java-agent by newrelic.

the class SamplerServiceImpl method runSampler.

private void runSampler(MetricSampler sampler) {
    if (!coreService.isEnabled()) {
        return;
    }
    sampler.sample(statsEngine);
    if (!isAutoAppNamingEnabled) {
        mergeStatsEngine(defaultAppName);
        return;
    }
    List<IRPMService> rpmServices = ServiceFactory.getRPMServiceManager().getRPMServices();
    for (IRPMService rpmService : rpmServices) {
        String appName = rpmService.getApplicationName();
        mergeStatsEngine(appName);
    }
}
Also used : IRPMService(com.newrelic.agent.IRPMService)

Aggregations

IRPMService (com.newrelic.agent.IRPMService)17 Test (org.junit.Test)11 HashMap (java.util.HashMap)9 AgentConfig (com.newrelic.agent.config.AgentConfig)4 MockServiceManager (com.newrelic.agent.MockServiceManager)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)1 RPMServiceManager (com.newrelic.agent.RPMServiceManager)1 TransactionService (com.newrelic.agent.TransactionService)1 ConfigServiceImpl (com.newrelic.agent.config.ConfigServiceImpl)1 ErrorService (com.newrelic.agent.errors.ErrorService)1 ClassTransformerService (com.newrelic.agent.instrumentation.ClassTransformerService)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)1 HttpError (com.newrelic.agent.transport.HttpError)1 JSONException (com.newrelic.agent.util.JSONException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1