Class MetricsSystem

java.lang.Object
org.apache.hadoop.metrics2.MetricsSystem
All Implemented Interfaces:
MetricsSystemMXBean
Direct Known Subclasses:
MetricsSystemImpl

@Public @Evolving public abstract class MetricsSystem extends Object implements MetricsSystemMXBean
The metrics system interface. The following components are used for metrics. MetricsSource and MetricsSink register with the metrics system. Implementations of MetricsSystem polls the MetricsSources periodically and pass the MetricsRecords to MetricsSink.
  • Constructor Details

    • MetricsSystem

      public MetricsSystem()
  • Method Details

    • init

      @Private public abstract MetricsSystem init(String prefix)
    • register

      public abstract <T> T register(String name, String desc, T source)
      Register a metrics source
      Type Parameters:
      T - the actual type of the source object
      Parameters:
      source - object to register
      name - of the source. Must be unique or null (then extracted from the annotations of the source object.)
      desc - the description of the source (or null. See above.)
      Returns:
      the source object
      Throws:
      MetricsException - Metrics Exception.
    • unregisterSource

      public abstract void unregisterSource(String name)
      Unregister a metrics source
      Parameters:
      name - of the source. This is the name you use to call register()
    • register

      public <T> T register(T source)
      Register a metrics source (deriving name and description from the object)
      Type Parameters:
      T - the actual type of the source object
      Parameters:
      source - object to register
      Returns:
      the source object
      Throws:
      MetricsException - Metrics Exception.
    • getSource

      @Private public abstract MetricsSource getSource(String name)
      Parameters:
      name - of the metrics source
      Returns:
      the metrics source (potentially wrapped) object
    • register

      public abstract <T extends MetricsSink> T register(String name, String desc, T sink)
      Register a metrics sink
      Type Parameters:
      T - the type of the sink
      Parameters:
      sink - to register
      name - of the sink. Must be unique.
      desc - the description of the sink
      Returns:
      the sink
      Throws:
      MetricsException - Metrics Exception.
    • register

      public abstract void register(MetricsSystem.Callback callback)
      Register a callback interface for JMX events
      Parameters:
      callback - the callback object implementing the MBean interface.
    • publishMetricsNow

      public abstract void publishMetricsNow()
      Requests an immediate publish of all metrics from sources to sinks. This is a "soft" request: the expectation is that a best effort will be done to synchronously snapshot the metrics from all the sources and put them in all the sinks (including flushing the sinks) before returning to the caller. If this can't be accomplished in reasonable time it's OK to return to the caller before everything is done.
    • shutdown

      public abstract boolean shutdown()
      Shutdown the metrics system completely (usually during server shutdown.) The MetricsSystemMXBean will be unregistered.
      Returns:
      true if shutdown completed