com.codahale.metrics.Gauge类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中com.codahale.metrics.Gauge类的一些代码示例,展示了Gauge类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Gauge类的具体详情如下:
包路径:com.codahale.metrics.Gauge
类名称:Gauge

Gauge介绍

[英]A gauge metric is an instantaneous reading of a particular value. To instrument a queue's depth, for example:

final Queue<String> queue = new ConcurrentLinkedQueue<String>(); 
final Gauge<Integer> queueDepth = new Gauge<Integer>() { 
public Integer getValue() { 
return queue.size(); 
} 
};

[中]仪表度量是特定值的瞬时读数。要检测队列的深度,例如:

final Queue<String> queue = new ConcurrentLinkedQueue<String>(); 
final Gauge<Integer> queueDepth = new Gauge<Integer>() { 
public Integer getValue() { 
return queue.size(); 
} 
};

代码示例

代码示例来源:origin: azkaban/azkaban

public long getGaugeValue(final String name) {
  // Assume that the gauge value can be converted to type long.
  return (long) this.registry.getGauges().get(name).getValue();
 }
}

代码示例来源:origin: Alluxio/alluxio

private Map<String, Long> getMetricsInternal() {
 MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
 // Get all counters.
 Map<String, Counter> counters = metricRegistry.getCounters();
 // Only the gauge for cached blocks is retrieved here, other gauges are statistics of
 // free/used spaces, those statistics can be gotten via other REST apis.
 String blocksCachedProperty =
   MetricsSystem.getMetricName(DefaultBlockWorker.Metrics.BLOCKS_CACHED);
 @SuppressWarnings("unchecked") Gauge<Integer> blocksCached =
   (Gauge<Integer>) metricRegistry.getGauges().get(blocksCachedProperty);
 // Get values of the counters and gauges and put them into a metrics map.
 SortedMap<String, Long> metrics = new TreeMap<>();
 for (Map.Entry<String, Counter> counter : counters.entrySet()) {
  metrics.put(counter.getKey(), counter.getValue().getCount());
 }
 metrics.put(blocksCachedProperty, blocksCached.getValue().longValue());
 return metrics;
}

代码示例来源:origin: apache/incubator-gobblin

@Override
protected void reportInContext(MetricContext context,
                SortedMap<String, Gauge> gauges,
                SortedMap<String, Counter> counters,
                SortedMap<String, Histogram> histograms,
                SortedMap<String, Meter> meters,
                SortedMap<String, Timer> timers) {
 for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
  Gauge gauge = entry.getValue();
  if (gauge.getValue() instanceof Long ||
    gauge.getValue() instanceof Integer ||
    gauge.getValue() instanceof Short ||
    gauge.getValue() instanceof Byte)
   reportValue(context, entry.getKey(), ((Number) gauge.getValue()).longValue());
 }
 for (Map.Entry<String, Counter> entry : counters.entrySet()) {
  reportCount(context, entry.getKey(), entry.getValue().getCount());
 }
 for (Map.Entry<String, Meter> entry : meters.entrySet()) {
  reportCount(context, entry.getKey(), entry.getValue().getCount());
 }
 for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
  reportCount(context, entry.getKey(), entry.getValue().getCount());
 }
 for (Map.Entry<String, Timer> entry : timers.entrySet()) {
  reportCount(context, entry.getKey(), entry.getValue().getCount());
 }
}

代码示例来源:origin: aol/micro-server

@Test
public void queriesIntervalCounterInc() {
  catcher.requestStart(new AddQuery(
      RequestData.builder()
          .correlationId(10l)
          .type("test")
          .build()));
  assertThat(registry.getGauges().size(), equalTo(2));
  assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-started-interval-count").getValue(), equalTo(1l));
  assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-started-test-interval-count").getValue(), equalTo(1l));
}

代码示例来源:origin: Alluxio/alluxio

.get(MetricsSystem.getMetricName(DefaultBlockMaster.Metrics.CAPACITY_TOTAL)).getValue();
Long masterCapacityUsed = (Long) mr.getGauges()
  .get(MetricsSystem.getMetricName(DefaultBlockMaster.Metrics.CAPACITY_USED)).getValue();
  (Long) mr.getGauges().get(MetricsSystem.getMetricName(MasterMetrics.UFS_CAPACITY_TOTAL))
    .getValue();
    .getValue();
  .get(MetricsSystem.getClusterMetricName(ClientMetrics.BYTES_READ_LOCAL)).getValue();
Long bytesReadRemote = (Long) mr.getGauges()
  .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_READ_ALLUXIO)).getValue();
Long bytesReadUfs = (Long) mr.getGauges()
  .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_READ_UFS_ALL)).getValue();
response.setTotalBytesReadLocal(FormatUtils.getSizeFromBytes(bytesReadLocal))
  .setTotalBytesReadRemote(FormatUtils.getSizeFromBytes(bytesReadRemote))
  .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_WRITTEN_ALLUXIO)).getValue();
Long bytesWrittenUfs = (Long) mr.getGauges()
  .get(MetricsSystem.getClusterMetricName(WorkerMetrics.BYTES_WRITTEN_UFS_ALL)).getValue();
response.setTotalBytesWrittenAlluxio(FormatUtils.getSizeFromBytes(bytesWrittenAlluxio))
  .setTotalBytesWrittenUfs(FormatUtils.getSizeFromBytes(bytesWrittenUfs));
  .getValue();
  .getValue();
  .getValue();
response

代码示例来源:origin: pippo-java/pippo

protected void writeGauges(SortedMap<String, Gauge> gauges, BufferedWriter writer) throws IOException {
  writeBanner("Gauges", writer);
  for (String key : gauges.keySet()) {
    writer.write(key + " = " + gauges.get(key).getValue());
    writer.newLine();
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

Map.Entry<String, Gauge> dropwizardEntry = registry.getMetricRegistry().getGauges().entrySet().iterator().next();
assertEquals("test", stagemonitorEntry.getKey().getName());
assertEquals(1,
    stagemonitorEntry.getValue().getValue());
    dropwizardEntry.getValue().getValue());
assertEquals(0, registry.getMetricRegistry().getGauges().size());

代码示例来源:origin: Graylog2/graylog2-server

@GET
  @Timed
  @RequiresPermissions(RestPermissions.THROUGHPUT_READ)
  @ApiOperation(value = "Current throughput of this node in messages per second")
  @Produces(MediaType.APPLICATION_JSON)
  public Throughput total() {
    final SortedMap<String, Gauge> gauges = metricRegistry.getGauges(MetricUtils.filterSingleMetric(
        GlobalMetricNames.OUTPUT_THROUGHPUT_RATE));
    final Gauge gauge = Iterables.getOnlyElement(gauges.values(), null);
    if (gauge == null || !(gauge.getValue() instanceof Number)) {
      return Throughput.create(0);
    } else {
      return Throughput.create(((Number) gauge.getValue()).longValue());
    }
  }
}

代码示例来源:origin: alibaba/jstorm

/**
   * {@inheritDoc}
   */
  @Override
  public Object getValue(Integer window) {
    return this.gauge.getValue();
  }
}

代码示例来源:origin: apache/incubator-gobblin

@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);
}

代码示例来源:origin: jooby-project/jooby

@SuppressWarnings("rawtypes")
private static Map<String, Object> gauges(final SortedMap<String, Gauge> gauges) {
 Map<String, Object> result = new TreeMap<>();
 gauges.forEach((name, gauge) -> {
  try {
   result.put(name, gauge.getValue());
  } catch (Exception ex) {
   result.put(name, ex.toString());
  }
 });
 return result;
}

代码示例来源:origin: Alluxio/alluxio

private Map<String, Long> getMetricsInternal() {
 MetricRegistry metricRegistry = MetricsSystem.METRIC_REGISTRY;
 // Get all counters.
 Map<String, Counter> counters = metricRegistry.getCounters();
 // Only the gauge for pinned files is retrieved here, other gauges are statistics of
 // free/used
 // spaces, those statistics can be gotten via other REST apis.
 String filesPinnedProperty = MetricsSystem.getMetricName(MasterMetrics.FILES_PINNED);
 @SuppressWarnings("unchecked") Gauge<Integer> filesPinned =
   (Gauge<Integer>) MetricsSystem.METRIC_REGISTRY.getGauges().get(filesPinnedProperty);
 // Get values of the counters and gauges and put them into a metrics map.
 SortedMap<String, Long> metrics = new TreeMap<>();
 for (Map.Entry<String, Counter> counter : counters.entrySet()) {
  metrics.put(counter.getKey(), counter.getValue().getCount());
 }
 metrics.put(filesPinnedProperty, filesPinned.getValue().longValue());
 return metrics;
}

代码示例来源:origin: Alluxio/alluxio

private static List<Metric> allMetrics(MetricsSystem.InstanceType instanceType) {
 List<Metric> metrics = new ArrayList<>();
 for (Entry<String, Gauge> entry : METRIC_REGISTRY.getGauges().entrySet()) {
  if (entry.getKey().startsWith(instanceType.toString())) {
   Object value = entry.getValue().getValue();
   if (!(value instanceof Number)) {
    LOG.warn(
      "The value of metric {} of type {} is not sent to metrics master,"
        + " only metrics value of number can be collected",
      entry.getKey(), entry.getValue().getClass().getSimpleName());
    continue;
   }
   metrics.add(Metric.from(entry.getKey(), ((Number) value).longValue()));
  }
 }
 for (Entry<String, Counter> entry : METRIC_REGISTRY.getCounters().entrySet()) {
  metrics.add(Metric.from(entry.getKey(), entry.getValue().getCount()));
 }
 for (Entry<String, Meter> entry : METRIC_REGISTRY.getMeters().entrySet()) {
  // TODO(yupeng): From Meter's implementation, getOneMinuteRate can only report at rate of at
  // least seconds. if the client's duration is too short (i.e. < 1s), then getOneMinuteRate
  // would return 0
  metrics.add(Metric.from(entry.getKey(), entry.getValue().getOneMinuteRate()));
 }
 for (Entry<String, Timer> entry : METRIC_REGISTRY.getTimers().entrySet()) {
  metrics.add(Metric.from(entry.getKey(), entry.getValue().getCount()));
 }
 return metrics;
}

代码示例来源:origin: aol/micro-server

@Test
public void queriesIntervalCounterDec() {
  catcher.requestComplete(new RemoveQuery(
      RequestData.builder()
          .correlationId(10l)
          .type("test")
          .build()));
  assertThat(registry.getGauges().size(), equalTo(2));
  assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-interval-count").getValue(),
      equalTo(1l));
  assertThat(registry.getGauges().get(this.config.getPrefix() + ".requests-completed-test-interval-count").getValue(),
      equalTo(1l));
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public T getValue() {
 return this.gauge.getValue();
}

代码示例来源:origin: Alluxio/alluxio

private Object getGauge(String name) {
  return MetricsSystem.METRIC_REGISTRY.getGauges().get(MetricsSystem.getMetricName(name))
    .getValue();
 }
}

代码示例来源:origin: Alluxio/alluxio

@Override
 public void getMetrics(GetMetricsPOptions options,
   StreamObserver<GetMetricsPResponse> responseObserver) {
  RpcUtils.call(LOG, (RpcUtils.RpcCallableThrowsIOException<GetMetricsPResponse>) () -> {

   MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
   Map<String, alluxio.grpc.MetricValue> metricsMap = new HashMap<>();

   for (Map.Entry<String, Counter> entry : mr.getCounters().entrySet()) {
    metricsMap.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), alluxio.grpc.MetricValue
      .newBuilder().setLongValue(entry.getValue().getCount()).build());
   }

   for (Map.Entry<String, Gauge> entry : mr.getGauges().entrySet()) {
    Object value = entry.getValue().getValue();
    if (value instanceof Integer) {
     metricsMap.put(entry.getKey(), alluxio.grpc.MetricValue.newBuilder()
       .setLongValue(Long.valueOf((Integer) value)).build());
    } else if (value instanceof Long) {
     metricsMap.put(entry.getKey(), alluxio.grpc.MetricValue.newBuilder()
       .setLongValue(Long.valueOf((Long) value)).build());
    } else if (value instanceof Double) {
     metricsMap.put(entry.getKey(),
       alluxio.grpc.MetricValue.newBuilder().setDoubleValue((Double) value).build());
    }
   }
   return GetMetricsPResponse.newBuilder().putAllMetrics(metricsMap).build();
  }, "getConfiguration", "options=%s", responseObserver, options);
 }
}

代码示例来源:origin: stagemonitor/stagemonitor

private Double getDoubleFromGauge(Gauge gauge) {
  if (gauge.getValue() instanceof Number) {
    return ((Number) gauge.getValue()).doubleValue();
  } else if (gauge.getValue() instanceof Boolean) {
    return ((Boolean) gauge.getValue()) ? 1.0 : 0;
  } else {
    return -1d;
  }
}

代码示例来源:origin: Alluxio/alluxio

private Object getGauge(String name) {
  return MetricsSystem.METRIC_REGISTRY.getGauges().get(MetricsSystem.getMetricName(name))
    .getValue();
 }
}

代码示例来源:origin: apache/kylin

Iterator<Entry<String, Gauge>> gaugeIterator = dropwizardGauges.entrySet().iterator();
while (gaugeIterator.hasNext()) {
  @SuppressWarnings("rawtypes")
  Entry<String, Gauge> gauge = gaugeIterator.next();
  final MetricsInfo info = Interns.info(gauge.getKey(), EMPTY_STRING);
  final Object o = gauge.getValue().getValue();
Iterator<Entry<String, Counter>> counterIterator = dropwizardCounters.entrySet().iterator();
while (counterIterator.hasNext()) {
  Entry<String, Counter> counter = counterIterator.next();
Iterator<Entry<String, Histogram>> histogramIterator = dropwizardHistograms.entrySet().iterator();
while (histogramIterator.hasNext()) {
  final Entry<String, Histogram> entry = histogramIterator.next();

相关文章

Gauge类方法