use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class MetricsRecords method assertTag.
public static void assertTag(MetricsRecord record, String tagName, String expectedValue) {
MetricsTag processIdTag = getFirstTagByName(record, tagName);
assertNotNull(processIdTag);
assertEquals(expectedValue, processIdTag.value());
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class TestGraphiteMetrics method testPutMetrics2.
@Test
public void testPutMetrics2() {
GraphiteSink sink = new GraphiteSink();
List<MetricsTag> tags = new ArrayList<MetricsTag>();
tags.add(new MetricsTag(MsInfo.Context, "all"));
tags.add(new MetricsTag(MsInfo.Hostname, null));
Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
metrics.add(makeMetric("foo1", 1));
metrics.add(makeMetric("foo2", 2));
MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
final GraphiteSink.Graphite mockGraphite = makeGraphite();
Whitebox.setInternalState(sink, "graphite", mockGraphite);
sink.putMetrics(record);
try {
verify(mockGraphite).write(argument.capture());
} catch (IOException e) {
e.printStackTrace();
}
String result = argument.getValue();
assertEquals(true, result.equals("null.all.Context.Context=all.foo1 1 10\n" + "null.all.Context.Context=all.foo2 2 10\n") || result.equals("null.all.Context.Context=all.foo2 2 10\n" + "null.all.Context.Context=all.foo1 1 10\n"));
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class TestMetricsCache method testGet.
@SuppressWarnings("deprecation")
@Test
public void testGet() {
MetricsCache cache = new MetricsCache();
assertNull("empty", cache.get("r", Arrays.asList(makeTag("t", "t"))));
MetricsRecord mr = makeRecord("r", Arrays.asList(makeTag("t", "t")), Arrays.asList(makeMetric("m", 1)));
cache.update(mr);
MetricsCache.Record cr = cache.get("r", mr.tags());
LOG.debug("tags=" + mr.tags() + " cr=" + cr);
assertNotNull("Got record", cr);
assertEquals("contains 1 metric", 1, cr.metrics().size());
checkMetricValue("new metric value", cr, "m", 1);
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class TestMetricsCache method testUpdate.
@SuppressWarnings("deprecation")
@Test
public void testUpdate() {
MetricsCache cache = new MetricsCache();
MetricsRecord mr = makeRecord("r", Arrays.asList(makeTag("t", "tv")), Arrays.asList(makeMetric("m", 0), makeMetric("m1", 1)));
MetricsCache.Record cr = cache.update(mr);
verify(mr).name();
verify(mr).tags();
verify(mr).metrics();
assertEquals("same record size", cr.metrics().size(), ((Collection<AbstractMetric>) mr.metrics()).size());
assertEquals("same metric value", 0, cr.getMetric("m"));
MetricsRecord mr2 = makeRecord("r", Arrays.asList(makeTag("t", "tv")), Arrays.asList(makeMetric("m", 2), makeMetric("m2", 42)));
cr = cache.update(mr2);
assertEquals("contains 3 metric", 3, cr.metrics().size());
checkMetricValue("updated metric value", cr, "m", 2);
checkMetricValue("old metric value", cr, "m1", 1);
checkMetricValue("new metric value", cr, "m2", 42);
MetricsRecord mr3 = makeRecord("r", // different tag value
Arrays.asList(makeTag("t", "tv3")), Arrays.asList(makeMetric("m3", 3)));
// should get a new record
cr = cache.update(mr3);
assertEquals("contains 1 metric", 1, cr.metrics().size());
checkMetricValue("updated metric value", cr, "m3", 3);
// tags cache should be empty so far
assertEquals("no tags", 0, cr.tags().size());
// until now
cr = cache.update(mr3, true);
assertEquals("Got 1 tag", 1, cr.tags().size());
assertEquals("Tag value", "tv3", cr.getTag("t"));
checkMetricValue("Metric value", cr, "m3", 3);
}
use of org.apache.hadoop.metrics2.util.MetricsCache.Record in project hadoop by apache.
the class GangliaSink30 method appendPrefix.
@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())) {
if (t.info() != MsInfo.Context && t.info() != MsInfo.Hostname && t.value() != null) {
sb.append('.').append(t.name()).append('=').append(t.value());
}
}
}
}
}
Aggregations