java.lang.Object
org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics
All Implemented Interfaces:
org.apache.hadoop.metrics2.MetricsSource

@Private public class TopMetrics extends Object implements org.apache.hadoop.metrics2.MetricsSource
The interface to the top metrics.

Metrics are collected by a custom audit logger, .hdfs.server.namenode.top.TopAuditLogger, which calls TopMetrics to increment per-operation, per-user counts on every audit log call. These counts are used to show the top users by NameNode operation as well as across all operations.

TopMetrics maintains these counts for a configurable number of time intervals, e.g. 1min, 5min, 25min. Each interval is tracked by a RollingWindowManager.

These metrics are published as a JSON string via .hdfs.server .namenode.metrics.FSNamesystemMBean#getTopWindows. This is done by calling .RollingWindowManager#snapshot on each RollingWindowManager.

Thread-safe: relies on thread-safety of RollingWindowManager

  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
    • TOPMETRICS_METRICS_SOURCE_NAME

      public static final String TOPMETRICS_METRICS_SOURCE_NAME
      See Also:
  • Constructor Details

    • TopMetrics

      public TopMetrics(org.apache.hadoop.conf.Configuration conf, int[] reportingPeriods)
  • Method Details

    • getTopWindows

      public List<RollingWindowManager.TopWindow> getTopWindows()
      Get a list of the current TopWindow statistics, one TopWindow per tracked time interval.
    • report

      public void report(boolean succeeded, String userName, InetAddress addr, String cmd, String src, String dst, org.apache.hadoop.fs.FileStatus status)
      Pick the same information that DefaultAuditLogger does before writing to a log file. This is to be consistent when TopMetrics is charged with data read back from log files instead of being invoked directly by the FsNamesystem
      Parameters:
      succeeded -
      userName -
      addr -
      cmd -
      src -
      dst -
      status -
    • report

      public void report(String userName, String cmd)
    • report

      public void report(long currTime, String userName, String cmd)
    • getMetrics

      public void getMetrics(org.apache.hadoop.metrics2.MetricsCollector collector, boolean all)
      Flatten out the top window metrics into MetricsRecords for consumption by external metrics systems. Each metrics record added corresponds to the reporting period a.k.a window length of the configured rolling windows.
      Specified by:
      getMetrics in interface org.apache.hadoop.metrics2.MetricsSource
      Parameters:
      collector -
      all -