Search in sources :

Example 1 with Gauge

use of com.yammer.metrics.core.Gauge in project java by wavefrontHQ.

the class WavefrontYammerMetricsReporterTest method testPlainGauge.

@Test(timeout = 1000)
public void testPlainGauge() throws Exception {
    Gauge gauge = metricsRegistry.newGauge(WavefrontYammerMetricsReporterTest.class, "mygauge", new Gauge<Double>() {

        @Override
        public Double value() {
            return 13.0;
        }
    });
    wavefrontYammerMetricsReporter.run();
    assertThat(receiveFromSocket(1, fromMetrics), contains(equalTo("\"mygauge\" 13.0 1485224035")));
}
Also used : Gauge(com.yammer.metrics.core.Gauge) Test(org.junit.Test)

Example 2 with Gauge

use of com.yammer.metrics.core.Gauge in project java by wavefrontHQ.

the class QueueController method run.

@Override
public void run() {
    // 1. grab current queue sizes (tasks count) and report to EntityProperties
    int backlog = processorTasks.stream().mapToInt(x -> x.getTaskQueue().size()).sum();
    queueSize.set(backlog);
    if (backlogSizeSink != null) {
        backlogSizeSink.accept(backlog);
    }
    // 2. grab queue sizes (points/etc count)
    Long totalWeight = 0L;
    for (QueueProcessor<T> task : processorTasks) {
        TaskQueue<T> taskQueue = task.getTaskQueue();
        // noinspection ConstantConditions
        totalWeight = taskQueue.weight() == null ? null : taskQueue.weight() + totalWeight;
        if (totalWeight == null)
            break;
    }
    if (totalWeight != null) {
        if (currentWeight == null) {
            currentWeight = new AtomicLong();
            Metrics.newGauge(new TaggedMetricName("buffer", handlerKey.getEntityType() + "-count", "port", handlerKey.getHandle()), new Gauge<Long>() {

                @Override
                public Long value() {
                    return currentWeight.get();
                }
            });
        }
        currentWeight.set(totalWeight);
    }
    // 3. adjust timing
    adjustTimingFactors(processorTasks);
    // 4. print stats when there's backlog
    if (backlog > 0) {
        printQueueStats();
    } else if (outputQueueingStats) {
        outputQueueingStats = false;
        logger.info("[" + handlerKey.getHandle() + "] " + handlerKey.getEntityType() + " backlog has been cleared!");
    }
}
Also used : TaggedMetricName(com.wavefront.common.TaggedMetricName) Managed(com.wavefront.common.Managed) DataSubmissionTask(com.wavefront.agent.data.DataSubmissionTask) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) Timer(java.util.Timer) Logger(java.util.logging.Logger) RateLimiter(com.google.common.util.concurrent.RateLimiter) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Pair(com.wavefront.common.Pair) Gauge(com.yammer.metrics.core.Gauge) HandlerKey(com.wavefront.agent.handlers.HandlerKey) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Metrics(com.yammer.metrics.Metrics) Comparator(java.util.Comparator) TimerTask(java.util.TimerTask) Nullable(javax.annotation.Nullable) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TaggedMetricName(com.wavefront.common.TaggedMetricName)

Aggregations

Gauge (com.yammer.metrics.core.Gauge)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 DataSubmissionTask (com.wavefront.agent.data.DataSubmissionTask)1 HandlerKey (com.wavefront.agent.handlers.HandlerKey)1 Managed (com.wavefront.common.Managed)1 Pair (com.wavefront.common.Pair)1 TaggedMetricName (com.wavefront.common.TaggedMetricName)1 Metrics (com.yammer.metrics.Metrics)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1 Supplier (java.util.function.Supplier)1 Logger (java.util.logging.Logger)1