Example usage for org.apache.hadoop.metrics2 MetricsRecordBuilder add

List of usage examples for org.apache.hadoop.metrics2 MetricsRecordBuilder add

Introduction

In this page you can find the example usage for org.apache.hadoop.metrics2 MetricsRecordBuilder add.

Prototype

public abstract MetricsRecordBuilder add(AbstractMetric metric);

Source Link

Document

Add a pre-made immutable metric object

Usage

From source file:com.alibaba.wasp.metrics.DynamicMetricsRegistry.java

License:Apache License

/**
 * Sample all the mutable metrics and put the snapshot in the builder
 * @param builder to contain the metrics snapshot
 * @param all get all the metrics even if the values are not changed.
 *///  www.j a v a2  s  .com
public void snapshot(MetricsRecordBuilder builder, boolean all) {

    for (Entry<String, MetricsTag> entry : tags()) {
        builder.add(entry.getValue());
    }
    for (Entry<String, MetricMutable> entry : metrics()) {
        entry.getValue().snapshot(builder, all);
    }
}

From source file:org.apache.phoenix.trace.TraceMetricSource.java

License:Apache License

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    // add a marker record so we know how many spans are used
    // this is also necessary to ensure that we register the metrics source as an MBean (avoiding a
    // runtime warning)
    MetricsRecordBuilder marker = collector.addRecord(TracingUtils.METRICS_MARKER_CONTEXT);
    marker.add(new MetricsTag(new MetricsInfoImpl("stat", "num spans"), Integer.toString(spans.size())));

    // actually convert the known spans into metric records as well
    synchronized (this) {
        for (Metric span : spans) {
            MetricsRecordBuilder builder = collector
                    .addRecord(new MetricsInfoImpl(TracingUtils.getTraceMetricName(span.id), span.desc));
            builder.setContext(TracingUtils.METRICS_CONTEXT);
            for (Pair<MetricsInfo, Long> metric : span.counters) {
                builder.addCounter(metric.getFirst(), metric.getSecond());
            }//from  w  w  w.j  av  a2  s.  c o m
            for (MetricsTag tag : span.tags) {
                builder.add(tag);
            }
        }
        // reset the spans so we don't keep a big chunk of memory around
        spans = new ArrayList<Metric>();
    }
}