簡體   English   中英

用於 JAVA 的 Sigar API(需要指南)

[英]Sigar API for JAVA (need a guide)

我已經下載了 Sigar API ( http://support.hyperic.com/display/SIGAR/Home ) 並希望在項目中使用它來獲取有關正在運行的不同進程的信息。

我的問題是我真的找不到一些有用的代碼片段來學習,而且他們網站上的 javadoc 沒有太大幫助,因為我不知道我應該尋找什么。

你有什么想法我可以找到更多信息嗎?

要查找pid (需要查找某個進程的信息),您可以使用ProcessFinder 查找單個進程 pid 的方法是findSingleProcess(String expression) 例子:

    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()));

表達式語法是這樣的:

Class.Attribute.operator=value

在哪里:

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

更多信息在這里: http : //support.hyperic.com/display/SIGAR/PTQL

如果您使用的是 Windows 7,請嘗試做一些事情

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

在他們最新的包中,他們在bindings\\java\\examples下給出了很多使用bindings\\java\\examples 去看一下。

hyperic 站點似乎不見了,但是這個https://layer4.fr/blog/2016/10/10/os-monitoring-with-java/告訴您如何將 Sigar 掛接到 Java。 您確實需要將 sigar-amd64-winnt.dll 文件放在 DLL 路徑上的某個位置(例如 C:\\Windows)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM