public static long[] getPids(SigarProxy sigar, String[] args) throws SigarException { long[] pids; switch (args.length) { case 0: pids = new long[] { sigar.getPid() }; break; case 1: if (args[0].indexOf("=") > 0) { pids = ProcessFinder.find(sigar, args[0]); } else if (args[0].equals("$$")) { pids = new long[] { sigar.getPid() }; } else { pids = new long[] { Long.parseLong(args[0]) }; } break; default: pids = new long[args.length]; for (int i=0; i<args.length; i++) { pids[i] = Long.parseLong(args[i]); } break; } return pids; }
@Override public Collection<Long> findTargets() { return Collections.singleton(getSigar().getPid()); } }
public ProcessInfo getThisProcess() { long self = sigar.getPid(); ProcessInfo info = new ProcessInfo(self); return info; }
public ProcessInfo getThisProcess() { long self = sigar.getPid(); ProcessInfo info = new ProcessInfo(self); return info; }
private String findPid() { final String name = ManagementFactory.getRuntimeMXBean().getName(); final int i = name.indexOf("@"); return i > 0 ? name.substring(0, i) : Long.toString(SystemInstance.get().getComponent(SigarProxy.class).getPid()) /* not used primarily to work on windows */; }
@Check public ProcessEvent getProcess() { final SigarProxy sigar = SystemInstance.get().getComponent(SigarProxy.class); if (sigar == null) { return null; } try { final ProcStat procStat = sigar.getProcStat(); final Process process = Process.builder() .withIdle(procStat.getIdle()) .withRunning(procStat.getRunning()) .withSleeping(procStat.getSleeping()) .withStopped(procStat.getStopped()) .withThreads(procStat.getThreads()) .withTotal(procStat.getTotal()) .withZombie(procStat.getZombie()).build(); return ProcessEvent.of(process, Long.toString(sigar.getPid())); } catch (final SigarException e) { LOGGER.log(LOG_LEVEL, "Error getting process metrics from Sigar", e); } return null; }
public static SystemSnapshot snapshot(final SigarProxy sigar) { final SystemSnapshot systemSnapshot = new SystemSnapshot(); systemSnapshot.setPid(sigar.getPid()); try { systemSnapshot.setUptime(sigar.getUptime().getUptime());