@Inject public BlockingBatchedESOutput(MetricRegistry metricRegistry, Messages messages, org.graylog2.Configuration serverConfiguration, Journal journal) { super(metricRegistry, messages, journal); this.maxBufferSize = serverConfiguration.getOutputBatchSize(); outputFlushInterval = serverConfiguration.getOutputFlushInterval(); this.processTime = metricRegistry.timer(name(this.getClass(), "processTime")); this.batchSize = metricRegistry.histogram(name(this.getClass(), "batchSize")); this.bufferFlushes = metricRegistry.meter(name(this.getClass(), "bufferFlushes")); this.bufferFlushFailures = metricRegistry.meter(name(this.getClass(), "bufferFlushFailures")); this.bufferFlushesRequested = metricRegistry.meter(name(this.getClass(), "bufferFlushesRequested")); buffer = new ArrayList<>(maxBufferSize); }
public static <T> SimpleGauge<T> gauge( T initialValue, String name, String topologyId, String componentId, Integer taskId, Integer port) { String metricName = metricName(name, topologyId, componentId, taskId, port); if (REGISTRY.getGauges().containsKey(metricName)) { return (SimpleGauge) REGISTRY.getGauges().get(metricName); } else { return REGISTRY.register(metricName, new SimpleGauge<>(initialValue)); } }
public DropwizardRowIngestionMeters() { this.metricRegistry = new MetricRegistry(); this.processed = metricRegistry.meter(PROCESSED); this.processedWithError = metricRegistry.meter(PROCESSED_WITH_ERROR); this.unparseable = metricRegistry.meter(UNPARSEABLE); this.thrownAway = metricRegistry.meter(THROWN_AWAY); }
@Test public void aGaugeAnnotatedMethodWithAbsoluteName() throws Exception { instance.doAThingWithAbsoluteName(); final Gauge metric = registry.getGauges().get(name("absoluteName")); assertThat("Guice creates a metric", metric, is(notNullValue())); assertThat("Guice creates a gauge with the given value", ((Gauge<String>) metric).getValue(), is("anotherThingWithAbsoluteName")); }
@Test public void aCounterAnnotatedMethodWithDefaultName() throws Exception { instance.doAnotherThing(); final Counter metric = registry.getCounters().get(name(InstrumentedWithCounter.class, "doAnotherThing", COUNTER_SUFFIX_MONOTONIC)); assertThat("Guice creates a metric", metric, is(notNullValue())); assertThat("Guice creates a counter with the given value", metric.getCount(), is((long) 1)); }
@Test public void aMeteredAnnotatedMethod() throws Exception { meteredInstance.doAThing(); final Meter metric = registry.getMeters().get(name(InstrumentedWithMetered.class, "things")); assertThat("Guice creates a metric", metric, is(notNullValue())); assertThat("Guice creates a meter which gets marked", metric.getCount(), is(1L)); } }
@Test public void aMethodAnnotatedWithBothATimerAndAnExceptionCounter() throws Exception { final Timer timedMetric = registry.getTimers().get(name(InstrumentedWithExceptionMetered.class, "timedAndException", TIMED_SUFFIX)); final Meter errorMetric = registry.getMeters().get(name(InstrumentedWithExceptionMetered.class, "timedAndException", DEFAULT_NAME_SUFFIX)); is(notNullValue())); is(instanceOf(Timer.class))); timedMetric.getCount(), is(0L)); timedMetric.getCount(), is(1L)); timedMetric.getCount(), is(2L));
@Test public void aTimedAnnotatedMethod() throws Exception { instance.doAThing(); final Timer metric = registry.getTimers().get(name(InstrumentedWithTimed.class, "things")); assertMetricSetup(metric); assertThat("Guice creates a timer which records invocation length", metric.getCount(), is(1L)); assertThat("Guice creates a timer which records invocation duration without underestimating too much", metric.getSnapshot().getMax(), is(greaterThan(NANOSECONDS.convert(5, MILLISECONDS)))); assertThat("Guice creates a timer which records invocation duration without overestimating too much", metric.getSnapshot().getMax(), is(lessThan(NANOSECONDS.convert(15, MILLISECONDS)))); }
@Test public void timer() { MetricRegistry codaRegistry = new MetricRegistry(); MetricsRegistry r = new MetricsRegistry(clock, codaRegistry); r.timer("foo").record(1, TimeUnit.MILLISECONDS); Assertions.assertEquals(1, codaRegistry.getTimers().get("foo").getCount()); }
/** * Register Dropwizard health checks. * * @param pool the pool to register health checks for * @param hikariConfig the pool configuration * @param registry the HealthCheckRegistry into which checks will be registered */ public static void registerHealthChecks(final HikariPool pool, final HikariConfig hikariConfig, final HealthCheckRegistry registry) { final Properties healthCheckProperties = hikariConfig.getHealthCheckProperties(); final MetricRegistry metricRegistry = (MetricRegistry) hikariConfig.getMetricRegistry(); final long checkTimeoutMs = Long.parseLong(healthCheckProperties.getProperty("connectivityCheckTimeoutMs", String.valueOf(hikariConfig.getConnectionTimeout()))); registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "ConnectivityCheck"), new ConnectivityHealthCheck(pool, checkTimeoutMs)); final long expected99thPercentile = Long.parseLong(healthCheckProperties.getProperty("expected99thPercentileMs", "0")); if (metricRegistry != null && expected99thPercentile > 0) { SortedMap<String,Timer> timers = metricRegistry.getTimers((name, metric) -> name.equals(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Wait"))); if (!timers.isEmpty()) { final Timer timer = timers.entrySet().iterator().next().getValue(); registry.register(MetricRegistry.name(hikariConfig.getPoolName(), "pool", "Connection99Percent"), new Connection99Percent(timer, expected99thPercentile)); } } }
@Override public void doRun() { final SortedMap<String, ? extends Counting> counters = metricRegistry.getCounters( filterSingleMetric(GlobalMetricNames.OUTPUT_THROUGHPUT) ); final SortedMap<String, ? extends Counting> inputCounters = metricRegistry.getCounters( filterSingleMetric(GlobalMetricNames.INPUT_THROUGHPUT) ); final SortedMap<String, ? extends Counting> streamMeters = metricRegistry.getMeters(streamMetricFilter); final Iterable<Map.Entry<String, ? extends Counting>> entries = Iterables.concat(counters.entrySet(), inputCounters.entrySet(), streamMeters.entrySet()); final String rateName = name(metricName, GlobalMetricNames.RATE_SUFFIX); if (!metricRegistry.getMetrics().containsKey(rateName)) { try { log.debug("Registering derived, per-second metric {}", rateName); metricRegistry.register(rateName, new Gauge<Double>() { @Override public Double getValue() {
@Test(dependsOnMethods = "testQueueStats") public void testRegisterAll() { MetricRegistry metricRegistry = new MetricRegistry(); this.boundedBlockingRecordQueue.stats().get().registerAll(metricRegistry, METRIC_NAME_PREFIX); @SuppressWarnings("rawtypes") Map<String, Gauge> gauges = metricRegistry.getGauges(); Assert.assertEquals(gauges.size(), 2); Assert.assertEquals(gauges .get(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.QUEUE_SIZE)).getValue(), 2); Assert.assertEquals(gauges .get(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.FILL_RATIO)).getValue(), 1d); Assert.assertEquals(metricRegistry.getMeters().size(), 2); Assert.assertEquals(metricRegistry .meter(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.GET_ATTEMPT_RATE)) .getCount(), 7); Assert.assertEquals(metricRegistry .meter(MetricRegistry.name(METRIC_NAME_PREFIX, BoundedBlockingRecordQueue.QueueStats.PUT_ATTEMPT_RATE)) .getCount(), 8); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { String timerName = invocation.getMethod().getAnnotation(Timed.class).value(); if (timerName.isEmpty()) { timerName = MetricRegistry.name(invocation.getThis().getClass().getSuperclass(), invocation.getMethod().getName()); } Timer.Context timerContext = metricsServiceProvider .get() .getMetricRegistry() .timer(timerName) .time(); try { return invocation.proceed(); } finally { timerContext.stop(); } }
private Timer registerHdrTimer(MetricRegistry metricRegistry, final String metricName) { Timer timer; try { timer = metricRegistry.register(metricName, new HdrTimer(1, MINUTES, 1)); } catch (IllegalArgumentException e) { final SortedMap<String, Timer> timers = metricRegistry.getTimers((name, metric) -> metricName.equals(name)); timer = Iterables.getOnlyElement(timers.values()); } return timer; }
@Override public Status ackMessage(String queueName, UUID queueMessageId ) { if( logger.isTraceEnabled() ){ logger.trace("Acking message for queue {} with id: {}", queueName, queueMessageId); } Timer.Context timer = metricsService.getMetricRegistry().timer( MetricsService.ACK_TIME_TOTAL ).time(); try { QueueAckRequest message = new QueueAckRequest( queueName, queueMessageId ); return sendMessageToLocalRouters( message ); } finally { timer.close(); } }
private void addGaugeInternal(String name, Gauge gauge) { try { gaugesLock.lock(); gauges.put(name, gauge); // Metrics throws an Exception if we don't do this when the key already exists if (metricRegistry.getGauges().containsKey(name)) { LOGGER.warn("A Gauge with name [" + name + "] already exists. " + " The old gauge will be overwritten, but this is not recommended"); metricRegistry.remove(name); } metricRegistry.register(name, gauge); } finally { gaugesLock.unlock(); } }