Sigar API for JAVA (need a guide)

不打扰是莪最后的温柔 提交于 2019-12-05 11:05:59

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

joseporto

If you are using Windows 7 try doing something

likefindSingleProcess("State.Name.ct=explorer");

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

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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!