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

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

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

Metric.getValue介绍

[英]Returns the value of the metric.
[中]返回度量值。

代码示例

代码示例来源: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

/**
 * {@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

out.append(m.getConfig().getName()).append('\t')
  .append(m.getConfig().getTags().toString()).append('\t')
  .append(m.getValue().toString()).append('\n');

代码示例来源: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

@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

/**
 * {@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

@Test
 public void testNonNumericMetrics() throws Exception {
  MapMXBean mapMXBean = new MapMXBean();
  try {
   MetricPoller poller = new JmxMetricPoller(
     new LocalJmxConnector(),
     Collections.singletonList(new ObjectName("com.netflix.servo.test:*")),
     MATCH_ALL,
     false,
     null);

   List<Metric> metrics = poller.poll(config -> config.getName().equals("StringValue"));
   assertEquals(metrics.size(), 1);
   assertEquals(metrics.get(0).getValue(), "AStringResult");
  } finally {
   mapMXBean.destroy();
  }
 }
}

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

/**
 * Tabular JMX values are very useful for cases where we want the same behavior as CompositePath but we
 * don't know up front what the values are going to be.
 */
@Test
public void testTabularData() throws Exception {
 MapMXBean mapMXBean = new MapMXBean();
 try {
  MetricPoller poller = new JmxMetricPoller(
    new LocalJmxConnector(),
    new ObjectName("com.netflix.servo.test:*"),
    MATCH_ALL);
  List<Metric> metrics = poller.poll(config -> config.getName().equals("Count"));
  assertEquals(metrics.size(), 2);
  Map<String, Integer> values = new HashMap<>();
  for (Metric m : metrics) {
   values.put(m.getConfig().getTags().getTag("JmxCompositePath").getValue(), (Integer) m.getValue());
  }
  assertEquals(values.get("Entry1"), (Integer) 111);
  assertEquals(values.get("Entry2"), (Integer) 222);
 } finally {
  mapMXBean.destroy();
 }
}

代码示例来源: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-graphite

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: io.servicecomb/foundation-metrics

@Override
public Map<String, String> convert(List<Metric> metrics) {
 Map<String, String> pickedMetrics = new HashMap<>();
 for (Metric metric : metrics) {
  if (isTotalRequestInstanceLevelMetric(metric.getConfig().getName())) {
   pickedMetrics.put(metric.getConfig().getName().replace(" INSTANCE_LEVEL", ""), metric.getValue().toString());
  } else if ("RequestQueueRelated".equals(metric.getConfig().getName())) {
   String instanceContent = metric.getValue()
     .toString()
     .substring(metric.getValue().toString().indexOf("InstanceLevel={") + "InstanceLevel={".length());
   instanceContent = instanceContent.substring(0, instanceContent.indexOf('}'));
   String[] keyAndValueStrings = instanceContent.split(",");
   for (String keyAndValueString : keyAndValueStrings) {
    String[] keyAndValue = keyAndValueString.split("=");
    pickedMetrics.put(keyAndValue[0].trim(), keyAndValue[1].trim());
   }
  } else if (isSystemOrTPSAndLatencyMetric(metric.getConfig().getName())) {
   String instanceContent = metric.getValue().toString().substring(1, metric.getValue().toString().length() - 1);
   String[] keyAndValueStrings = instanceContent.split(",");
   for (String keyAndValueString : keyAndValueStrings) {
    String[] keyAndValue = keyAndValueString.split("=");
    pickedMetrics.put(keyAndValue[0].trim(), keyAndValue[1].trim());
   }
  }
 }
 return pickedMetrics;
}

代码示例来源: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-atlas

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

代码示例来源: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.sap.cloud.yaas.service-sdk/service-sdk-monitoring

@Override
  public void updateImpl(final List<Metric> metrics)
  {
    for (final Metric metric : metrics)
    {
      Object metricValue = metric.getValue();
      if (metricValue instanceof Double
          && (((Double) metricValue) == Double.POSITIVE_INFINITY || ((Double) metricValue) == Double.NEGATIVE_INFINITY))
      {
        metricValue = null;
      }
      else if (metricValue instanceof Float
          && (((Float) metricValue) == Float.POSITIVE_INFINITY || ((Float) metricValue) == Float.NEGATIVE_INFINITY))
      {
        metricValue = null;
      }

      MetricLogger
          .newInstance()
          .metric(namingConvention.getName(metric))
          .type(metric.hasNumberValue() ? MetricType.NUMBER : MetricType.STRING)
          .log(metricValue);
    }
    LOG.debug("Wrote {} metrics to logger", metrics.size());
  }
}

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

/**
 * {@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: com.redhat.lightblue/lightblue-core-hystrix

@Override
public void updateImpl(List<Metric> metrics) {
  // The statsd client doesn't do any checks on the underlying socket's state
  // and the socket connects only once, so we cannot trust the socket to stay
  // open over a period of time.  If this is changed/fixed we could reuse the
  // client but until then it cannot be safely reused.
  StatsDClient statsd = createClient();
  LOGGER.debug("sending data");
  try {
    for (Metric metric : metrics) {
      String aspect = namingConvention.getName(metric);
      if (metric.getConfig().getTags().getTag(DataSourceType.COUNTER.getValue()) != null) {
        statsd.count(aspect, metric.getNumberValue().longValue());
      } else if (metric.hasNumberValue()) {
        statsd.gauge(aspect, metric.getNumberValue().longValue());
      } else {
        statsd.set(aspect, metric.getValue().toString());
      }
      statsd.time(aspect, metric.getTimestamp() / 1000);
    }
  } finally {
    statsd.stop();
  }
}

代码示例来源:origin: com.sap.cloud.yaas.service-sdk/service-sdk-monitoring

private Event buildEvent(final Metric metric)
{
  final EventDSL eventBuilder = client.event()//
      .host(observerPrefix)//
      .service(namingConvention.getName(metric))//
      .state("ok")//
      .description(null)//
      .time(metric.getTimestamp() / SECOND_AS_MILLI);
  if (metric.hasNumberValue())
  {
    eventBuilder.metric(metric.getNumberValue().doubleValue());
  }
  else if (metric.getValue() != null)
  {
    eventBuilder.attribute("value", metric.getValue().toString());
  }
  for (final Tag tag : metric.getConfig().getTags())
  {
    eventBuilder.tag(tag.getValue());
  }
  final Event event = eventBuilder.build();
  LOG.debug("Creating metric for '{}.{}' with timestamp '{}' and metric '{}' and attributes '{}'", event.getHost(),
      event.getService(), event.getTime(), event.getMetricD(), event.getAttributesList());
  return event;
}

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

/**
 * 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());
}

相关文章