com.yammer.metrics.core.Gauge Java Examples

The following examples show how to use com.yammer.metrics.core.Gauge. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileCacheMetrics.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public FileCacheMetrics()
{
    hits = Metrics.newMeter(factory.createMetricName("Hits"), "hits", TimeUnit.SECONDS);
    requests = Metrics.newMeter(factory.createMetricName("Requests"), "requests", TimeUnit.SECONDS);
    hitRate = Metrics.newGauge(factory.createMetricName("HitRate"), new RatioGauge()
    {
        protected double getNumerator()
        {
            return hits.count();
        }

        protected double getDenominator()
        {
            return requests.count();
        }
    });
    size = Metrics.newGauge(factory.createMetricName("Size"), new Gauge<Long>()
    {
        public Long value()
        {
            return FileCacheService.instance.sizeInBytes();
        }
    });
}
 
Example #2
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
private static Metric getCumulativeCounter(MetricsRegistry metricsRegistry,
                                           MetricMetadata metricMetadata) {
    MetricName counterCallbackName = new MetricName(YammerExample.class, "yammer.test.cumulativeCounter");
    Metric cumulativeCounter = SfUtil.cumulativeCounter(
            metricsRegistry,
            counterCallbackName,
            metricMetadata,
            new Gauge<Long>() {

                private long i = 0;

                @Override
                public Long value() {
                    return i++;
                }

            });

    metricMetadata.forMetric(cumulativeCounter)
            .withSourceName(SIGNAL_FX)
            .withDimension(LIBRARY_VERSION, YAMMER);

    return cumulativeCounter;
}
 
Example #3
Source File: CommitLogMetrics.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public CommitLogMetrics(final AbstractCommitLogService service, final CommitLogSegmentManager allocator)
{
    completedTasks = Metrics.newGauge(factory.createMetricName("CompletedTasks"), new Gauge<Long>()
    {
        public Long value()
        {
            return service.getCompletedTasks();
        }
    });
    pendingTasks = Metrics.newGauge(factory.createMetricName("PendingTasks"), new Gauge<Long>()
    {
        public Long value()
        {
            return service.getPendingTasks();
        }
    });
    totalCommitLogSize = Metrics.newGauge(factory.createMetricName("TotalCommitLogSize"), new Gauge<Long>()
    {
        public Long value()
        {
            return allocator.bytesUsed();
        }
    });
    waitingOnSegmentAllocation = Metrics.newTimer(factory.createMetricName("WaitingOnSegmentAllocation"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
    waitingOnCommit = Metrics.newTimer(factory.createMetricName("WaitingOnCommit"), TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
}
 
Example #4
Source File: ScheduledReporterTest.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
private Set<Entry<MetricName, Metric>> set(List<Metric> metrics) {
  final Map<MetricName, Metric> map = new HashMap<MetricName, Metric>();
  for (Metric metric : metrics) {
    String name = null;
    if (metric instanceof Gauge) {
      name = "gauge";
    } else if (metric instanceof Counter) {
      name = "counter";
    } else if (metric instanceof Histogram) {
      name = "histogram";
    } else if (metric instanceof Meter) {
      name = "meter";
    } else if (metric instanceof Timer) {
      name = "timer";
    }
    map.put(new MetricName(System.class, name), metric);
  }
  return map.entrySet();
}
 
Example #5
Source File: DeepPagingCache.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
public DeepPagingCache(long maxEntriesForDeepPaging) {
  _hits = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, HIT), HIT, TimeUnit.SECONDS);
  _misses = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, MISS), MISS, TimeUnit.SECONDS);
  _evictions = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, EVICTION), EVICTION,
      TimeUnit.SECONDS);
  _lruCache = new ConcurrentLinkedHashMap.Builder<DeepPageKeyPlusPosition, DeepPageContainer>()
      .maximumWeightedCapacity(maxEntriesForDeepPaging)
      .listener(new EvictionListener<DeepPageKeyPlusPosition, DeepPageContainer>() {
        @Override
        public void onEviction(DeepPageKeyPlusPosition key, DeepPageContainer value) {
          _positionCache.remove(key);
          _evictions.mark();
        }
      }).build();
  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, DEEP_PAGING_CACHE, SIZE), new Gauge<Long>() {
    @Override
    public Long value() {
      return _lruCache.weightedSize();
    }
  });
  _positionCache = new ConcurrentSkipListMap<DeepPageKeyPlusPosition, DeepPageContainer>();
}
 
Example #6
Source File: CQLMetrics.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public CQLMetrics()
{
    regularStatementsExecuted = Metrics.newCounter(factory.createMetricName("RegularStatementsExecuted"));
    preparedStatementsExecuted = Metrics.newCounter(factory.createMetricName("PreparedStatementsExecuted"));
    preparedStatementsEvicted = Metrics.newCounter(factory.createMetricName("PreparedStatementsEvicted"));

    preparedStatementsCount = Metrics.newGauge(factory.createMetricName("PreparedStatementsCount"), new Gauge<Integer>()
    {
        public Integer value()
        {
            return QueryProcessor.preparedStatementsCount();
        }
    });
    preparedStatementsRatio = Metrics.newGauge(factory.createMetricName("PreparedStatementsRatio"), new RatioGauge()
    {
        public double getNumerator()
        {
            return preparedStatementsExecuted.count();
        }

        public double getDenominator()
        {
            return regularStatementsExecuted.count() + preparedStatementsExecuted.count();
        }
    });
}
 
Example #7
Source File: ClientMetrics.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void addCounter(String name, final Callable<Integer> provider)
{
    Metrics.newGauge(factory.createMetricName(name), new Gauge<Integer>()
    {
        public Integer value()
        {
            try
            {
                return provider.call();
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
        }
    });
}
 
Example #8
Source File: FilterMetricPredicateTest.java    From kafka-graphite with Apache License 2.0 6 votes vote down vote up
@Test
public void keepGaugesIfTheyThrowRuntimeExceptions() throws Exception {
    MetricPredicate predicate = new FilterMetricPredicate();

    MetricName metricName = new MetricName("test", "test", "delete", "scope", "mBeanName");

    Metric gauge = Metrics.newGauge(metricName, new Gauge<Long>() {
        @Override
        public Long value() {
            throw new RuntimeException("catch me if you can");
        }
    });

    assertTrue(predicate.matches(metricName, gauge));

    assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricName));
    assertEquals(Metrics.defaultRegistry().allMetrics().get(metricName), gauge);
}
 
Example #9
Source File: GroupMetrics.java    From kafka-metrics with Apache License 2.0 6 votes vote down vote up
public T get(String group, TopicPartition tp) {
    Map<TopicPartition, T> metrics = data.get(group);
    if (metrics == null) {
        metrics = new HashMap<>();
        data.put(group, metrics);
    }
    T metric = metrics.get(tp);
    if (metric == null) {
        try {
            metric = cls.newInstance();
            if (metric instanceof Gauge) {
                registry.newGauge(NewName(group, tp), (Gauge)metric);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        metrics.put(tp, metric);
    }
    return metric;
}
 
Example #10
Source File: SharedMergeScheduler.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public SharedMergeScheduler(int threads, long smallMergeThreshold) {
  MetricName mergeSmallQueueDepth = new MetricName(ORG_APACHE_BLUR, LUCENE, SMALL_QUEUE_DEPTH);
  MetricName mergeSmallQueueDepthInBytes = new MetricName(ORG_APACHE_BLUR, LUCENE, SMALL_QUEUE_DEPTH_IN_BYTES);
  MetricName mergeLargeQueueDepth = new MetricName(ORG_APACHE_BLUR, LUCENE, LARGE_QUEUE_DEPTH);
  MetricName mergeLargeQueueDepthInBytes = new MetricName(ORG_APACHE_BLUR, LUCENE, LARGE_QUEUE_DEPTH_IN_BYTES);

  _smallMergeThreshold = smallMergeThreshold;
  _smallMergeService = Executors.newThreadPool(SHARED_MERGE_SCHEDULER_PREFIX + "-small", threads, false);
  _largeMergeService = Executors.newThreadPool(SHARED_MERGE_SCHEDULER_PREFIX + "-large", threads, false);
  for (int i = 0; i < threads; i++) {
    _smallMergeService.submit(getMergerRunnable(_smallMergeQueue));
    _largeMergeService.submit(getMergerRunnable(_largeMergeQueue));
  }

  Metrics.newGauge(mergeSmallQueueDepth, new Gauge<Long>() {
    @Override
    public Long value() {
      return (long) _smallMergeQueue.size();
    }
  });
  Metrics.newGauge(mergeSmallQueueDepthInBytes, new Gauge<Long>() {
    @Override
    public Long value() {
      return getSizeInBytes(_smallMergeQueue);
    }
  });
  Metrics.newGauge(mergeLargeQueueDepth, new Gauge<Long>() {
    @Override
    public Long value() {
      return (long) _largeMergeQueue.size();
    }
  });
  Metrics.newGauge(mergeLargeQueueDepthInBytes, new Gauge<Long>() {
    @Override
    public Long value() {
      return getSizeInBytes(_largeMergeQueue);
    }
  });
}
 
Example #11
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
@Test
public void isTaggedTest() {
  registry.add(new MetricName("kafka.common", "AppInfo", "Version", null, "kafka.common:type=AppInfo,name=Version"),
      new Gauge<String>() {
        public String value() {
          return "0.8.2";
        }
      });
  assertTrue(((StatsDReporter) reporter).isTagged(registry.allMetrics()));
}
 
Example #12
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
@Test
public final void longGauge() throws Exception {
  final long value = 0xdeadbeef;
  addMetricAndRunReporter(
      new Callable<Gauge<Object>>() {
        @Override
        public Gauge<Object> call() throws Exception {
          return createGauge(value);
        }
      });
  verifySend(value);
}
 
Example #13
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
@Test
public void stringGauge() throws Exception {
  final String value = "The Metric";
  addMetricAndRunReporter(
      new Callable<Gauge<Object>>() {
        @Override
        public Gauge<Object> call() throws Exception {
          return createGauge(value);
        }
      });
  verify(statsD, never()).gauge(Matchers.anyString(), Matchers.anyDouble());
}
 
Example #14
Source File: StatsDReporterTest.java    From kafka-statsd-metrics2 with Apache License 2.0 5 votes vote down vote up
static Gauge<Object> createGauge(Object value) throws Exception {
  @SuppressWarnings("unchecked")
  final Gauge<Object> mock = mock(Gauge.class);
  when(mock.value()).thenReturn(value);
  return configureMatcher(mock, doAnswer(new MetricsProcessorAction() {
    @Override
    void delegateToProcessor(MetricProcessor<Object> processor, MetricName name, Object context) throws Exception {
      processor.processGauge(name, mock, context);
    }
  }));
}
 
Example #15
Source File: KafkaTimelineMetricsReporter.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Override
public void processGauge(MetricName name, Gauge<?> gauge, Context context) throws Exception {
  final long currentTimeMillis = System.currentTimeMillis();
  final String sanitizedName = sanitizeName(name);

  try {
    if (!isExcludedMetric(sanitizedName)) {
      cacheSanitizedTimelineMetric(currentTimeMillis, sanitizedName, "", Double.parseDouble(String.valueOf(gauge.value())));
      populateMetricsList(context, MetricType.GAUGE, sanitizedName);
    }
  } catch (NumberFormatException ex) {
    LOG.debug(ex.getMessage());
  }
}
 
Example #16
Source File: ShardServerEventHandler.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public ShardServerEventHandler() {
  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections"), new Gauge<Long>() {
    @Override
    public Long value() {
      return null;
    }
  });
  _connectionMeter = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections/s"), "Connections/s",
      TimeUnit.SECONDS);
}
 
Example #17
Source File: ControllerServerEventHandler.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public ControllerServerEventHandler() {
  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections"), new Gauge<Long>() {
    @Override
    public Long value() {
      return null;
    }
  });
  _connectionMeter = Metrics.newMeter(new MetricName(ORG_APACHE_BLUR, BLUR, "Connections/s"), "Connections/s",
      TimeUnit.SECONDS);
}
 
Example #18
Source File: ByteArrayPrimitiveFactory.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
public ByteArrayPrimitiveFactory(BlurConfiguration configuration) {
  super(configuration);
  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, FST, SIZE), new Gauge<Long>() {
    @Override
    public Long value() {
      return _size.get();
    }
  });
}
 
Example #19
Source File: JSONReporter.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
@Override
public void processGauge(MetricName name, Gauge<?> gauge, Context context) throws Exception {
  MetricInfo info = context.getMetricInfo(name);
  long time = context.getTime();
  info.addNumber("timestamp", time);
  info.addNumber("value", getDouble(gauge.value()));
}
 
Example #20
Source File: YammerExample.java    From signalfx-java with Apache License 2.0 5 votes vote down vote up
private static Gauge getGauge(MetricsRegistry metricsRegistry, MetricMetadata metricMetadata) {
    Gauge gauge = metricsRegistry.newGauge(YammerExample.class, "yammer.test.gauge",
            new Gauge<Double>() {
                @Override
                public Double value() {
                    return Math.sin(System.currentTimeMillis() * 0.001 * 2 * Math.PI / 60);
                }
            });

    metricMetadata.forMetric(gauge)
            .withSourceName(SIGNAL_FX)
            .withDimension(LIBRARY_VERSION, YAMMER);
    return gauge;
}
 
Example #21
Source File: AggregatedLongGauge.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public void refresh() {
  long sum = 0;
  for (Gauge<T> gauge : _gauges) {
    sum += gauge.value().longValue();
  }
  _value = sum / _gauges.size();
}
 
Example #22
Source File: FilterMetricPredicateTest.java    From kafka-graphite with Apache License 2.0 5 votes vote down vote up
@Test
public void deleteGaugesIfTheyThrowNoSuchElementException() throws Exception {
    MetricPredicate predicate = new FilterMetricPredicate();

    MetricName metricNameToBeDeleted = new MetricName("test", "test", "delete", "scope", "mBeanName");

    Metric gaugeToBeDeleted = Metrics.newGauge(metricNameToBeDeleted, new Gauge<Long>() {
        @Override
        public Long value() {
            throw new NoSuchElementException("catch me if you can - i'm the the same as in KAFKA-1866");
        }
    });

    MetricName metricNameToStay = new MetricName("stay", "stay", "stay", "scope", "stay:mBeanName");
    Metric gaugeToStay = Metrics.newGauge(metricNameToStay, new Gauge<Long>() {
        @Override
        public Long value() {
            return 42L;
        }
    });


    assertFalse(predicate.matches(metricNameToBeDeleted, gaugeToBeDeleted));
    assertTrue(predicate.matches(metricNameToStay, gaugeToStay));


    assertFalse("The gauge should be deleted", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToBeDeleted));
    assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToStay));
    assertEquals(Metrics.defaultRegistry().allMetrics().get(metricNameToStay), gaugeToStay);
}
 
Example #23
Source File: ValidatingMetricProcessor.java    From kafka-graphite with Apache License 2.0 5 votes vote down vote up
@Override
public void processGauge(MetricName name, Gauge gauge, Object context) throws Exception {
    try {
        gauge.value();
    } catch (NoSuchElementException ex) {
        throw new InvalidGaugeException(String.format("%s.%s.%s", name.getGroup(), name.getType(), name.getName()), ex);
    }
}
 
Example #24
Source File: KafkaTimelineMetricsReporterTest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  @SuppressWarnings({ "rawtypes", "unchecked" })
  Gauge g = registry.newGauge(System.class, "gauge", gauge);
  Counter counter = registry.newCounter(System.class, "counter");
  Histogram histogram = registry.newHistogram(System.class, "histogram");
  Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS);
  Timer timer = registry.newTimer(System.class, "timer");
  list.add(g);
  list.add(counter);
  list.add(histogram);
  list.add(meter);
  list.add(timer);
  Properties properties = new Properties();
  properties.setProperty("zookeeper.connect", "localhost:2181");
  properties.setProperty("kafka.timeline.metrics.sendInterval", "5900");
  properties.setProperty("kafka.timeline.metrics.maxRowCacheSize", "10000");
  properties.setProperty("kafka.timeline.metrics.hosts", "localhost:6188");
  properties.setProperty("kafka.timeline.metrics.port", "6188");
  properties.setProperty("kafka.timeline.metrics.reporter.enabled", "true");
  properties.setProperty("external.kafka.metrics.exclude.prefix", "a.b.c");
  properties.setProperty("external.kafka.metrics.include.prefix", "a.b.c.d");
  properties.setProperty("external.kafka.metrics.include.regex", "a.b.c.*.f");
  properties.setProperty("kafka.timeline.metrics.instanceId", "cluster");
  properties.setProperty("kafka.timeline.metrics.set.instanceId", "false");
  props = new VerifiableProperties(properties);
}
 
Example #25
Source File: ScheduledReporterTest.java    From ambari-metrics with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
  Gauge g = registry.newGauge(System.class, "gauge", gauge);
  Counter counter = registry.newCounter(System.class, "counter");
  Histogram histogram = registry.newHistogram(System.class, "histogram");
  Meter meter = registry.newMeter(System.class, "meter", "empty", TimeUnit.MILLISECONDS);
  Timer timer = registry.newTimer(System.class, "timer");
  list.add(g);
  list.add(counter);
  list.add(histogram);
  list.add(meter);
  list.add(timer);
  reporter.start(200, TimeUnit.MILLISECONDS);
}
 
Example #26
Source File: YammerMetricProcessor.java    From cruise-control with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void processGauge(MetricName metricName, Gauge<?> gauge, Context context) {
  if (MetricsUtils.isInterested(metricName)) {
    LOG.trace("Processing metric {} of type Gauge.", metricName);
    if (!(gauge.value() instanceof Number)) {
      throw new IllegalStateException(String.format("The value of yammer metric %s is %s, which is not a number",
                                                    metricName, gauge.value()));
    }
    CruiseControlMetric ccm = MetricsUtils.toCruiseControlMetric(context.time(),
                                                                 context.brokerId(),
                                                                 metricName,
                                                                 ((Number) gauge.value()).doubleValue());
    context.reporter().sendCruiseControlMetric(ccm);
  }
}
 
Example #27
Source File: CacheMetrics.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Create metrics for given cache.
 *
 * @param type Type of Cache to identify metrics.
 * @param cache Cache to measure metrics
 */
public CacheMetrics(String type, final ICache cache)
{
    MetricNameFactory factory = new DefaultNameFactory("Cache", type);

    capacity = Metrics.newGauge(factory.createMetricName("Capacity"), new Gauge<Long>()
    {
        public Long value()
        {
            return cache.capacity();
        }
    });
    hits = Metrics.newMeter(factory.createMetricName("Hits"), "hits", TimeUnit.SECONDS);
    requests = Metrics.newMeter(factory.createMetricName("Requests"), "requests", TimeUnit.SECONDS);
    hitRate = Metrics.newGauge(factory.createMetricName("HitRate"), new RatioGauge()
    {
        protected double getNumerator()
        {
            return hits.count();
        }

        protected double getDenominator()
        {
            return requests.count();
        }
    });
    size = Metrics.newGauge(factory.createMetricName("Size"), new Gauge<Long>()
    {
        public Long value()
        {
            return cache.weightedSize();
        }
    });
    entries = Metrics.newGauge(factory.createMetricName("Entries"), new Gauge<Integer>()
    {
        public Integer value()
        {
            return cache.size();
        }
    });
}
 
Example #28
Source File: ValidationMetrics.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public Gauge<Double> buildGauge(final String key) {
  return new CurrentTimeMillisDeltaGaugeHours(key);
}
 
Example #29
Source File: ValidationMetrics.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public Gauge<Long> buildGauge(final String key) {
  return new StoredValueGauge(key);
}
 
Example #30
Source File: CustomReporter.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public void processGauge(final MetricName name, final Gauge<?> gauge,
        final PrintStream stream) {
    stream.printf(locale, "    value = %s\n", gauge.value());
}