本文整理了Java中io.micrometer.core.instrument.Tag.getValue()
方法的一些代码示例,展示了Tag.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag.getValue()
方法的具体详情如下:
包路径:io.micrometer.core.instrument.Tag
类名称:Tag
方法名:getValue
暂无
代码示例来源:origin: line/armeria
@Override
public String toString() {
if (tags.isEmpty()) {
return name;
}
final StringBuilder buf = new StringBuilder();
buf.append(name).append('{');
tags.forEach(tag -> buf.append(tag.getKey()).append('=')
.append(tag.getValue()).append(','));
buf.setCharAt(buf.length() - 1, '}');
return buf.toString();
}
}
代码示例来源:origin: line/armeria
private static String measurementName(Meter.Id id, Measurement measurement) {
final StringBuilder buf = new StringBuilder();
// Append name.
buf.append(id.getName());
// Append statistic.
buf.append('#');
buf.append(measurement.getStatistic().getTagValueRepresentation());
// Append tags if there are any.
final Iterator<Tag> tagsIterator = id.getTags().iterator();
if (tagsIterator.hasNext()) {
buf.append('{');
tagsIterator.forEachRemaining(tag -> buf.append(tag.getKey()).append('=')
.append(tag.getValue()).append(','));
buf.setCharAt(buf.length() - 1, '}');
}
return buf.toString();
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
private void mergeAvailableTags(Map<String, Set<String>> availableTags, Meter meter) {
meter.getId().getTags().forEach((tag) -> {
Set<String> value = Collections.singleton(tag.getValue());
availableTags.merge(tag.getKey(), value, this::merge);
});
}
代码示例来源:origin: yidongnan/grpc-spring-boot-starter
/**
* Logs a sorted and readable list of meters using the debug level. Useful for debugging.
*
* @param meters The meters to be logged.
*/
public static void logMeters(final Collection<? extends Meter> meters) {
if (!log.isDebugEnabled()) {
return;
}
// The original collection is usually unmodifiable
final List<Meter> sortedMeters = new ArrayList<>(meters);
Collections.sort(sortedMeters, METER_COMPARATOR);
log.debug("Found meters:");
for (final Meter meter : sortedMeters) {
final Id id = meter.getId();
final String type = id.getType().name();
final String name = id.getName();
final Map<String, String> tagMap = new LinkedHashMap<>(); // Tags are already sorted
for (final Tag tag : id.getTags()) {
tagMap.put(tag.getKey(), tag.getValue());
}
log.debug("- {} {} {}", type, name, tagMap);
}
}
代码示例来源:origin: org.apache.camel/camel-micrometer
@Override
public void serialize(Tag tag, JsonGenerator json, SerializerProvider provider) throws IOException {
json.writeStartObject();
json.writeStringField(tag.getKey(), tag.getValue());
json.writeEndObject();
}
}
代码示例来源:origin: io.micrometer/micrometer-registry-cloudwatch
private List<Dimension> toDimensions(List<Tag> tags) {
return tags.stream()
.map(tag -> new Dimension().withName(tag.getKey()).withValue(tag.getValue()))
.collect(toList());
}
}
代码示例来源:origin: dev.rico/rico-metrics
@Override
public List<Context> getContext() {
return counter.getId().getTags()
.stream()
.map(t -> new ContextImpl(t.getKey(), t.getValue()))
.collect(Collectors.toList());
}
代码示例来源:origin: io.micrometer/micrometer-registry-atlas
private Id spectatorId(Meter.Id id) {
List<com.netflix.spectator.api.Tag> tags = getConventionTags(id).stream()
.map(t -> new BasicTag(t.getKey(), t.getValue()))
.collect(toList());
return registry.createId(getConventionName(id), tags);
}
代码示例来源: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: io.micrometer/micrometer-registry-kairos
KairosMetricBuilder tags(List<Tag> tags) {
KairosMetricBuilder tagBuilder = new KairosMetricBuilder();
if (tags.isEmpty()) {
// tags field is required for KairosDB, use hostname as a default tag
try {
tagBuilder.field("hostname", InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException ignore) {
/* ignore */
}
} else {
for (Tag tag : tags) {
tagBuilder.field(tag.getKey(), tag.getValue());
}
}
sb.append(",\"tags\":").append(tagBuilder.build());
return this;
}
代码示例来源:origin: io.micrometer/micrometer-registry-datadog
String writeMetric(Meter.Id id, @Nullable String suffix, long wallTime, double value) {
Meter.Id fullId = id;
if (suffix != null)
fullId = idWithSuffix(id, suffix);
Iterable<Tag> tags = getConventionTags(fullId);
String host = config.hostTag() == null ? "" : stream(tags.spliterator(), false)
.filter(t -> requireNonNull(config.hostTag()).equals(t.getKey()))
.findAny()
.map(t -> ",\"host\":\"" + escapeJson(t.getValue()) + "\"")
.orElse("");
String tagsArray = tags.iterator().hasNext()
? stream(tags.spliterator(), false)
.map(t -> "\"" + escapeJson(t.getKey()) + ":" + escapeJson(t.getValue()) + "\"")
.collect(joining(",", ",\"tags\":[", "]"))
: "";
return "{\"metric\":\"" + escapeJson(getConventionName(fullId)) + "\"," +
"\"points\":[[" + (wallTime / 1000) + ", " + value + "]]" + host + tagsArray + "}";
}
代码示例来源:origin: io.micrometer/micrometer-registry-new-relic
private String event(Meter.Id id, Iterable<Tag> extraTags, Attribute... attributes) {
StringBuilder tagsJson = new StringBuilder();
for (Tag tag : getConventionTags(id)) {
tagsJson.append(",\"").append(escapeJson(tag.getKey())).append("\":\"").append(escapeJson(tag.getValue())).append("\"");
}
NamingConvention convention = config().namingConvention();
for (Tag tag : extraTags) {
tagsJson.append(",\"").append(escapeJson(convention.tagKey(tag.getKey())))
.append("\":\"").append(escapeJson(convention.tagValue(tag.getValue()))).append("\"");
}
return Arrays.stream(attributes)
.map(attr -> ",\"" + attr.getName() + "\":" + DoubleFormat.decimalOrWhole(attr.getValue().doubleValue()))
.collect(Collectors.joining("", "{\"eventType\":\"" + escapeJson(getConventionName(id)) + "\"", tagsJson + "}"));
}
代码示例来源:origin: io.micrometer/micrometer-registry-elastic
String writeDocument(Meter meter, Consumer<StringBuilder> consumer) {
StringBuilder sb = new StringBuilder(INDEX_LINE);
String timestamp = FORMATTER.format(Instant.ofEpochMilli(config().clock().wallTime()));
String name = getConventionName(meter.getId());
String type = meter.getId().getType().toString().toLowerCase();
sb.append("{\"").append(config.timestampFieldName()).append("\":\"").append(timestamp).append('"')
.append(",\"name\":\"").append(escapeJson(name)).append('"')
.append(",\"type\":\"").append(type).append('"');
List<Tag> tags = getConventionTags(meter.getId());
for (Tag tag : tags) {
sb.append(",\"").append(escapeJson(tag.getKey())).append("\":\"")
.append(escapeJson(tag.getValue())).append('"');
}
consumer.accept(sb);
sb.append("}");
return sb.toString();
}
代码示例来源:origin: io.micrometer/micrometer-registry-wavefront
private String writeMetricProxy(Meter.Id id, @Nullable String suffix, long wallTime, double value) {
Meter.Id fullId = id;
if (suffix != null)
fullId = idWithSuffix(id, suffix);
// surrounding the name with double quotes allows for / and , in names
return "\"" + getConventionName(fullId) + "\" " + DoubleFormat.decimalOrNan(value) + " " + (wallTime / 1000) +
" source=" + config.source() + " " +
getConventionTags(fullId)
.stream()
.map(t -> t.getKey() + "=\"" + t.getValue() + "\"")
.collect(joining(" "));
}
代码示例来源:origin: io.micrometer/micrometer-registry-wavefront
private String writeMetricDirect(Meter.Id id, @Nullable String suffix, double value) {
Meter.Id fullId = id;
if (suffix != null)
fullId = idWithSuffix(id, suffix);
List<Tag> conventionTags = getConventionTags(fullId);
String tags = conventionTags
.stream()
.map(t -> "\"" + escapeJson(t.getKey()) + "\": \"" + escapeJson(t.getValue()) + "\"")
.collect(joining(","));
UUID uuid = UUID.randomUUID();
String uniqueNameSuffix = ((Long) uuid.getMostSignificantBits()).toString() + uuid.getLeastSignificantBits();
// To be valid JSON, the metric name must be unique. Since the same name can occur in multiple entries because of
// variance in tag values, we need to append a suffix to the name. The suffix must be numeric, or Wavefront interprets
// it as part of the name. Wavefront strips a $<NUMERIC> suffix from the name at parsing time.
return "\"" + escapeJson(getConventionName(fullId)) + "$" + uniqueNameSuffix + "\"" +
": {" +
"\"value\": " + DoubleFormat.decimalOrNan(value) + "," +
"\"tags\": {" + tags + "}" +
"}";
}
代码示例来源:origin: io.vertx/vertx-micrometer-metrics
private static JsonObject metricToJson(Meter meter) {
JsonObject tags = new JsonObject();
meter.getId().getTags().forEach(tag -> tags.put(tag.getKey(), tag.getValue()));
JsonObject obj = new JsonObject().put("tags", tags);
switch (meter.getId().getType()) {
case COUNTER:
return counterToJson(obj, (Counter)meter);
case GAUGE:
return gaugeToJson(obj, (Gauge)meter);
case TIMER:
return timerToJson(obj, (Timer)meter);
case DISTRIBUTION_SUMMARY:
return summaryToJson(obj, (DistributionSummary)meter);
case OTHER:
default:
return obj.put("type", "unknown");
}
}
代码示例来源:origin: io.micrometer/micrometer-registry-statsd
private void updateIfNamingConventionChanged() {
NamingConvention next = config.namingConvention();
if (this.namingConvention != next) {
this.namingConvention = next;
this.name = sanitize(next.name(id.getName(), id.getType(), id.getBaseUnit()));
this.tags = HashTreePMap.empty();
this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ?
id.getConventionTags(this.namingConvention).stream()
.map(t -> sanitize(t.getKey()) + "=" + sanitize(t.getValue()))
.collect(Collectors.joining(","))
: null;
this.tagsNoStat = tags(null, conventionTags, "=", "#");
}
}
代码示例来源:origin: io.micrometer/micrometer-registry-statsd
private void updateIfNamingConventionChanged() {
NamingConvention next = config.namingConvention();
if (this.namingConvention != next) {
this.namingConvention = next;
this.name = next.name(sanitize(id.getName()), id.getType(), id.getBaseUnit()) + ":";
this.tags = HashTreePMap.empty();
this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ?
id.getConventionTags(this.namingConvention).stream()
.map(t -> sanitize(t.getKey()) + ":" + sanitize(t.getValue()))
.collect(Collectors.joining(","))
: null;
this.tagsNoStat = tags(null, conventionTags, ":", "|#");
}
}
代码示例来源:origin: io.micrometer/micrometer-registry-statsd
private void updateIfNamingConventionChanged() {
NamingConvention next = config.namingConvention();
if (this.namingConvention != next) {
for (; ; ) {
if (namingConventionUpdater.compareAndSet(this, this.namingConvention, next))
break;
}
this.name = telegrafEscape(next.name(id.getName(), id.getType(), id.getBaseUnit()));
this.tags = HashTreePMap.empty();
this.conventionTags = id.getTagsAsIterable().iterator().hasNext() ?
id.getConventionTags(this.namingConvention).stream()
.map(t -> telegrafEscape(t.getKey()) + "=" + telegrafEscape(t.getValue()))
.collect(Collectors.joining(","))
: null;
this.tagsNoStat = tags(null, conventionTags, "=", ",");
}
}
代码示例来源:origin: io.vertx/vertx-micrometer-metrics
private static String id(Meter m) {
return m.getId().getName() + "["
+ StreamSupport.stream(m.getId().getTags().spliterator(), false)
.map(t -> t.getKey() + '=' + t.getValue())
.collect(Collectors.joining(","))
+ "]";
}
内容来源于网络,如有侵权,请联系作者删除!