Example usage for org.apache.hadoop.fs FileSystem getUsed

List of usage examples for org.apache.hadoop.fs FileSystem getUsed

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileSystem getUsed.

Prototype

public long getUsed() throws IOException 

Source Link

Document

Return the total size of all files in the filesystem.

Usage

From source file:org.apache.accumulo.server.monitor.servlets.DefaultServlet.java

License:Apache License

private void doAccumuloTable(StringBuilder sb) throws IOException {
    // Accumulo// w  w w  . j  a va  2  s  . c o m
    Configuration conf = CachedConfiguration.getInstance();
    FileSystem fs = TraceFileSystem
            .wrap(FileUtil.getFileSystem(conf, ServerConfiguration.getSiteConfiguration()));
    MasterMonitorInfo info = Monitor.getMmi();
    sb.append("<table>\n");
    sb.append("<tr><th colspan='2'><a href='/master'>Accumulo Master</a></th></tr>\n");
    if (info == null) {
        sb.append("<tr><td colspan='2'><span class='error'>Master is Down</span></td></tr>\n");
    } else {
        String consumed = "Unknown";
        String diskUsed = "Unknown";
        try {
            Path path = new Path(Monitor.getSystemConfiguration().get(Property.INSTANCE_DFS_DIR));
            log.debug("Reading the content summary for " + path);
            try {
                ContentSummary acu = fs.getContentSummary(path);
                ContentSummary rootSummary = fs.getContentSummary(new Path("/"));
                consumed = String.format("%.2f%%",
                        acu.getSpaceConsumed() * 100. / rootSummary.getSpaceConsumed());
                diskUsed = bytes(acu.getSpaceConsumed());
            } catch (Exception ex) {
                log.trace("Unable to get disk usage information from hdfs", ex);
            }

            boolean highlight = false;
            tableRow(sb, (highlight = !highlight), "Disk&nbsp;Used", diskUsed);
            if (fs.getUsed() != 0)
                tableRow(sb, (highlight = !highlight), "%&nbsp;of&nbsp;Used&nbsp;DFS", consumed);
            tableRow(sb, (highlight = !highlight), "<a href='/tables'>Tables</a>",
                    NumberType.commas(Monitor.getTotalTables()));
            tableRow(sb, (highlight = !highlight), "<a href='/tservers'>Tablet&nbsp;Servers</a>",
                    NumberType.commas(info.tServerInfo.size(), 1, Long.MAX_VALUE));
            tableRow(sb, (highlight = !highlight), "<a href='/tservers'>Dead&nbsp;Tablet&nbsp;Servers</a>",
                    NumberType.commas(info.deadTabletServers.size(), 0, 0));
            tableRow(sb, (highlight = !highlight), "Tablets",
                    NumberType.commas(Monitor.getTotalTabletCount(), 1, Long.MAX_VALUE));
            tableRow(sb, (highlight = !highlight), "Entries", NumberType.commas(Monitor.getTotalEntries()));
            tableRow(sb, (highlight = !highlight), "Lookups", NumberType.commas(Monitor.getTotalLookups()));
            tableRow(sb, (highlight = !highlight), "Uptime",
                    Duration.format(System.currentTimeMillis() - Monitor.getStartTime()));
        } catch (Exception e) {
            log.debug(e, e);
        }
    }
    sb.append("</table>\n");
}