com.netflix.servo.Metric.getTimestamp()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(87)

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

Metric.getTimestamp介绍

[英]Returns the point in time when the metric was sampled.
[中]返回对度量进行采样的时间点。

代码示例

代码示例来源:origin: Netflix/servo

CounterValue(Metric m) {
 this(m.getTimestamp(), m.getNumberValue().doubleValue());
}

代码示例来源:origin: Netflix/servo

public double computeRate(Metric m) {
 final long currentTimestamp = m.getTimestamp();
 final double currentValue = m.getNumberValue().doubleValue();
 final long durationMillis = currentTimestamp - timestamp;
 final double delta = currentValue - value;
 timestamp = currentTimestamp;
 value = currentValue;
 return computeRate(durationMillis, delta);
}

代码示例来源:origin: Netflix/servo

private int writeMetrics(Iterable<Metric> metrics, PrintWriter writer) {
 int count = 0;
 for (Metric metric : metrics) {
  String publishedName = namingConvention.getName(metric);
  StringBuilder sb = new StringBuilder();
  if (serverPrefix != null) {
   sb.append(serverPrefix).append(".");
  }
  sb.append(publishedName).append(" ")
    .append(metric.getValue().toString())
    .append(" ")
    .append(metric.getTimestamp() / 1000);
  LOGGER.debug("{}", sb);
  writer.write(sb.append("\n").toString());
  count++;
 }
 return count;
}

代码示例来源:origin: Netflix/servo

AtlasMetric(Metric m) {
 this(m.getConfig(), m.getTimestamp(), m.getNumberValue());
}

代码示例来源:origin: Netflix/servo

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object obj) {
 if (obj == null || !(obj instanceof Metric)) {
  return false;
 }
 Metric m = (Metric) obj;
 return config.equals(m.getConfig())
   && timestamp == m.getTimestamp()
   && value.equals(m.getValue());
}

代码示例来源:origin: Netflix/servo

private Metric normalize(Metric m, long stepBoundary) {
 NormalizedValue normalizedValue = cache.get(m.getConfig());
 if (normalizedValue == null) {
  normalizedValue = new NormalizedValue();
  cache.put(m.getConfig(), normalizedValue);
 }
 double value = normalizedValue.updateAndGet(m.getTimestamp(),
   m.getNumberValue().doubleValue());
 return new Metric(m.getConfig(), stepBoundary, value);
}

代码示例来源:origin: Netflix/servo

/**
 * {@inheritDoc}
 */
public void update(List<Metric> metrics) {
 Preconditions.checkNotNull(metrics, "metrics");
 LOGGER.debug("received {} metrics", metrics.size());
 final List<Metric> newMetrics = new ArrayList<>(metrics.size());
 for (Metric m : metrics) {
  if (isCounter(m)) {
   final MonitorConfig rateConfig = toRateConfig(m.getConfig());
   final CounterValue prev = cache.get(rateConfig);
   if (prev != null) {
    final double rate = prev.computeRate(m);
    newMetrics.add(new Metric(rateConfig, m.getTimestamp(), rate));
   } else {
    CounterValue current = new CounterValue(m);
    cache.put(rateConfig, current);
    if (intervalMillis > 0L) {
     final double delta = m.getNumberValue().doubleValue();
     final double rate = current.computeRate(intervalMillis, delta);
     newMetrics.add(new Metric(rateConfig, m.getTimestamp(), rate));
    }
   }
  } else {
   newMetrics.add(m);
  }
 }
 LOGGER.debug("writing {} metrics to downstream observer", newMetrics.size());
 observer.update(newMetrics);
}

代码示例来源:origin: Netflix/servo

protected static Metric asGauge(Metric m) {
 return new Metric(m.getConfig().withAdditionalTag(ATLAS_GAUGE_TAG),
   m.getTimestamp(), m.getValue());
}

代码示例来源:origin: Netflix/servo

protected static Metric asCounter(Metric m) {
 return new Metric(m.getConfig().withAdditionalTag(ATLAS_COUNTER_TAG),
   m.getTimestamp(), m.getValue());
}

代码示例来源:origin: Netflix/servo

/**
 * {@inheritDoc}
 */
@Override
public void update(List<Metric> metrics) {
 Preconditions.checkNotNull(metrics, "metrics");
 final List<Metric> newMetrics = new ArrayList<>(metrics.size());
 for (Metric m : metrics) {
  long offset = m.getTimestamp() % stepMillis;
  long stepBoundary = m.getTimestamp() - offset;
  String dsType = getDataSourceType(m);
  if (isGauge(dsType) || isNormalized(dsType)) {
   Metric atStepBoundary = new Metric(m.getConfig(), stepBoundary, m.getValue());
   newMetrics.add(atStepBoundary); // gauges are not normalized
  } else if (isRate(dsType)) {
   Metric normalized = normalize(m, stepBoundary);
   if (normalized != null) {
    newMetrics.add(normalized);
   }
  } else if (!isInformational(dsType)) {
   // unknown type - use a safe fallback
   newMetrics.add(m); // we cannot normalize this
  }
 }
 observer.update(newMetrics);
}

代码示例来源:origin: Netflix/servo

static TimeVal from(Metric m) {
 return new TimeVal(m.getTimestamp(), m.getNumberValue().doubleValue());
}

代码示例来源:origin: Netflix/servo

@Test
public void testAccessors() throws Exception {
 long now = System.currentTimeMillis();
 Metric m1 = new Metric("a", tags1, now, 42);
 assertEquals(m1.getConfig(), new MonitorConfig.Builder("a").withTags(tags1).build());
 assertEquals(m1.getTimestamp(), now);
 assertEquals(m1.getValue(), 42);
}

代码示例来源:origin: Netflix/servo

MetricDatum createMetricDatum(Metric metric) {
 MetricDatum metricDatum = new MetricDatum();
 return metricDatum.withMetricName(metric.getConfig().getName())
   .withDimensions(createDimensions(metric.getConfig().getTags()))
   .withUnit("None")//DataSourceTypeToAwsUnit.getUnit(metric.))
   .withTimestamp(new Date(metric.getTimestamp()))
   .withValue(truncate(metric.getNumberValue()));
 //TODO Need to convert into reasonable units based on DataType
}

代码示例来源:origin: Netflix/servo

assertEquals(m.getTimestamp(), stepBoundary);

代码示例来源:origin: Netflix/servo

/**
 * Return a new metric where the name and all tags are using the valid character
 * set.
 */
public static Metric toValidValue(Metric metric) {
 MonitorConfig cfg = metric.getConfig();
 MonitorConfig.Builder cfgBuilder = MonitorConfig.builder(toValidCharset(cfg.getName()));
 for (Tag orig : cfg.getTags()) {
  final String key = orig.getKey();
  if (RELAXED_GROUP_KEYS.contains(key)) {
   cfgBuilder.withTag(key, toValidCharsetTable(CHARS_ALLOWED_GROUPS, orig.getValue()));
  } else {
   cfgBuilder.withTag(toValidCharset(key), toValidCharset(orig.getValue()));
  }
 }
 cfgBuilder.withPublishingPolicy(cfg.getPublishingPolicy());
 return new Metric(cfgBuilder.build(), metric.getTimestamp(), metric.getValue());
}

代码示例来源:origin: com.netflix.servo/servo-core

public double computeRate(Metric m) {
 final long currentTimestamp = m.getTimestamp();
 final double currentValue = m.getNumberValue().doubleValue();
 final long durationMillis = currentTimestamp - timestamp;
 final double delta = currentValue - value;
 timestamp = currentTimestamp;
 value = currentValue;
 return computeRate(durationMillis, delta);
}

代码示例来源:origin: com.netflix.servo/servo-core

/**
 * {@inheritDoc}
 */
@Override
public boolean equals(Object obj) {
 if (obj == null || !(obj instanceof Metric)) {
  return false;
 }
 Metric m = (Metric) obj;
 return config.equals(m.getConfig())
   && timestamp == m.getTimestamp()
   && value.equals(m.getValue());
}

代码示例来源:origin: com.netflix.servo/servo-core

private Metric normalize(Metric m, long stepBoundary) {
 NormalizedValue normalizedValue = cache.get(m.getConfig());
 if (normalizedValue == null) {
  normalizedValue = new NormalizedValue();
  cache.put(m.getConfig(), normalizedValue);
 }
 double value = normalizedValue.updateAndGet(m.getTimestamp(),
   m.getNumberValue().doubleValue());
 return new Metric(m.getConfig(), stepBoundary, value);
}

代码示例来源:origin: com.netflix.servo/servo-atlas

protected static Metric asGauge(Metric m) {
 return new Metric(m.getConfig().withAdditionalTag(ATLAS_GAUGE_TAG),
   m.getTimestamp(), m.getValue());
}

代码示例来源:origin: com.netflix.servo/servo-aws

MetricDatum createMetricDatum(Metric metric) {
 MetricDatum metricDatum = new MetricDatum();
 return metricDatum.withMetricName(metric.getConfig().getName())
   .withDimensions(createDimensions(metric.getConfig().getTags()))
   .withUnit("None")//DataSourceTypeToAwsUnit.getUnit(metric.))
   .withTimestamp(new Date(metric.getTimestamp()))
   .withValue(truncate(metric.getNumberValue()));
 //TODO Need to convert into reasonable units based on DataType
}

相关文章