org.hyperic.sigar.cmd.Df Maven / Gradle / Ivy
/*
* Copyright (c) 2006 Hyperic, Inc.
* Copyright (c) 2010 VMware, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hyperic.sigar.cmd;
import java.util.ArrayList;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.FileSystemMap;
import org.hyperic.sigar.FileSystemUsage;
import org.hyperic.sigar.NfsFileSystem;
import org.hyperic.sigar.shell.FileCompleter;
import org.hyperic.sigar.util.GetlineCompleter;
/**
* Report filesytem disk space usage.
*/
public class Df extends SigarCommandBase {
private static final String OUTPUT_FORMAT =
"%-15s %4s %4s %5s %4s %-15s %s";
//like df -h -a
private static final String[] HEADER = new String[] {
"Filesystem",
"Size",
"Used",
"Avail",
"Use%",
"Mounted on",
"Type"
};
//df -i
private static final String[] IHEADER = new String[] {
"Filesystem",
"Inodes",
"IUsed",
"IFree",
"IUse%",
"Mounted on",
"Type"
};
private GetlineCompleter completer;
private boolean opt_i;
public Df(Shell shell) {
super(shell);
setOutputFormat(OUTPUT_FORMAT);
this.completer = new FileCompleter(shell);
}
public Df() {
super();
setOutputFormat(OUTPUT_FORMAT);
}
public GetlineCompleter getCompleter() {
return this.completer;
}
protected boolean validateArgs(String[] args) {
return true;
}
public String getSyntaxArgs() {
return "[filesystem]";
}
public String getUsageShort() {
return "Report filesystem disk space usage";
}
public void printHeader() {
printf(this.opt_i ? IHEADER : HEADER);
}
public void output(String[] args) throws SigarException {
this.opt_i = false;
ArrayList sys = new ArrayList();
if (args.length > 0) {
FileSystemMap mounts = this.proxy.getFileSystemMap();
for (int i=0; i