public static Sigar getSigar() { return new Sigar(); }
public void output(String[] args) throws SigarException { String query = args[0]; MultiProcCpu cpu = this.proxy.getMultiProcCpu(query); println("Number of processes: " + cpu.getProcesses()); println("Cpu usage: " + CpuPerc.format(cpu.getPercent())); println("Cpu time: " + Ps.getCpuTime(cpu.getTotal())); ProcMem mem = this.proxy.getMultiProcMem(query); println("Size: " + Sigar.formatSize(mem.getSize())); println("Resident: " + Sigar.formatSize(mem.getResident())); println("Share: " + Sigar.formatSize(mem.getShare())); }
private SwapStats() { try { Swap swap = sigar.getSwap(); this.prevPageIn = swap.getPageIn(); this.prevPageOut = swap.getPageOut(); } catch (SigarException e) { log.error(e, "Failed to get Swap"); } }
@Override Swap loadSnapshot(Sigar sigar) throws SigarException { return sigar.getSwap(); }
private String getFirstMountPoint() throws SigarException { @SuppressWarnings("unchecked") final Set<Map.Entry<String, FileSystem>> entries = (Set<Map.Entry<String, FileSystem>>) sigar.getFileSystemMap().entrySet(); for (Map.Entry<String, FileSystem> e : entries) { if (e.getValue().getType() == FileSystem.TYPE_LOCAL_DISK) { return e.getKey(); } } throw new IllegalStateException("No mount point found"); }
@Override NetInterfaceStat loadSnapshot(Sigar sigar) throws SigarException { return sigar.getNetInterfaceStat(ifname); } }
@Override public void onShutDown() { if (sigar != null) { sigar.close(); sigar = null; } }
public void output(String[] args) throws SigarException { String dir = args[0]; DirUsage du = this.sigar.getDirUsage(dir); println(du.getDiskUsage() + "\t" + dir); }
@Override FileSystemUsage loadSnapshot(Sigar sigar) throws SigarException { return sigar.getFileSystemUsage(mountpoint); } }
@Override CpuPerc loadSnapshot(Sigar sigar) throws SigarException { return sigar.getCpuPerc(); }
public void outputFileSystem(String arg) throws SigarException { FileSystemMap mounts = this.proxy.getFileSystemMap(); String name = FileCompleter.expand(arg); FileSystem fs = mounts.getMountPoint(name); if (fs != null) { printHeader(); output(fs); return; } throw new SigarException(arg + " No such file or directory"); }
private static String toString(ProcStat stat) { return stat.getTotal() + " processes: " + stat.getSleeping() + " sleeping, " + stat.getRunning() + " running, " + stat.getZombie() + " zombie, " + stat.getStopped() + " stopped... " + stat.getThreads() + " threads"; }
@Override public Integer getValue() { return cpuInfo.getTotalCores(); } });
private int getCpuCore() { try { return sigar.getCpuList().length; } catch (SigarException e) { return 1; } } public static void main(String[] args) throws SigarException {
@Override public Integer getValue() { return cpuInfo.getMhz(); } });
@Override public Long getValue() { return cpuInfo.getCacheSize(); } });
public void onException(FileInfo info, SigarException e) { System.out.println("Error checking " + info.getName() + ":"); e.printStackTrace(); } };
private int getCpuCore() { try { return sigar.getCpuList().length; } catch (SigarException e) { return 1; } } }
public String getUserDeniedMessage(long pid) { return SigarPermissionDeniedException.getUserDeniedMessage(this.proxy, pid); }