本文整理汇总了Java中org.apache.hadoop.metrics2.MetricsRecord.context方法的典型用法代码示例。如果您正苦于以下问题:Java MetricsRecord.context方法的具体用法?Java MetricsRecord.context怎么用?Java MetricsRecord.context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.metrics2.MetricsRecord
的用法示例。
在下文中一共展示了MetricsRecord.context方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendPrefix
import org.apache.hadoop.metrics2.MetricsRecord; //导入方法依赖的package包/类
@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());
}
}
}
}
}
示例2: getMetricBaseName
import org.apache.hadoop.metrics2.MetricsRecord; //导入方法依赖的package包/类
public String getMetricBaseName(MetricsRecord record, String metricPrefix) {
String metricBaseName = "";
if(!metricPrefix.isEmpty())
metricBaseName = metricPrefix + div + record.context();
else
metricBaseName = record.context();
if (!record.context().equalsIgnoreCase(record.name()) && !record.name().isEmpty())
metricBaseName = metricBaseName + div + record.name();
return metricBaseName;
}
示例3: putMetrics
import org.apache.hadoop.metrics2.MetricsRecord; //导入方法依赖的package包/类
@Override
public void putMetrics(MetricsRecord record) {
String hn = hostName;
String ctx = record.context();
String sn = serviceName;
for (MetricsTag tag : record.tags()) {
if (tag.info().name().equals(MsInfo.Hostname.name())
&& tag.value() != null) {
hn = tag.value();
} else if (tag.info().name().equals(MsInfo.Context.name())
&& tag.value() != null) {
ctx = tag.value();
} else if (tag.info().name().equals(MsInfo.ProcessName.name())
&& tag.value() != null) {
sn = tag.value();
}
}
StringBuilder buf = new StringBuilder();
if (!skipHostname && hn != null) {
int idx = hn.indexOf(".");
if (idx == -1) {
buf.append(hn).append(PERIOD);
} else {
buf.append(hn.substring(0, idx)).append(PERIOD);
}
}
buf.append(sn).append(PERIOD);
buf.append(ctx).append(PERIOD);
buf.append(record.name().replaceAll("\\.", "-")).append(PERIOD);
// Collect datapoints.
for (AbstractMetric metric : record.metrics()) {
String type = null;
if (metric.type().equals(MetricType.COUNTER)) {
type = "c";
} else if (metric.type().equals(MetricType.GAUGE)) {
type = "g";
}
StringBuilder line = new StringBuilder();
line.append(buf.toString())
.append(metric.name().replace(' ', '_'))
.append(":")
.append(metric.value())
.append("|")
.append(type);
writeMetric(line.toString());
}
}