@Override public String toString() { return new StringJoiner(", ", this.getClass().getSimpleName() + "{", "}") .add("info=" + info) .add("value=" + value()) .toString(); } }
@Override public boolean equals(Object obj) { if (obj instanceof MetricsTag) { final MetricsTag other = (MetricsTag) obj; return Objects.equal(info, other.info()) && Objects.equal(value, other.value()); } return false; }
@Override public String context() { // usually the first tag for (MetricsTag t : tags) { if (t.info() == MsInfo.Context) { return t.value(); } } return DEFAULT_CONTEXT; }
private void setAttrCacheTag(MetricsTag tag, int recNo) { String key = tagName(tag.name(), recNo); attrCache.put(key, new Attribute(key, tag.value())); }
@Override public MetricsRecordBuilder add(MetricsTag tag) { return tuple(tag.name(), tag.value()); }
@Override public MetricsRecordBuilder add(MetricsTag tag) { return tuple(tag.name(), tag.value()); }
@InterfaceAudience.Private public void appendPrefix(MetricsRecord record, StringBuilder sb) { String contextName = record.context(); Collection<MetricsTag> tags = record.tags(); if (useTagsMap.containsKey(contextName)) { Set<String> useTags = useTagsMap.get(contextName); for (MetricsTag t : tags) { if (useTags == null || useTags.contains(t.name())) { // the context is always skipped here because it is always added // the hostname is always skipped to avoid case-mismatches // from different DNSes. if (t.info() != MsInfo.Context && t.info() != MsInfo.Hostname && t.value() != null) { sb.append('.').append(t.name()).append('=').append(t.value()); } } } } }
@Override public boolean accepts(MetricsTag tag) { // Accept if whitelisted Pattern ipat = includeTagPatterns.get(tag.name()); if (ipat != null && ipat.matcher(tag.value()).matches()) { return true; } // Reject if blacklisted Pattern epat = excludeTagPatterns.get(tag.name()); if (epat != null && epat.matcher(tag.value()).matches()) { return false; } // Reject if no match in whitelist only mode if (!includeTagPatterns.isEmpty() && excludeTagPatterns.isEmpty()) { return false; } return true; }
@Override public MetricsRecordBuilder add(MetricsTag metricsTag) { tags.put(canonicalizeMetricName(metricsTag.name()), metricsTag.value()); return this; }
@Override public void putMetrics(MetricsRecord record) { writer.print(record.timestamp()); writer.print(" "); writer.print(record.context()); writer.print("."); writer.print(record.name()); String separator = ": "; for (MetricsTag tag : record.tags()) { writer.print(separator); separator = ", "; writer.print(tag.name()); writer.print("="); writer.print(tag.value()); } for (AbstractMetric metric : record.metrics()) { writer.print(separator); separator = ", "; writer.print(metric.name()); writer.print("="); writer.print(metric.value()); } writer.println(); }
@Override public boolean accepts(Iterable<MetricsTag> tags) { // Accept if any include tag pattern matches for (MetricsTag t : tags) { Pattern pat = includeTagPatterns.get(t.name()); if (pat != null && pat.matcher(t.value()).matches()) { return true; } } // Reject if any exclude tag pattern matches for (MetricsTag t : tags) { Pattern pat = excludeTagPatterns.get(t.name()); if (pat != null && pat.matcher(t.value()).matches()) { return false; } } // Reject if no match in whitelist only mode if (!includeTagPatterns.isEmpty() && excludeTagPatterns.isEmpty()) { return false; } return true; }
/** * Gets the balancer status tag from the Metrics registry */ public String getStatus() throws Exception { MetricsSource source = DefaultMetricsSystem.instance().getSource(MetricsBalancerSource.METRICS_JMX_CONTEXT); if (source instanceof MetricsBalancerSourceImpl) { MetricsTag status = ((MetricsBalancerSourceImpl) source).getMetricsRegistry() .getTag(MetricsBalancerSource.BALANCER_STATUS); return status.value(); } else { LOG.warn("Balancer JMX Metrics not registered"); throw new Exception("MetricsBalancer JMX Context not found"); } }
/** * Update the cache and return the current cached record * @param mr the update record * @param includingTags cache tag values (for later lookup by name) if true * @return the updated cache record */ public Record update(MetricsRecord mr, boolean includingTags) { String name = mr.name(); RecordCache recordCache = map.get(name); if (recordCache == null) { recordCache = new RecordCache(); map.put(name, recordCache); } Collection<MetricsTag> tags = mr.tags(); Record record = recordCache.get(tags); if (record == null) { record = new Record(); recordCache.put(tags, record); } for (AbstractMetric m : mr.metrics()) { record.metrics.put(m.name(), m); } if (includingTags) { // mostly for some sinks that include tags as part of a dense schema for (MetricsTag t : mr.tags()) { record.tags.put(t.name(), t.value()); } } return record; }
tag.value()); separator = ", ";
private void addDynamicEntry(List<String> keys, List<Object> values, List<String> variableValues, String family, MetricsTag tag, MetricInfo metric, int count) { // <family><.dynColumn><count> <VARCHAR> keys.add(getDynamicColumnName(family, metric.columnName, count) + " VARCHAR"); // build the annotation value String val = tag.description() + " - " + tag.value(); values.add(VARIABLE_VALUE); variableValues.add(val); }
keys.add(HOSTNAME.columnName); values.add(VARIABLE_VALUE); variableValues.add(tag.value()); } else if (tag.name().equals("Context")) {
@Override public boolean equals(Object obj) { if (obj instanceof MetricsTag) { final MetricsTag other = (MetricsTag) obj; return Objects.equal(info, other.info()) && Objects.equal(value, other.value()); } return false; }