use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class JmxGetTest method testJmxGetStatsMulti.
@Test
public void testJmxGetStatsMulti() throws MalformedObjectNameException {
StatsEngine stats = new StatsEngineImpl();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
List<JmxMetric> metrics = new ArrayList<>();
metrics.add(JmxMetric.create("hello1", JmxType.SIMPLE));
metrics.add(JmxMetric.create("goodbye1", JmxType.MONOTONICALLY_INCREASING));
JmxGet object = new JmxMultiMBeanGet("ThreadPool:type=rara,key1=*", "ThreadPool:type=rara,key1=*", null, metrics, null, null);
Map<String, Float> values = new HashMap<>();
values.put("hello1", 5f);
values.put("goodbye1", 4f);
object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
Assert.assertEquals(5f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getTotal(), .001);
Assert.assertEquals(4f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getTotal(), .001);
values.clear();
values.put("hello1", 6f);
values.put("goodbye1", 7f);
object.recordStats(stats, createMap("ThreadPool:type=rara,key1=a", values), server);
Assert.assertEquals(11f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getTotal(), .001);
Assert.assertEquals(7f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getTotal(), .001);
Assert.assertEquals(2f, stats.getStats("JMX/ThreadPool/rara/a/hello1").getCallCount(), .001);
Assert.assertEquals(2f, stats.getStats("JMX/ThreadPool/rara/a/goodbye1").getCallCount(), .001);
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class JmxObjectFactoryTest method verifyYml.
private void verifyYml(List<JmxGet> actual) throws MalformedObjectNameException {
StatsEngine stats = new StatsEngineImpl();
Map<String, Float> values = new HashMap<>();
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Assert.assertEquals(4, actual.size());
JmxGet one = actual.get(3);
Assert.assertEquals("solr*:type=queryResultCache,*", one.getObjectName().toString());
Assert.assertTrue(one.getAttributes().contains("lookups"));
// LOOKUPS
values.put("lookups", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("lookups", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// HITS
values.clear();
values.put("hits", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/hits").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("hits", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/hits").getTotal(), .001);
// hitratio
values.clear();
values.put("hitratio", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/hitratio").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("hitratio", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/hitratio").getTotal(), .001);
// size
values.clear();
values.put("size", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("size", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// cumulative_hitratio
values.clear();
values.put("cumulative_hitratio", 1f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("cumulative_hitratio", 4f);
one.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
stats = new StatsEngineImpl();
JmxGet two = actual.get(2);
// lookups
values.clear();
values.put("lookups", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// it should be monotonically increasing
values.clear();
values.put("lookups", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(4f, stats.getStats("JMX/solr/test/lookups").getTotal(), .001);
// size
values.clear();
values.put("size", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// it should be simple
values.clear();
values.put("size", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(5f, stats.getStats("JMX/solr/test/size").getTotal(), .001);
// cumulative_hitratio
values.clear();
values.put("cumulative_hitratio", 1f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(1f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
// it should be simple
values.clear();
values.put("cumulative_hitratio", 4f);
two.recordStats(stats, createMap("solr:type=test", values), server);
Assert.assertEquals(5f, stats.getStats("JMX/solr/test/cumulative_hitratio").getTotal(), .001);
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class Harvestable method recordIntervalMetric.
private void recordIntervalMetric() {
long startTimeInNanos = System.nanoTime();
final long harvestIntervalInNanos = startTimeInNanos - lastHarvest;
lastHarvest = startTimeInNanos;
ServiceFactory.getStatsService().doStatsWork(new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
if (harvestIntervalInNanos > 0) {
statsEngine.getResponseTimeStats(service.getEventHarvestIntervalMetric()).recordResponseTime(harvestIntervalInNanos, TimeUnit.NANOSECONDS);
}
}
@Override
public String getAppName() {
return appName;
}
}, "HarvestInterval");
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class ErrorServiceImpl method harvestEvents.
public void harvestEvents(final String appName) {
boolean eventsEnabled = isEventsEnabledForApp(appName);
if (!eventsEnabled) {
reservoirForApp.remove(appName);
return;
}
if (maxSamplesStored <= 0) {
clearReservoir(appName);
return;
}
long startTimeInNanos = System.nanoTime();
final DistributedSamplingPriorityQueue<ErrorEvent> reservoir = reservoirForApp.put(appName, new DistributedSamplingPriorityQueue<ErrorEvent>(appName, "Error Service", maxSamplesStored));
if (reservoir != null && reservoir.size() > 0) {
try {
ServiceFactory.getRPMServiceManager().getOrCreateRPMService(appName).sendErrorEvents(maxSamplesStored, reservoir.getNumberOfTries(), Collections.unmodifiableList(reservoir.asList()));
final long durationInNanos = System.nanoTime() - startTimeInNanos;
ServiceFactory.getStatsService().doStatsWork(new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
recordSupportabilityMetrics(statsEngine, durationInNanos, reservoir);
}
@Override
public String getAppName() {
return appName;
}
}, reservoir.getServiceName());
if (reservoir.size() < reservoir.getNumberOfTries()) {
int dropped = reservoir.getNumberOfTries() - reservoir.size();
Agent.LOG.log(Level.FINE, "Dropped {0} error events out of {1}.", dropped, reservoir.getNumberOfTries());
}
} catch (HttpError e) {
if (!e.discardHarvestData()) {
Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be included in the next harvest.", e);
// Save unsent data by merging it with current data using reservoir algorithm
DistributedSamplingPriorityQueue<ErrorEvent> currentReservoir = reservoirForApp.get(appName);
currentReservoir.retryAll(reservoir);
} else {
// discard harvest data
reservoir.clear();
Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be dropped.", e);
}
} catch (Exception e) {
// discard harvest data
reservoir.clear();
Agent.LOG.log(Level.FINE, "Unable to send error events. Unsent events will be dropped.", e);
}
}
}
use of com.newrelic.agent.stats.StatsEngine in project newrelic-java-agent by newrelic.
the class SpanEventsServiceImpl method harvestEvents.
@Override
public void harvestEvents(final String appName) {
if (!spanEventsConfig.isEnabled() || reservoirManager.getMaxSamplesStored() <= 0) {
clearReservoir();
return;
}
long startTimeInNanos = System.nanoTime();
final ReservoirManager.HarvestResult result = reservoirManager.attemptToSendReservoir(appName, collectorSender, logger);
if (result != null) {
final long durationInNanos = System.nanoTime() - startTimeInNanos;
ServiceFactory.getStatsService().doStatsWork(new StatsWork() {
@Override
public void doWork(StatsEngine statsEngine) {
recordSupportabilityMetrics(statsEngine, durationInNanos, result.sent, result.seen);
}
@Override
public String getAppName() {
return appName;
}
}, "HarvestResult");
}
}
Aggregations