当前位置: 首页>>代码示例>>Java>>正文


Java Meter类代码示例

本文整理汇总了Java中com.netflix.spectator.api.Meter的典型用法代码示例。如果您正苦于以下问题:Java Meter类的具体用法?Java Meter怎么用?Java Meter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Meter类属于com.netflix.spectator.api包,在下文中一共展示了Meter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: meterToKind

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Convert a Spectator Meter type into a Stackdriver Metric kind.
 */
public String meterToKind(Registry registry, Meter meter) {
  if (meter instanceof Counter) {
    return "CUMULATIVE";
  }

  if (registry.counters().anyMatch(m -> m.id().equals(meter.id()))) {
    return "CUMULATIVE";
  }

  if (meterIsTimer(registry, meter)) {
      return "CUMULATIVE";
  }

  return "GAUGE";
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:19,代码来源:MetricDescriptorCache.java

示例2: addMeterToTimeSeries

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Add a TimeSeries for each appropriate meter measurement.
 */
void addMeterToTimeSeries(
      Registry registry, Meter meter, List<TimeSeries> tsList) {
  Iterable<Measurement> measurements = meter.measure();
  boolean applyFilter = true;

  if (cache.meterIsTimer(registry, meter)) {
     measurements = transformTimerMeasurements(measurements);
     applyFilter = false;
  }
  for (Measurement measurement : measurements) {
    if (applyFilter && !measurementFilter.test(measurement)) {
      continue;
    }

    String descriptorType = cache.idToDescriptorType(measurement.id());
    tsList.add(measurementToTimeSeries(descriptorType, registry, meter, measurement));
  }
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:22,代码来源:StackdriverWriter.java

示例3: testAddMeasurementsToTimeSeries

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
@Test
public void testAddMeasurementsToTimeSeries() {
  DefaultRegistry testRegistry = new DefaultRegistry(clock);

  long millisA = TimeUnit.MILLISECONDS.convert(1472394975L, TimeUnit.SECONDS);
  long millisB = millisA + 987;
  String timeA = "2016-08-28T14:36:15.000000000Z";
  String timeB = "2016-08-28T14:36:15.987000000Z";
  Meter timerA = testRegistry.timer(idAXY);
  Meter timerB = testRegistry.timer(idBXY);
  Measurement measureAXY = new Measurement(idAXY, millisA, 1);
  Measurement measureBXY = new Measurement(idBXY, millisB, 20.1);

  descriptorRegistrySpy.addExtraTimeSeriesLabel(
      MetricDescriptorCache.INSTANCE_LABEL, INSTANCE_ID);
  
  Assert.assertEquals(
      makeTimeSeries(descriptorA, idAXY, 1, timeA),
      writer.measurementToTimeSeries(descriptorA.getType(), testRegistry, timerA, measureAXY));
  Assert.assertEquals(
      makeTimeSeries(descriptorB, idBXY, 20.1, timeB),
      writer.measurementToTimeSeries(descriptorB.getType(), testRegistry, timerB, measureBXY));
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:24,代码来源:StackdriverWriterTest.java

示例4: measure

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
private Iterable<Measurement> measure() {
  Map<Id, Measurement> measurements = new HashMap<>();
  Iterator<Meter> iter = queue.iterator();
  while (iter.hasNext()) {
    Meter meter = iter.next();
    if (meter.hasExpired()) {
      iter.remove();
    } else {
      for (Measurement m : meter.measure()) {
        Measurement prev = measurements.get(m.id());
        if (prev == null) {
          measurements.put(m.id(), m);
        } else {
          double v = prev.value() + m.value();
          measurements.put(prev.id(), new Measurement(prev.id(), prev.timestamp(), v));
        }
      }
    }
  }
  return measurements.values();
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:22,代码来源:PolledMeter.java

示例5: testEncodeCombinedRegistry

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
@Test
public void testEncodeCombinedRegistry() {
  // Multiple occurrences of measurements in the same registry
  // (confirm these are handled within the registry itself).
  Measurement measureBXY2 = new Measurement(idBXY, 5, 5.5);
  Meter meterB2 = new TestMeter("ignoreB", measureBXY2);

  DefaultRegistry registry = new DefaultRegistry(clock);
  registry.register(meterB);
  registry.register(meterB2);

  List<TaggedDataPoints> expectedTaggedDataPoints = Arrays.asList(
     new TaggedDataPoints(
           Arrays.asList(new BasicTag("tagA", "X"),
                         new BasicTag("tagB", "Y")),
           Arrays.asList(new DataPoint(clock.wallTime(), 50.5 + 5.5))));

  HashMap<String, MetricValues> expect = new HashMap<>();
  expect.put("idB", new MetricValues("Counter", expectedTaggedDataPoints));

  Assert.assertEquals(expect, controller.encodeRegistry(registry, allowAll));
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:23,代码来源:MetricsControllerTest.java

示例6: run

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
public static Collection<String> run() throws Exception {
  ManualClock clock = new ManualClock();
  clock.setWallTime(1234567890L);
  Registry r = new DefaultRegistry(clock);
  checkDistributionSummary(r);
  checkTimer(r);
  checkLongTaskTimer(r);
  checkCounter(r);
  checkGauge(r);

  // Histogram utilities
  checkBucketCounter(r, "age");
  checkBucketCounter(r, "ageBiasOld");
  checkBucketCounter(r, "latency");
  checkBucketCounter(r, "latencyBiasSlow");
  checkBucketCounter(r, "bytes");
  checkBucketCounter(r, "decimal");
  checkBucketDistributionSummary(r);
  checkBucketTimer(r);
  checkPercentileDistributionSummary(r);
  checkPercentileTimer(r);

  List<String> ms = new ArrayList<>();
  for (Meter meter : r) {
    for (Measurement m : meter.measure()) {
      ms.add(m.toString());
    }
  }
  Collections.sort(ms);
  return ms.stream()
      .filter(s -> !s.contains("non-deterministic"))
      .collect(Collectors.toList());
}
 
开发者ID:brharrington,项目名称:spectator-examples,代码行数:34,代码来源:Main.java

示例7: meterIsTimer

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Determine if meter is a Timer or not.
 */
public boolean meterIsTimer(Registry registry, Meter meter) {
  return idToTimer.computeIfAbsent(meter.id(), k -> {
      try {
        return registry.timers().anyMatch(m -> m.id().equals(meter.id()));
      } catch (ArrayIndexOutOfBoundsException aoex) {
        // !!! 20160929
        // !!! I dont know if this is a bug or what
        // !!! but the tests all get an array out of bounds calling stream()
        return meter instanceof Timer;
      }
      });
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:16,代码来源:MetricDescriptorCache.java

示例8: measurementToTimeSeries

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Convert a Spectator metric Meter into a Stackdriver TimeSeries entry.
 *
 * @param descriptorType
 *   The Stackdriver MetricDescriptorType name for the measurement.
 *
 * @param measurement
 *   The Spectator Measurement to encode.
 *
 * @return
 *   The Stackdriver TimeSeries equivalent for the measurement.
 */
public TimeSeries measurementToTimeSeries(
      String descriptorType, Registry registry, Meter meter, Measurement measurement) {
  Map<String, String> labels
      = cache.tagsToTimeSeriesLabels(descriptorType, measurement.id().tags());

  long millis = measurement.timestamp();
  double value = measurement.value();

  TimeInterval timeInterval = new TimeInterval();
  Date date = new Date(millis);
  timeInterval.setEndTime(rfc3339.format(date));

  String descriptorKind = cache.descriptorTypeToKind(descriptorType, registry, meter);
  if (descriptorKind == "CUMULATIVE") {
    timeInterval.setStartTime(counterStartTimeRfc3339);
  }

  TypedValue typedValue = new TypedValue();
  typedValue.setDoubleValue(value);

  Point point = new Point();
  point.setValue(typedValue);
  point.setInterval(timeInterval);

  Metric metric = new Metric();
  metric.setType(descriptorType);
  metric.setLabels(labels);

  TimeSeries ts = new TimeSeries();
  ts.setResource(monitoredResource);
  ts.setMetric(metric);
  ts.setMetricKind(descriptorKind);
  ts.setValueType("DOUBLE");
  ts.setPoints(Lists.<Point>newArrayList(point));

  return ts;
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:50,代码来源:StackdriverWriter.java

示例9: registryToTimeSeries

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Produce a TimeSeries for each appropriate measurement in the registry.
 */
public List<TimeSeries> registryToTimeSeries(Registry registry) {
  log.debug("Collecting metrics...");
  ArrayList<TimeSeries> tsList = new ArrayList<TimeSeries>();
  Iterator<Meter> iterator = registry.iterator();

  while (iterator.hasNext()) {
    addMeterToTimeSeries(registry, iterator.next(), tsList);
  }
  return tsList;
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:14,代码来源:StackdriverWriter.java

示例10: testMeasurementsToTimeSeries

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
@Test
public void testMeasurementsToTimeSeries() throws IOException {
    Measurement measureAXY
        = new Measurement(idAXY, clock.monotonicTime(), 1);
    Measurement measureBXY
        = new Measurement(idBXY, clock.monotonicTime(), 2);

  DefaultRegistry testRegistry = new DefaultRegistry(clock);
  testRegistry.counter(idAXY).increment();
  testRegistry.counter(idBXY).increment(2);

  // Note this writer is still using the mock Monitoring client stub.
  TestableStackdriverWriter spy
      = spy(new TestableStackdriverWriter(writerConfig.build()));

  Meter counterA = testRegistry.counter(idAXY);
  Meter counterB = testRegistry.counter(idBXY);

  doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(
      eq(descriptorA.getType()), eq(testRegistry), eq(counterA), eq(measureAXY));
  doReturn(new TimeSeries()).when(spy).measurementToTimeSeries(
      eq(descriptorB.getType()), eq(testRegistry), eq(counterB), eq(measureBXY));

  // Just testing the call flow produces descriptors since
  // we return empty TimeSeries values.
  spy.registryToTimeSeries(testRegistry);
}
 
开发者ID:spinnaker,项目名称:kork,代码行数:28,代码来源:StackdriverWriterTest.java

示例11: monitorMeter

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Provided for backwards compatibility to support the {@link Registry#register(Meter)}
 * method. Use the builder created with {@link #using(Registry)} instead.
 *
 * @deprecated This method only exists to allow for backwards compatibility and should
 * be considered an internal detail. Scheduled to be removed in 2.0.
 */
@Deprecated
public static void monitorMeter(Registry registry, Meter meter) {
  ConcurrentMap<Id, Object> state = registry.state();
  Object c = Utils.computeIfAbsent(state, meter.id(), MeterState::new);
  if (!(c instanceof MeterState)) {
    Utils.propagateTypeError(registry, meter.id(), MeterState.class, c.getClass());
  } else {
    MeterState t = (MeterState) c;
    t.add(meter);
    t.schedule(registry, null);
  }
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:20,代码来源:PolledMeter.java

示例12: getMeter

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
private Meter getMeter(String meterName, String threadPoolName) {
  ThreadPoolMonitor.attach(registry, latchedExecutor, threadPoolName);
  PolledMeter.update(registry);
  final Id id = registry.createId(meterName).withTag(ThreadPoolMonitor.ID_TAG_NAME,
      (threadPoolName == null || threadPoolName.isEmpty()) ? ThreadPoolMonitor.DEFAULT_ID : threadPoolName);
  return registry.get(id);
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:8,代码来源:ThreadPoolMonitorTest.java

示例13: checkIdTagValue

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
private void checkIdTagValue(Meter meter, String expectedIdValue) {
  final Iterable<Measurement> measurements = meter.measure();
  final Iterator<Measurement> measurementIterator = measurements.iterator();
  assertTrue(measurementIterator.hasNext());

  final Iterator<Tag> tags = measurementIterator.next().id().tags().iterator();
  assertTrue(tags.hasNext());
  Tag tag = tags.next();
  assertEquals(ThreadPoolMonitor.ID_TAG_NAME, tag.key());
  assertEquals(expectedIdValue, tag.value());
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:12,代码来源:ThreadPoolMonitorTest.java

示例14: encodeRegistry

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
/**
 * Internal API for encoding a registry that can be encoded as JSON.
 * This is a helper function for the REST endpoint and to test against.
 */
Map<String, MetricValues> encodeRegistry(
      Registry sourceRegistry, Predicate<Measurement> filter) {
  Map<String, MetricValues> metricMap = new HashMap<String, MetricValues>();

  /**
   * Flatten the meter measurements into a map of measurements keyed by
   * the name and mapped to the different tag variants.
   */
  for (Meter meter : sourceRegistry) {
    String kind = knownMeterKinds.computeIfAbsent(
                       meter.id(), k -> meterToKind(sourceRegistry, meter));

    for (Measurement measurement : meter.measure()) {
      if (!filter.test(measurement)) {
        continue;
      }

      String measurementName = measurement.id().name();
      MetricValues have = metricMap.get(measurementName);
      if (have == null) {
        metricMap.put(measurementName, new MetricValues(kind, measurement));
      } else {
        have.addMeasurement(measurement);
      }
    }
  }
  return metricMap;
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:33,代码来源:MetricsController.java

示例15: testEncodeCompositeRegistry

import com.netflix.spectator.api.Meter; //导入依赖的package包/类
@Test
public void testEncodeCompositeRegistry() {
  // Multiple occurrences of measurements in the same registry
  // (confirm these are handled within the registry itself).
  // Here measurements are duplicated but meters have different sets.
  Measurement measureAXY2 = new Measurement(idAXY, 20, 20.20);
  Meter meterA2 = new TestMeter("ignoreA", measureAXY2);

  DefaultRegistry registry = new DefaultRegistry(clock);
  registry.register(meterA);
  registry.register(meterA2);

  List<TaggedDataPoints> expected_tagged_data_points
      = Arrays.asList(
             new TaggedDataPoints(Arrays.asList(new BasicTag("tagA", "Y"),
                                                new BasicTag("tagB", "X")),
                                  Arrays.asList(new DataPoint(clock.wallTime(), 12.12))),
             new TaggedDataPoints(Arrays.asList(new BasicTag("tagA", "X"),
                                                new BasicTag("tagB", "Y")),
                                  // This should be 20, but AggrMeter keeps first time,
                                  // which happens to be the 11th, not the most recent time.
                                  Arrays.asList(new DataPoint(clock.wallTime(), 11.11 + 20.20))),
             new TaggedDataPoints(Arrays.asList(new BasicTag("tagA", "X"),
                                                new BasicTag("tagZ", "Z")),
                                  Arrays.asList(new DataPoint(clock.wallTime(), 13.13))));

  HashMap<String, MetricValues> expect = new HashMap<String, MetricValues>();
  expect.put("idA", new MetricValues("Counter", expected_tagged_data_points));

  Assert.assertEquals(expect,
                      controller.encodeRegistry(registry, allowAll));
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:33,代码来源:MetricsControllerTest.java


注:本文中的com.netflix.spectator.api.Meter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。