add iostat command
This commit is contained in:
		
							parent
							
								
									60852cf91e
								
							
						
					
					
						commit
						aa0731c3b8
					
				
							
								
								
									
										110
									
								
								bindings/java/src/net/hyperic/sigar/cmd/Iostat.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								bindings/java/src/net/hyperic/sigar/cmd/Iostat.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,110 @@
 | 
			
		||||
package net.hyperic.sigar.cmd;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import net.hyperic.sigar.Sigar;
 | 
			
		||||
import net.hyperic.sigar.SigarException;
 | 
			
		||||
import net.hyperic.sigar.FileSystem;
 | 
			
		||||
import net.hyperic.sigar.FileSystemMap;
 | 
			
		||||
import net.hyperic.sigar.FileSystemUsage;
 | 
			
		||||
 | 
			
		||||
import net.hyperic.sigar.shell.FileCompleter;
 | 
			
		||||
import net.hyperic.sigar.util.GetlineCompleter;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Report filesytem disk space usage.
 | 
			
		||||
 */
 | 
			
		||||
public class Iostat extends SigarCommandBase {
 | 
			
		||||
 | 
			
		||||
    private static final String OUTPUT_FORMAT =
 | 
			
		||||
        "%-10s %-10s %-10s %-10s";
 | 
			
		||||
 | 
			
		||||
    //like df -h -a
 | 
			
		||||
    private static final String[] HEADER = new String[] {
 | 
			
		||||
        "Filesystem",
 | 
			
		||||
        "Mounted on",
 | 
			
		||||
        "Reads",
 | 
			
		||||
        "Writes",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    private GetlineCompleter completer;
 | 
			
		||||
 | 
			
		||||
    public Iostat(Shell shell) {
 | 
			
		||||
        super(shell);
 | 
			
		||||
        setOutputFormat(OUTPUT_FORMAT);
 | 
			
		||||
        this.completer = new FileCompleter(shell);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iostat() {
 | 
			
		||||
        super();
 | 
			
		||||
        setOutputFormat(OUTPUT_FORMAT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GetlineCompleter getCompleter() {
 | 
			
		||||
        return this.completer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean validateArgs(String[] args) {
 | 
			
		||||
        return args.length <= 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSyntaxArgs() {
 | 
			
		||||
        return "[filesystem]";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getUsageShort() {
 | 
			
		||||
        return "Report filesystem disk i/o";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void printHeader() {
 | 
			
		||||
        printf(HEADER);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void output(String[] args) throws SigarException {
 | 
			
		||||
        if (args.length == 1) {
 | 
			
		||||
            FileSystemMap mounts = this.proxy.getFileSystemMap();
 | 
			
		||||
            String name = FileCompleter.expand(args[0]);
 | 
			
		||||
            FileSystem fs = mounts.getMountPoint(name);
 | 
			
		||||
 | 
			
		||||
            if (fs != null) {
 | 
			
		||||
                printHeader();
 | 
			
		||||
                output(fs);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            throw new SigarException(args[0] +
 | 
			
		||||
                                     " No such file or directory");
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            FileSystem[] fslist = this.proxy.getFileSystemList();
 | 
			
		||||
            printHeader();
 | 
			
		||||
            for (int i=0; i<fslist.length; i++) {
 | 
			
		||||
                if (fslist[i].getType() == FileSystem.TYPE_LOCAL_DISK) {
 | 
			
		||||
                    output(fslist[i]);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void output(FileSystem fs) throws SigarException {
 | 
			
		||||
        FileSystemUsage usage =
 | 
			
		||||
            this.sigar.getFileSystemUsage(fs.getDirName());
 | 
			
		||||
 | 
			
		||||
        ArrayList items = new ArrayList();
 | 
			
		||||
 | 
			
		||||
        items.add(fs.getDevName());
 | 
			
		||||
        items.add(fs.getDirName());
 | 
			
		||||
        items.add(String.valueOf(usage.getDiskReads()));
 | 
			
		||||
        items.add(String.valueOf(usage.getDiskWrites()));
 | 
			
		||||
 | 
			
		||||
        printf(items);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static String formatSize(long size) {
 | 
			
		||||
        return Sigar.formatSize(size * 1024);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) throws Exception {
 | 
			
		||||
        new Iostat().processCommand(args);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -55,6 +55,7 @@ public class Shell extends ShellBase {
 | 
			
		||||
 | 
			
		||||
    public void registerCommands() throws ShellCommandInitException {
 | 
			
		||||
        registerCommandHandler("df", new Df(this));
 | 
			
		||||
        registerCommandHandler("iostat", new Iostat(this));
 | 
			
		||||
        registerCommandHandler("free", new Free(this));
 | 
			
		||||
        registerCommandHandler("pargs", new ShowArgs(this));
 | 
			
		||||
        registerCommandHandler("penv", new ShowEnv(this));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user