本文整理了Java中io.micrometer.core.instrument.Tag
类的一些代码示例,展示了Tag
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tag
类的具体详情如下:
包路径:io.micrometer.core.instrument.Tag
类名称:Tag
暂无
代码示例来源:origin: line/armeria
private static void zip(List<Tag> list, String... tags) {
checkArgument(tags.length % 2 == 0, "tags.length: %s (expected: even)", tags.length);
for (int i = 0; i < tags.length;) {
list.add(Tag.of(tags[i++], tags[i++]));
}
}
代码示例来源: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: org.apache.camel/camel-micrometer
@Override
public void process(Exchange exchange) {
Message in = exchange.getIn();
String defaultMetricsName = simple(exchange, getEndpoint().getMetricsName(), String.class);
String finalMetricsName = getStringHeader(in, HEADER_METRIC_NAME, defaultMetricsName);
Iterable<Tag> defaultTags = getEndpoint().getTags();
Iterable<Tag> headerTags = getTagHeader(in, HEADER_METRIC_TAGS, Tags.empty());
Iterable<Tag> finalTags = Tags.concat(defaultTags, headerTags).stream()
.map(tag -> Tag.of(
simple(exchange, tag.getKey(), String.class),
simple(exchange, tag.getValue(), String.class)))
.reduce(Tags.empty(), Tags::and, Tags::and)
.and(Tags.of(
CAMEL_CONTEXT_TAG, getEndpoint().getCamelContext().getName()));
try {
doProcess(exchange, finalMetricsName, finalTags);
} catch (Exception e) {
exchange.setException(e);
} finally {
clearMetricsHeaders(in);
}
}
代码示例来源:origin: org.springframework.boot/spring-boot-actuator
@ReadOperation
public MetricResponse metric(@Selector String requiredMetricName,
@Nullable List<String> tag) {
List<Tag> tags = parseTags(tag);
Collection<Meter> meters = findFirstMatchingMeters(this.registry,
requiredMetricName, tags);
if (meters.isEmpty()) {
return null;
}
Map<Statistic, Double> samples = getSamples(meters);
Map<String, Set<String>> availableTags = getAvailableTags(meters);
tags.forEach((t) -> availableTags.remove(t.getKey()));
Meter.Id meterId = meters.iterator().next().getId();
return new MetricResponse(requiredMetricName, meterId.getDescription(),
meterId.getBaseUnit(), asList(samples, Sample::new),
asList(availableTags, AvailableTag::new));
}
代码示例来源:origin: netifi-proteus/proteus-java
String generatePrometheusFriendlyName(Meter.Id id) {
String name = "";
Optional<Tag> group = findTagByKey(id, "group");
if (group.isPresent()) {
name += group.get().getValue();
}
Optional<Tag> service = findTagByKey(id, "service");
if (service.isPresent()) {
name += "." + service.get().getValue();
}
Optional<Tag> method = findTagByKey(id, "method");
if (method.isPresent()) {
name += "." + method.get().getValue();
}
if (name.isEmpty()) {
return name;
} else {
return name + "." + id.getName();
}
}
代码示例来源:origin: netifi-proteus/proteus-java
private Optional<Tag> findTagByKey(Meter.Id id, String key) {
return id.getTags().stream().filter(tag -> tag.getKey().equals(key)).findFirst();
}
}
代码示例来源:origin: line/armeria
@Override
public void accept(List<Endpoint> endpoints) {
final Map<Endpoint, Boolean> endpointsToUpdate = new HashMap<>();
endpoints.forEach(e -> endpointsToUpdate.put(e, true));
endpointGroup.allServers.forEach(
conn -> endpointsToUpdate.putIfAbsent(conn.endpoint(), false));
// Update the previously appeared endpoints.
healthMap.entrySet().forEach(e -> {
final Endpoint authority = e.getKey();
final Boolean healthy = endpointsToUpdate.remove(authority);
e.setValue(Boolean.TRUE.equals(healthy));
});
// Process the newly appeared endpoints.
endpointsToUpdate.forEach((endpoint, healthy) -> {
healthMap.put(endpoint, healthy);
final List<Tag> tags = new ArrayList<>(2);
tags.add(Tag.of("authority", endpoint.authority()));
final String ipAddr = endpoint.hasIpAddr() ? endpoint.ipAddr() : "";
assert ipAddr != null;
tags.add(Tag.of("ip", ipAddr));
registry.gauge(idPrefix.name(), idPrefix.tags(tags),
this, unused -> healthMap.get(endpoint) ? 1 : 0);
});
}
}
代码示例来源: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: reactor/reactor-core
Tag.of(TAG_SCHEDULER_ID, schedulerId));
代码示例来源: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: line/armeria
@Override
public MeterIdPrefix apply(MeterRegistry registry, RequestLog log) {
final List<Tag> tags = buildTags(log);
// Add the 'httpStatus' tag.
final HttpStatus status;
if (log.isAvailable(RequestLogAvailability.RESPONSE_HEADERS)) {
status = log.status();
} else {
status = HttpStatus.UNKNOWN;
}
tags.add(Tag.of("httpStatus", status.codeAsText()));
return new MeterIdPrefix(name, tags);
}
代码示例来源: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: line/armeria
private List<Tag> buildTags(RequestLog log) {
final RequestContext ctx = log.context();
final Object requestContent = log.requestContent();
String methodName = null;
if (requestContent instanceof RpcRequest) {
methodName = ((RpcRequest) requestContent).method();
}
if (methodName == null) {
final HttpHeaders requestHeaders = log.requestHeaders();
final HttpMethod httpMethod = requestHeaders.method();
if (httpMethod != null) {
methodName = httpMethod.name();
}
}
if (methodName == null) {
methodName = MoreObjects.firstNonNull(log.method().name(), "__UNKNOWN_METHOD__");
}
final List<Tag> tags = new ArrayList<>(4); // method, hostNamePattern, pathMapping, status
tags.add(Tag.of("method", methodName));
if (ctx instanceof ServiceRequestContext) {
final ServiceRequestContext sCtx = (ServiceRequestContext) ctx;
tags.add(Tag.of("hostnamePattern", sCtx.virtualHost().hostnamePattern()));
tags.add(Tag.of("pathMapping", sCtx.pathMapping().meterTag()));
}
return tags;
}
};
代码示例来源: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: reactor/reactor-core
.map(tuple -> Tag.of(tuple.getT1(), tuple.getT2()))
.collect(Collectors.toList());
代码示例来源: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: reactor/reactor-core
commonTags.add(Tag.of(FluxMetrics.TAG_SEQUENCE_NAME, sequenceName));
commonTags.add(Tag.of(FluxMetrics.TAG_SEQUENCE_TYPE, FluxMetrics.TAGVALUE_MONO));
commonTags.addAll(sequenceTags);
代码示例来源: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: reactor/reactor-core
commonTags.add(Tag.of(TAG_SEQUENCE_NAME, sequenceName));
commonTags.add(Tag.of(TAG_SEQUENCE_TYPE, TAGVALUE_FLUX));
commonTags.addAll(sequenceTags);
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!