Sigar API for JAVA (need a guide)

2019-05-03 09:27发布

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?

3条回答
别忘想泡老子
2楼-- · 2019-05-03 10:07

If you are using Windows 7 try doing something

likefindSingleProcess("State.Name.ct=explorer");
查看更多
地球回转人心会变
3楼-- · 2019-05-03 10:30

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: http://support.hyperic.com/display/SIGAR/PTQL

查看更多
爷的心禁止访问
4楼-- · 2019-05-03 10:34

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

查看更多
登录 后发表回答