use of org.apache.hadoop.metrics2.MetricsTag in project hadoop by apache.
the class GraphiteSink method putMetrics.
@Override
public void putMetrics(MetricsRecord record) {
StringBuilder lines = new StringBuilder();
StringBuilder metricsPathPrefix = new StringBuilder();
// Configure the hierarchical place to display the graph.
metricsPathPrefix.append(metricsPrefix).append(".").append(record.context()).append(".").append(record.name());
for (MetricsTag tag : record.tags()) {
if (tag.value() != null) {
metricsPathPrefix.append(".");
metricsPathPrefix.append(tag.name());
metricsPathPrefix.append("=");
metricsPathPrefix.append(tag.value());
}
}
// The record timestamp is in milliseconds while Graphite expects an epoc time in seconds.
long timestamp = record.timestamp() / 1000L;
// Collect datapoints.
for (AbstractMetric metric : record.metrics()) {
lines.append(metricsPathPrefix.toString() + "." + metric.name().replace(' ', '.')).append(" ").append(metric.value()).append(" ").append(timestamp).append("\n");
}
try {
graphite.write(lines.toString());
} catch (Exception e) {
LOG.warn("Error sending metrics to Graphite", e);
try {
graphite.close();
} catch (Exception e1) {
throw new MetricsException("Error closing connection to Graphite", e1);
}
}
}
use of org.apache.hadoop.metrics2.MetricsTag in project hadoop by apache.
the class MBeanInfoBuilder method get.
MBeanInfo get() {
curRecNo = 0;
for (MetricsRecordImpl rec : recs) {
for (MetricsTag t : rec.tags()) {
attrs.add(newAttrInfo("tag." + t.name(), t.description(), "java.lang.String"));
}
for (AbstractMetric m : rec.metrics()) {
m.visit(this);
}
++curRecNo;
}
MetricsSystemImpl.LOG.debug(attrs);
MBeanAttributeInfo[] attrsArray = new MBeanAttributeInfo[attrs.size()];
return new MBeanInfo(name, description, attrs.toArray(attrsArray), null, null, // no ops/ctors/notifications
null);
}
use of org.apache.hadoop.metrics2.MetricsTag in project hadoop by apache.
the class DataNodeMetricHelper method getMetrics.
/**
* Get metrics helper provides Helper function for
* metrics2 interface to act as a Metric source
*
* @param collector Metrics Collector that is passed in
* @param beanClass The Class that currently impliments the metric functions
* @param context A string that idenitifies the context
*
* @throws IOException
*/
public static void getMetrics(MetricsCollector collector, FSDatasetMBean beanClass, String context) throws IOException {
if (beanClass == null) {
throw new IOException("beanClass cannot be null");
}
String className = beanClass.getClass().getName();
collector.addRecord(className).setContext(context).addGauge(Interns.info("Capacity", "Total storage capacity"), beanClass.getCapacity()).addGauge(Interns.info("DfsUsed", "Total bytes used by dfs datanode"), beanClass.getDfsUsed()).addGauge(Interns.info("Remaining", "Total bytes of free storage"), beanClass.getRemaining()).add(new MetricsTag(Interns.info("StorageInfo", "Storage ID"), beanClass.getStorageInfo())).addGauge(Interns.info("NumFailedVolumes", "Number of failed Volumes" + " in the data Node"), beanClass.getNumFailedVolumes()).addGauge(Interns.info("LastVolumeFailureDate", "Last Volume failure in" + " milliseconds from epoch"), beanClass.getLastVolumeFailureDate()).addGauge(Interns.info("EstimatedCapacityLostTotal", "Total capacity lost" + " due to volume failure"), beanClass.getEstimatedCapacityLostTotal()).addGauge(Interns.info("CacheUsed", "Datanode cache used in bytes"), beanClass.getCacheUsed()).addGauge(Interns.info("CacheCapacity", "Datanode cache capacity"), beanClass.getCacheCapacity()).addGauge(Interns.info("NumBlocksCached", "Datanode number" + " of blocks cached"), beanClass.getNumBlocksCached()).addGauge(Interns.info("NumBlocksFailedToCache", "Datanode number of " + "blocks failed to cache"), beanClass.getNumBlocksFailedToCache()).addGauge(Interns.info("NumBlocksFailedToUnCache", "Datanode number of" + " blocks failed in cache eviction"), beanClass.getNumBlocksFailedToUncache());
}
use of org.apache.hadoop.metrics2.MetricsTag in project hadoop by apache.
the class TestMetricsSourceAdapter method testGetMetricsAndJmx.
@Test
public void testGetMetricsAndJmx() throws Exception {
// create test source with a single metric counter of value 0
TestSource source = new TestSource("test");
MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(source);
final MetricsSource s = sb.build();
List<MetricsTag> injectedTags = new ArrayList<MetricsTag>();
MetricsSourceAdapter sa = new MetricsSourceAdapter("test", "test", "test desc", s, injectedTags, null, null, 1, false);
// all metrics are initially assumed to have changed
MetricsCollectorImpl builder = new MetricsCollectorImpl();
Iterable<MetricsRecordImpl> metricsRecords = sa.getMetrics(builder, true);
// Validate getMetrics and JMX initial values
MetricsRecordImpl metricsRecord = metricsRecords.iterator().next();
assertEquals(0L, metricsRecord.metrics().iterator().next().value().longValue());
// skip JMX cache TTL
Thread.sleep(100);
assertEquals(0L, (Number) sa.getAttribute("C1"));
// change metric value
source.incrementCnt();
// validate getMetrics and JMX
builder = new MetricsCollectorImpl();
metricsRecords = sa.getMetrics(builder, true);
metricsRecord = metricsRecords.iterator().next();
assertTrue(metricsRecord.metrics().iterator().hasNext());
// skip JMX cache TTL
Thread.sleep(100);
assertEquals(1L, (Number) sa.getAttribute("C1"));
}
use of org.apache.hadoop.metrics2.MetricsTag in project hadoop by apache.
the class TestMetricsSystemImpl method checkMetricsRecords.
private void checkMetricsRecords(List<MetricsRecord> recs) {
LOG.debug(recs);
MetricsRecord r = recs.get(0);
assertEquals("name", "s1rec", r.name());
assertEquals("tags", new MetricsTag[] { tag(MsInfo.Context, "test"), tag(MsInfo.Hostname, hostname) }, r.tags());
assertEquals("metrics", MetricsLists.builder("").addCounter(info("C1", "C1 desc"), 1L).addGauge(info("G1", "G1 desc"), 2L).addCounter(info("S1NumOps", "Number of ops for s1"), 1L).addGauge(info("S1AvgTime", "Average time for s1"), 0.0).metrics(), r.metrics());
r = recs.get(1);
assertTrue("NumActiveSinks should be 3", Iterables.contains(r.metrics(), new MetricGaugeInt(MsInfo.NumActiveSinks, 3)));
}
Aggregations