【问题标题】:Sigar API for JAVA (need a guide)Sigar API for JAVA(需要指南)
【发布时间】:2012-09-20 11:47:23
【问题描述】:

我已下载 Sigar API (http://support.hyperic.com/display/SIGAR/Home),并希望在项目中使用它来获取有关正在运行的不同进程的信息。

我的问题是我真的找不到一些有用的代码 sn-ps 来学习,他们网站上的 javadoc 也没有多大帮助,因为我不知道我应该寻找什么。

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

【问题讨论】:

  • 我以前用过 SIGAR,觉得很简单。你能具体说明你在找什么吗? PTQL 文档页面与 javadoc 相结合对我来说似乎是一个不错的开始。
  • 因此,作为起点,我需要有关某个进程的处理器/内存使用情况的信息,例如 explorer.exe(示例)。
  • 这有点猜想,所以我不会发布这个作为回复;我认为你只是做 ProcMem pm = new ProcMem(); pm.gather(sigar, yourPid); pm.getsize()。带有 ProcTime 的 cpu 模拟。您可以使用 ProcessFinder 从 PTQL 表达式中查找 pid。

标签: java windows sigar


【解决方案1】:

要查找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

【讨论】:

  • 我正在尝试使用您所说的findSingleProcess("Exe.Name.ct=explorer");,但我收到此错误org.hyperic.sigar.SigarException: Query did not match any processes。正如我在任务管理器中看到的那样,explorer.exe 进程正在运行。
  • 你用的是什么操作系统?
【解决方案2】:

如果您使用的是 Windows 7,请尝试做一些事情

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

【讨论】:

    【解决方案3】:

    在他们最新的包中,他们在bindings\java\examples 下给出了很多使用示例。看看他们。

    【讨论】:

      【解决方案4】:

      hyperic 站点似乎消失了,但是这个https://layer4.fr/blog/2016/10/10/os-monitoring-with-java/ 告诉您如何将 Sigar 连接到 Java。您确实需要将 sigar-amd64-winnt.dll 文件放在 DLL 路径的某个位置(例如 C:\Windows)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-20
        • 2017-09-17
        相关资源
        最近更新 更多