Skip to content

Instantly share code, notes, and snippets.

@ricston-git
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricston-git/8d2e63bb2f62c0ad65b1 to your computer and use it in GitHub Desktop.
Save ricston-git/8d2e63bb2f62c0ad65b1 to your computer and use it in GitHub Desktop.
//create a sigar object
Sigar sigar = new Sigar();
for (int i = 0; i < 100; i++) {
ProcessFinder find = new ProcessFinder(sigar);
//get the list of current java processes, and optionally query the list to choose which process to monitor
long[] pidList = sigar.getProcList();
//assuming we know the process id, we may query the process finder
long pid = find.findSingleProcess("Pid.Pid.eq=54730");
//get memory info for the process id
ProcMem memory = new ProcMem();
memory.gather(sigar, pid);
//get cou info for the oricess id
ProcCpu cpu = new ProcCpu();
cpu.gather(sigar, pid);
//print the memory used by the process id
System.out.println("Current memory used: " + Long.toString(memory.getSize()));
//print all memory info
System.out.println(memory.toMap());
//print all cpu info
System.out.println(cpu.toMap());
Thread.sleep(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment