Sigar API for JAVA (need a guide)
Asked Answered
N

4

5

I've downloaded Sigar API ( http://support.hyperic.com/display/SIGAR/Home ) and would like to use it in a project to get information about different processes which are running.

My problem is that I can't really find some useful code snippets to learn from and the javadoc from their website isn't of much help, because I don't know what I should be looking for.

Do you have any ideea where I could find more information?

Nonlegal answered 20/9, 2012 at 11:47 Comment(3)
I used SIGAR before, and found it quite easy. Can you specify exactly what you're looking for? The PTQL doc page combines with the javadoc seems a pretty good start to me.Tarry
So, as a starting point, I need the information about proccessor/memory usage for a certain process, like explorer.exe (example).Nonlegal
This is a bit of a guess, so I won't post this as a reply; I think you just do ProcMem pm = new ProcMem(); pm.gather(sigar, yourPid); pm.getsize(). Analog for cpu with ProcTime. You can use ProcessFinder to find a pid from a PTQL expression.Tarry
N
11

To find the pid (which is needed to find out information about a certain process), you can use a ProcessFinder. The method to find a single process pid is findSingleProcess(String expression). Example:

    Sigar sigar=new Sigar();
    ProcessFinder find=new ProcessFinder(sigar);
    long pid=find.findSingleProcess("Exe.Name.ct=explorer");
    ProcMem memory=new ProcMem();
    memory.gather(sigar, pid);
    System.out.println(Long.toString(memory.getSize()));

The expression syntax is this:

Class.Attribute.operator=value

Where:

Class is the name of the Sigar class minus the Proc prefix.
Attribute is an attribute of the given Class, index into an array or key in a Map class.
operator is one of the following for String values:
eq - Equal to value
ne - Not Equal to value
ew - Ends with value
sw - Starts with value
ct - Contains value (substring)
re - Regular expression value matches
operator is one of the following for numeric values:
eq - Equal to value
ne - Not Equal to value
gt - Greater than value
ge - Greater than or equal value
lt - Less than value
le - Less than or equal value

More info here through the wayback machine: https://web.archive.org/web/20170201073935/http://support.hyperic.com/display/SIGAR/PTQL

Nonlegal answered 21/9, 2012 at 9:51 Comment(3)
I am trying to use findSingleProcess("Exe.Name.ct=explorer"); as you say and I'm getting this error org.hyperic.sigar.SigarException: Query did not match any processes. And the explorer.exe process is running as I can see in the Task manager.Alfredalfreda
what OS are you using?Nonlegal
The documentation site can only be accessed though wayback machine now: web.archive.org/web/20170201073935/http://support.hyperic.com/…Cilium
U
2

If you are using Windows 7 try doing something

likefindSingleProcess("State.Name.ct=explorer");
Unique answered 19/3, 2014 at 14:26 Comment(0)
S
0

In their latest package, they give a lot of usage examples under bindings\java\examples. Check them out.

Shift answered 11/10, 2013 at 7:35 Comment(0)
N
0

The hyperic site seems to be gone, but this https://layer4.fr/blog/2016/10/10/os-monitoring-with-java/ tells you how to hook Sigar to Java. You do need to put the sigar-amd64-winnt.dll file somewhere on the DLL path (e.g. C:\Windows)

Nelsen answered 14/11, 2019 at 23:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.