Search in sources :

Example 1 with TopMetrics

use of org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics in project hadoop by apache.

the class FSNamesystem method initAuditLoggers.

private List<AuditLogger> initAuditLoggers(Configuration conf) {
    // Initialize the custom access loggers if configured.
    Collection<String> alClasses = conf.getTrimmedStringCollection(DFS_NAMENODE_AUDIT_LOGGERS_KEY);
    List<AuditLogger> auditLoggers = Lists.newArrayList();
    if (alClasses != null && !alClasses.isEmpty()) {
        for (String className : alClasses) {
            try {
                AuditLogger logger;
                if (DFS_NAMENODE_DEFAULT_AUDIT_LOGGER_NAME.equals(className)) {
                    logger = new DefaultAuditLogger();
                } else {
                    logger = (AuditLogger) Class.forName(className).newInstance();
                }
                logger.initialize(conf);
                auditLoggers.add(logger);
            } catch (RuntimeException re) {
                throw re;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    // Make sure there is at least one logger installed.
    if (auditLoggers.isEmpty()) {
        auditLoggers.add(new DefaultAuditLogger());
    }
    // Add audit logger to calculate top users
    if (topConf.isEnabled) {
        topMetrics = new TopMetrics(conf, topConf.nntopReportingPeriodsMs);
        if (DefaultMetricsSystem.instance().getSource(TOPMETRICS_METRICS_SOURCE_NAME) == null) {
            DefaultMetricsSystem.instance().register(TOPMETRICS_METRICS_SOURCE_NAME, "Top N operations by user", topMetrics);
        }
        auditLoggers.add(new TopAuditLogger(topMetrics));
    }
    return Collections.unmodifiableList(auditLoggers);
}
Also used : TopAuditLogger(org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger) TopAuditLogger(org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger) TopMetrics(org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics) AlreadyBeingCreatedException(org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException) InvalidPathException(org.apache.hadoop.fs.InvalidPathException) StandbyException(org.apache.hadoop.ipc.StandbyException) IOException(java.io.IOException) RecoveryInProgressException(org.apache.hadoop.hdfs.protocol.RecoveryInProgressException) SnapshotException(org.apache.hadoop.hdfs.protocol.SnapshotException) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RetriableException(org.apache.hadoop.ipc.RetriableException) UnknownCryptoProtocolVersionException(org.apache.hadoop.hdfs.UnknownCryptoProtocolVersionException) UnresolvedLinkException(org.apache.hadoop.fs.UnresolvedLinkException) FileNotFoundException(java.io.FileNotFoundException) ServiceFailedException(org.apache.hadoop.ha.ServiceFailedException) RollingUpgradeException(org.apache.hadoop.hdfs.protocol.RollingUpgradeException) AccessControlException(org.apache.hadoop.security.AccessControlException) SnapshotAccessControlException(org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException)

Example 2 with TopMetrics

use of org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics in project hadoop by apache.

the class TestTopMetrics method testPresence.

@Test
public void testPresence() {
    Configuration conf = new Configuration();
    TopConf topConf = new TopConf(conf);
    TopMetrics topMetrics = new TopMetrics(conf, topConf.nntopReportingPeriodsMs);
    // Dummy command
    topMetrics.report("test", "listStatus");
    topMetrics.report("test", "listStatus");
    topMetrics.report("test", "listStatus");
    MetricsRecordBuilder rb = getMetrics(topMetrics);
    MetricsCollector mc = rb.parent();
    verify(mc).addRecord(TOPMETRICS_METRICS_SOURCE_NAME + ".windowMs=60000");
    verify(mc).addRecord(TOPMETRICS_METRICS_SOURCE_NAME + ".windowMs=300000");
    verify(mc).addRecord(TOPMETRICS_METRICS_SOURCE_NAME + ".windowMs=1500000");
    verify(rb, times(3)).addCounter(Interns.info("op=listStatus.TotalCount", "Total operation count"), 3L);
    verify(rb, times(3)).addCounter(Interns.info("op=*.TotalCount", "Total operation count"), 3L);
    verify(rb, times(3)).addCounter(Interns.info("op=listStatus." + "user=test.count", "Total operations performed by user"), 3L);
}
Also used : MetricsCollector(org.apache.hadoop.metrics2.MetricsCollector) Configuration(org.apache.hadoop.conf.Configuration) TopMetrics(org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics) TopConf(org.apache.hadoop.hdfs.server.namenode.top.TopConf) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Test(org.junit.Test)

Aggregations

TopMetrics (org.apache.hadoop.hdfs.server.namenode.top.metrics.TopMetrics)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 HadoopIllegalArgumentException (org.apache.hadoop.HadoopIllegalArgumentException)1 Configuration (org.apache.hadoop.conf.Configuration)1 InvalidPathException (org.apache.hadoop.fs.InvalidPathException)1 UnresolvedLinkException (org.apache.hadoop.fs.UnresolvedLinkException)1 ServiceFailedException (org.apache.hadoop.ha.ServiceFailedException)1 UnknownCryptoProtocolVersionException (org.apache.hadoop.hdfs.UnknownCryptoProtocolVersionException)1 AlreadyBeingCreatedException (org.apache.hadoop.hdfs.protocol.AlreadyBeingCreatedException)1 RecoveryInProgressException (org.apache.hadoop.hdfs.protocol.RecoveryInProgressException)1 RollingUpgradeException (org.apache.hadoop.hdfs.protocol.RollingUpgradeException)1 SnapshotAccessControlException (org.apache.hadoop.hdfs.protocol.SnapshotAccessControlException)1 SnapshotException (org.apache.hadoop.hdfs.protocol.SnapshotException)1 TopAuditLogger (org.apache.hadoop.hdfs.server.namenode.top.TopAuditLogger)1 TopConf (org.apache.hadoop.hdfs.server.namenode.top.TopConf)1 RetriableException (org.apache.hadoop.ipc.RetriableException)1 StandbyException (org.apache.hadoop.ipc.StandbyException)1 MetricsCollector (org.apache.hadoop.metrics2.MetricsCollector)1