Example usage for org.apache.hadoop.metrics2 MetricsSystem register

List of usage examples for org.apache.hadoop.metrics2 MetricsSystem register

Introduction

In this page you can find the example usage for org.apache.hadoop.metrics2 MetricsSystem register.

Prototype

public abstract <T extends MetricsSink> T register(String name, String desc, T sink);

Source Link

Document

Register a metrics sink

Usage

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

License:Apache License

public static void main(String[] args) throws Exception {
    final MetricRegistry metrics = new MetricRegistry();

    final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metrics).build(
            DefaultMetricsSystem.initialize("StandaloneTest"), // The application-level name
            "Test", // Component name
            "Test", // Component description
            "Test"); // Name for each metric record
    final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metrics).build();

    MetricsSystem metrics2 = DefaultMetricsSystem.instance();
    // Writes to stdout without a filename configuration
    // Will be invoked every 10seconds by default
    FileSink sink = new FileSink();
    metrics2.register("filesink", "filesink", sink);
    sink.init(new SubsetConfiguration(null, null) {
        public String getString(String key) {
            if (key.equals("filename")) {
                return null;
            }//from  w  w w  .j  av a2s.c  om
            return super.getString(key);
        }
    });

    // How often should the dropwizard reporter be invoked
    metrics2Reporter.start(500, TimeUnit.MILLISECONDS);
    // How often will the dropwziard metrics be logged to the console
    consoleReporter.start(2, TimeUnit.SECONDS);

    generateMetrics(metrics, 5000, 25, TimeUnit.MILLISECONDS, metrics2Reporter, 10);
}

From source file:com.twitter.hraven.hadoopJobMonitor.metrics.HadoopJobMonitorMetrics.java

License:Apache License

static HadoopJobMonitorMetrics create(Configuration conf) {
    MetricsSystem ms = DefaultMetricsSystem.instance();

    HadoopJobMonitorMetrics metricObject = new HadoopJobMonitorMetrics();
    MetricsSourceBuilder sb = MetricsAnnotations.newSourceBuilder(metricObject);
    final MetricsSource s = sb.build();
    ms.register("HadoopJobMonitorMetrics", "The Metrics of HadoopJobMonitor service", s);

    ScheduledExecutorService heartbeatExecutor = Executors
            .newSingleThreadScheduledExecutor(new SimpleThreadFactory());
    heartbeatExecutor.scheduleAtFixedRate(metricObject.new Heart(), 0, 1, TimeUnit.MINUTES);
    return metricObject;
}

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

License:Apache License

public TraceMetricSource() {

    MetricsSystem manager = Metrics.initialize();

    // Register this instance.
    // For right now, we ignore the MBean registration issues that show up in DEBUG logs. Basically,
    // we need a Jmx MBean compliant name. We'll get to a better name when we want that later
    manager.register(CONTEXT, "Phoenix call tracing", this);
}