com.netflix.spectator.api.Tag类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(130)

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

Tag介绍

[英]Key/value pair used to classify and drill into measurements.
[中]用于分类和钻取度量值的键/值对。

代码示例

代码示例来源:origin: apache/servicecomb-java-chassis

protected Sample convertMeasurementToSample(Measurement measurement) {
 String prometheusName = measurement.id().name().replace(".", "_");
 List<String> labelNames = new ArrayList<>();
 List<String> labelValues = new ArrayList<>();
 for (Tag tag : measurement.id().tags()) {
  labelNames.add(tag.key());
  labelValues.add(tag.value());
 }
 return new Sample(prometheusName, labelNames, labelValues, measurement.value());
}

代码示例来源:origin: apache/servicecomb-java-chassis

private void printNetLog(StringBuilder sb, MeasurementNode osNode) {
 MeasurementNode netNode = osNode.findChild(OsMeter.OS_TYPE_NET);
 if (netNode == null || netNode.getMeasurements().isEmpty()) {
  return;
 }
 appendLine(sb, "  net:");
 appendLine(sb, "    send(Bps)    recv(Bps)    send(pps)    recv(pps)    interface");
 StringBuilder tmpSb = new StringBuilder();
 for (MeasurementNode interfaceNode : netNode.getChildren().values()) {
  double sendRate = interfaceNode.findChild(NetMeter.TAG_SEND.value()).summary();
  double sendPacketsRate = interfaceNode.findChild(NetMeter.TAG_PACKETS_SEND.value()).summary();
  double receiveRate = interfaceNode.findChild(NetMeter.TAG_RECEIVE.value()).summary();
  double receivePacketsRate = interfaceNode.findChild(NetMeter.TAG_PACKETS_RECEIVE.value()).summary();
  if (sendRate == 0 && receiveRate == 0 && receivePacketsRate == 0 && sendPacketsRate == 0) {
   continue;
  }
  appendLine(tmpSb, "    %-12s %-12s %-12s %-12s %s",
    NetUtils.humanReadableBytes((long) sendRate),
    NetUtils.humanReadableBytes((long) receiveRate),
    NetUtils.humanReadableBytes((long) sendPacketsRate),
    NetUtils.humanReadableBytes((long) receivePacketsRate),
    interfaceNode.getName());
 }
 if (tmpSb.length() != 0) {
  sb.append(tmpSb.toString());
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public Tag find(Iterable<Tag> tags) {
  for (Tag tag : tags) {
   if (tag.key().equals(tagKey)) {
    return tag;
   }
  }

  return null;
 }
}

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

private Id convert(io.micrometer.core.instrument.Meter.Id id) {
 List<Tag> tags = id.getTags()
   .stream()
   .map(t -> Tag.of(t.getKey(), t.getValue()))
   .collect(Collectors.toList());
 return Id.create(id.getName()).withTags(tags);
}

代码示例来源:origin: apache/servicecomb-java-chassis

public void from(Iterable<Measurement> measurements, MeasurementGroupConfig groupConfig) {
  for (Measurement measurement : measurements) {
   Id id = measurement.id();
   MeasurementNode node = addChild(id.name(), measurement);

   List<TagFinder> tagFinders = groupConfig.findTagFinders(id.name());
   if (tagFinders == null) {
    continue;
   }

   for (TagFinder tagFinder : tagFinders) {
    Tag tag = tagFinder.find(id.tags());
    if (tag == null) {
     if (tagFinder.skipOnNull()) {
      break;
     }
     throw new IllegalStateException(
       String.format("tag key \"%s\" not exist in %s",
         tagFinder.getTagKey(),
         measurement));
    }

    node = node.addChild(tag.value(), measurement);
   }
  }
 }
}

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

@Override
public String name() {
 return tag.key();
}

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

private String[] toStringArray(Tag[] ts, int length) {
 String[] strs = new String[length * 2];
 for (int i = 0; i < length; ++i) {
  strs[2 * i] = ts[i].key();
  strs[2 * i + 1] = ts[i].value();
 }
 return strs;
}

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

JsonStringBuilder addField(String k, Tag tag) {
 if (tag != null) {
  addField(k, tag.value());
 }
 return this;
}

代码示例来源:origin: org.apache.servicecomb/foundation-metrics

@Override
 public Tag find(Iterable<Tag> tags) {
  for (Tag tag : tags) {
   if (tag.key().equals(tagKey)) {
    return tag;
   }
  }

  return null;
 }
}

代码示例来源:origin: com.netflix.spectator/spectator-api

private String[] toStringArray(Tag[] ts, int length) {
 String[] strs = new String[length * 2];
 for (int i = 0; i < length; ++i) {
  strs[2 * i] = ts[i].key();
  strs[2 * i + 1] = ts[i].value();
 }
 return strs;
}

代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc

JsonStringBuilder addField(String k, Tag tag) {
 if (tag != null) {
  addField(k, tag.value());
 }
 return this;
}

代码示例来源:origin: com.netflix.spectator/spectator-api

/**
 * Dedup any entries in {@code ts} that have the same key. The last entry with a given
 * key will get selected. Input data must already be sorted by the tag key. Returns the
 * length of the overall deduped array.
 */
private int dedup(Tag[] src, int ss, Tag[] dst, int ds, int len) {
 if (len == 0) {
  return ds;
 } else {
  dst[ds] = src[ss];
  String k = src[ss].key();
  int j = ds;
  final int e = ss + len;
  for (int i = ss + 1; i < e; ++i) {
   if (k.equals(src[i].key())) {
    dst[j] = src[i];
   } else {
    k = src[i].key();
    dst[++j] = src[i];
   }
  }
  return j + 1;
 }
}

代码示例来源:origin: com.netflix.spectator/spectator-web-spring

JacksonableTag(Tag tag) {
 key = tag.key();
 value = tag.value();
}

代码示例来源:origin: org.apache.servicecomb/metrics-core

private void printNetLog(StringBuilder sb, MeasurementNode osNode) {
 MeasurementNode netNode = osNode.findChild(OsMeter.OS_TYPE_NET);
 if (netNode == null || netNode.getMeasurements().isEmpty()) {
  return;
 }
 appendLine(sb, "  net:");
 appendLine(sb, "    send         receive      interface");
 StringBuilder tmpSb = new StringBuilder();
 for (MeasurementNode interfaceNode : netNode.getChildren().values()) {
  double sendRate = interfaceNode.findChild(NetMeter.TAG_SEND.value()).summary();
  double receiveRate = interfaceNode.findChild(NetMeter.TAG_RECEIVE.value()).summary();
  if (sendRate == 0 && receiveRate == 0) {
   continue;
  }
  appendLine(tmpSb, "    %-12s %-12s %s",
    NetUtils.humanReadableBytes((long) sendRate),
    NetUtils.humanReadableBytes((long) receiveRate),
    interfaceNode.getName());
 }
 if (tmpSb.length() != 0) {
  sb.append(tmpSb.toString());
 }
}

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

/**
 * Dedup any entries in {@code ts} that have the same key. The last entry with a given
 * key will get selected. Input data must already be sorted by the tag key. Returns the
 * length of the overall deduped array.
 */
private int dedup(Tag[] src, int ss, Tag[] dst, int ds, int len) {
 if (len == 0) {
  return ds;
 } else {
  dst[ds] = src[ss];
  String k = src[ss].key();
  int j = ds;
  final int e = ss + len;
  for (int i = ss + 1; i < e; ++i) {
   if (k.equals(src[i].key())) {
    dst[j] = src[i];
   } else {
    k = src[i].key();
    dst[++j] = src[i];
   }
  }
  return j + 1;
 }
}

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

JacksonableTag(Tag tag) {
 key = tag.key();
 value = tag.value();
}

代码示例来源:origin: org.apache.servicecomb/foundation-metrics

public void from(Iterable<Measurement> measurements, MeasurementGroupConfig groupConfig) {
  for (Measurement measurement : measurements) {
   Id id = measurement.id();
   MeasurementNode node = addChild(id.name(), measurement);

   List<TagFinder> tagFinders = groupConfig.findTagFinders(id.name());
   if (tagFinders == null) {
    continue;
   }

   for (TagFinder tagFinder : tagFinders) {
    Tag tag = tagFinder.find(id.tags());
    if (tag == null) {
     if (tagFinder.skipOnNull()) {
      break;
     }
     throw new IllegalStateException(
       String.format("tag key \"%s\" not exist in %s",
         tagFinder.getTagKey(),
         measurement));
    }

    node = node.addChild(tag.value(), measurement);
   }
  }
 }
}

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

private void putTag(Map<String, String> tags, Tag tag) {
 if (tag != null) {
  tags.put(tag.key(), tag.value());
 }
}

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

/**
 * Add custom tags to the request metrics. Note, IPC metrics already have many tags and it
 * is not recommended for users to tack on additional context. In particular, any additional
 * tags should have a <b>guaranteed</b> low cardinality. If additional tagging causes these
 * metrics to exceed limits, then you may lose all visibility into requests.
 */
public IpcLogEntry addTag(Tag tag) {
 this.additionalTags.put(tag.key(), tag.value());
 return this;
}

代码示例来源:origin: com.netflix.spectator/spectator-ext-ipc

/**
 * Add custom tags to the request metrics. Note, IPC metrics already have many tags and it
 * is not recommended for users to tack on additional context. In particular, any additional
 * tags should have a <b>guaranteed</b> low cardinality. If additional tagging causes these
 * metrics to exceed limits, then you may lose all visibility into requests.
 */
public IpcLogEntry addTag(Tag tag) {
 this.additionalTags.put(tag.key(), tag.value());
 return this;
}

相关文章