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

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

Introduction

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

Prototype

public abstract MetricsRecordBuilder setContext(String value);

Source Link

Document

Set the context tag

Usage

From source file:com.github.joshelser.dropwizard.metrics.hadoop.HadoopMetrics2Reporter.java

License:Apache License

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder builder = collector.addRecord(recordName);
    if (null != context) {
        builder.setContext(context);
    }// w  ww.ja va  2s  .  c  o  m

    // Synchronizing here ensures that the dropwizard metrics collection side is excluded from executing
    // at the same time we are pulling elements from the queues.
    synchronized (this) {
        snapshotAllMetrics(builder);
    }

    metrics2Registry.snapshot(builder, all);
}

From source file:org.apache.calcite.dropwizard.metrics.hadoop.HadoopMetrics2Reporter.java

License:Apache License

@Override
public void getMetrics(MetricsCollector collector, boolean all) {
    MetricsRecordBuilder builder = collector.addRecord(recordName);
    if (null != context) {
        builder.setContext(context);
    }/*from   w  ww  .  ja va 2s . com*/

    snapshotAllMetrics(builder);

    metrics2Registry.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  ww w.ja  va  2 s .co  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>();
    }
}