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);
}
}
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);
}
}
Aggregations