我正在使用SIAGR API来计算CPU使用量,但是当使用负载运行程序测试它时,会得到异常,或者,它是可以的。
org.hyperic.sigar.SigarFileNotFoundException: No such file or directory
at org.hyperic.sigar.Cpu.gather(Native Method)
at org.hyperic.sigar.Cpu.fetch(Cpu.java:30)
at org.hyperic.sigar.Sigar.getCpu(Sigar.java:320)
at org.hyperic.sigar.Sigar.getCpuPerc(Sigar.java:348)请查找下面的示例代码
public static void main(String[] args)
{
try
{
Shell shell = new Shell();
shell.setPageSize(PageControl.SIZE_UNLIMITED);
Sigar sigar = shell.getSigar();
CpuPerc cpu = null;
for (int i = 0; i < 10; i++)
{
try
{
Thread.sleep(500L);
} catch (Exception e)
{
// TODO: handle exception
}
cpu = sigar.getCpuPerc();
double val = cpu.getCombined();
int cpuUsage = (int) (val * 100);
// System.out.println(CpuPerc.format(val));
System.out.println(cpuUsage);
}
}
catch (SigarException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}我的要求是在特定的时间间隔收集50个周期的CPU使用量。记录平均值和最高值。
请帮我解决这个问题
发布于 2015-04-07 13:16:12
为什么不使用LoadRunner的内置功能来连接到Windows和LINUX/UNIX的本地接口来收集CPU数据?你似乎在重新设计一个已经建造的滚轮。
https://stackoverflow.com/questions/29483480
复制相似问题