use of com.codahale.metrics.Histogram in project airpal by airbnb.
the class LocalUsageStore method markUsage.
@Override
public void markUsage(Table table) {
Histogram window = usageMap.get(table);
if (window == null) {
final SlidingTimeWindowReservoir reservoir = new SlidingTimeWindowReservoir(usageTrackTime.getQuantity(), usageTrackTime.getUnit());
window = new Histogram(reservoir);
usageMap.put(table, window);
}
window.update(1);
}
use of com.codahale.metrics.Histogram in project spring-boot by spring-projects.
the class DropwizardMetricServicesTests method setCustomReservoirTimer.
@Test
public void setCustomReservoirTimer() {
given(this.reservoirFactory.getReservoir(anyString())).willReturn(new UniformReservoir());
this.writer.submit("timer.foo", 200);
this.writer.submit("timer.foo", 300);
assertThat(this.registry.timer("timer.foo").getCount()).isEqualTo(2);
Timer timer = (Timer) this.registry.getMetrics().get("timer.foo");
Histogram histogram = (Histogram) ReflectionTestUtils.getField(timer, "histogram");
assertThat(ReflectionTestUtils.getField(histogram, "reservoir").getClass().equals(UniformReservoir.class)).isTrue();
}
use of com.codahale.metrics.Histogram in project jstorm by alibaba.
the class TopologyMetricContext method adjustMetrics.
private void adjustMetrics(Map<String, Map<Integer, MetricSnapshot>> metrics, Map<String, Integer> metaCounters, Map<String, Map<Integer, Histogram>> histograms) {
for (Map.Entry<String, Map<Integer, MetricSnapshot>> metricEntry : metrics.entrySet()) {
String meta = metricEntry.getKey();
MetricType metricType = MetricUtils.metricType(meta);
MetaType metaType = MetricUtils.metaType(meta);
Map<Integer, MetricSnapshot> winData = metricEntry.getValue();
if (metricType == MetricType.HISTOGRAM) {
for (Map.Entry<Integer, MetricSnapshot> dataEntry : winData.entrySet()) {
MetricSnapshot snapshot = dataEntry.getValue();
Integer cnt = metaCounters.get(meta);
Histogram histogram = histograms.get(meta).get(dataEntry.getKey());
if (cnt != null && cnt > 1) {
Snapshot snapshot1 = histogram.getSnapshot();
snapshot.set_mean(snapshot1.getMean());
snapshot.set_p50(snapshot1.getMedian());
snapshot.set_p75(snapshot1.get75thPercentile());
snapshot.set_p95(snapshot1.get95thPercentile());
snapshot.set_p98(snapshot1.get98thPercentile());
snapshot.set_p99(snapshot1.get99thPercentile());
snapshot.set_p999(snapshot1.get999thPercentile());
snapshot.set_stddev(snapshot1.getStdDev());
snapshot.set_min(snapshot1.getMin());
snapshot.set_max(snapshot1.getMax());
if (MetricUtils.metricAccurateCal && metaType == MetaType.TOPOLOGY) {
snapshot.set_points(MetricUtils.longs2bytes(snapshot1.getValues()));
}
}
if (metaType != MetaType.TOPOLOGY || !MetricUtils.metricAccurateCal) {
snapshot.set_points(new byte[0]);
}
}
}
}
}
use of com.codahale.metrics.Histogram in project torodb by torodb.
the class ToroMetricRegistry method histogram.
/**
*
* @param name
* @param resetOnSnapshot This is usually true if you're using snapshots as a means of defining
* the window in which you want to calculate, say, the 99.9th percentile
* @return
*/
public Histogram histogram(MetricName name, boolean resetOnSnapshot) {
Reservoir reservoir;
if (resetOnSnapshot) {
reservoir = new HdrHistogramResetOnSnapshotReservoir();
} else {
reservoir = new HdrHistogramReservoir();
}
Histogram histogram = register(name, new Histogram(reservoir));
return histogram;
}
use of com.codahale.metrics.Histogram in project HikariCP by brettwooldridge.
the class TestMetrics method testMetricUsage.
@Test
public void testMetricUsage() throws SQLException {
assumeFalse(Os.isFamily(Os.FAMILY_WINDOWS));
MetricRegistry metricRegistry = new MetricRegistry();
HikariConfig config = newHikariConfig();
config.setMinimumIdle(1);
config.setMaximumPoolSize(1);
config.setMetricRegistry(metricRegistry);
config.setInitializationFailTimeout(0);
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
try (HikariDataSource ds = new HikariDataSource(config)) {
try (Connection connection = ds.getConnection()) {
UtilityElf.quietlySleep(250L);
}
Histogram histo = metricRegistry.getHistograms(new MetricFilter() {
/** {@inheritDoc} */
@Override
public boolean matches(String name, Metric metric) {
return name.equals(MetricRegistry.name("testMetricUsage", "pool", "Usage"));
}
}).values().iterator().next();
assertEquals(1, histo.getCount());
double seventyFifth = histo.getSnapshot().get75thPercentile();
assertTrue("Seventy-fith percentile less than 250ms: " + seventyFifth, seventyFifth >= 250.0);
}
}
Aggregations