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()); }
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()); } }
@Override public Tag find(Iterable<Tag> tags) { for (Tag tag : tags) { if (tag.key().equals(tagKey)) { return tag; } } return null; } }
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); }
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); } } } }
@Override public String name() { return tag.key(); }
JsonStringBuilder addField(String k, Tag tag) { if (tag != null) { addField(k, tag.value()); } return this; }
@Override public Tag find(Iterable<Tag> tags) { for (Tag tag : tags) { if (tag.key().equals(tagKey)) { return tag; } } return null; } }
JsonStringBuilder addField(String k, Tag tag) { if (tag != null) { addField(k, tag.value()); } return this; }
/** * 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; } }
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()); } }
/** * 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; } }
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); } } } }
/** * 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; }
/** * 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; }