7

I'm new to Sigar. I would like to run a simple test to know how I can monitor my system.

I added sigar-1.6.4 and log4j as external libraries, but when I go to run it, I face this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.Sigar.getCpuInfoList()[Lorg/hyperic/sigar/CpuInfo; at org.hyperic.sigar.Sigar.getCpuInfoList(Native Method)

Here is my code:

import java.util.Map;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Sigar sigar = new Sigar();
        CpuInfo[] cpuinfo = null;
        try {
        cpuinfo = sigar.getCpuInfoList();
        } catch (SigarException se) {
        se.printStackTrace();
        }

        System.out.println("---------------------");
        System.out.println("Sigar found " + cpuinfo.length + " CPU(s)!");
        System.out.println("---------------------");
    }

}

Any help would be appreciated.

Jay
  • 18,959
  • 11
  • 53
  • 72
Narges
  • 1,345
  • 6
  • 14
  • 29

2 Answers2

9

I understood the problem!
I have to use the following JVM Argument:

-Djava.library.path="./lib" 

in Run Configuration, Arguments tab, VM arguments in eclipse, while the contnet of sigar-bin/lib is in lib folder.

Dungeon Hunter
  • 19,827
  • 13
  • 59
  • 82
Narges
  • 1,345
  • 6
  • 14
  • 29
  • solved a very strange and annoying problem, thank you! – Hanfeng Apr 25 '14 at 13:30
  • I get same error but my problem is not solved yet ??? what is my problem, I use sigar in a web application and libraries are loaded. – M2E67 Apr 09 '18 at 09:38
5

Sigar works via JNI. As such, the appropriate .so or .dll file needs to be in the path specified by the java.library.path property.

Check your sigar distribution - the zip file, I mean. Unzip it and copy the contents of sigar-bin\lib to a location accessible by your Path, PATH, and LD_LIBRARY_PATH environment variables. Usually, only one file needs to be accessible per platform.

That should do the trick, if it doesn't, let me know and I'll see what I can do.

Vishal Rao
  • 216
  • 2
  • 5
  • I do what you said, but still the same error, I guess I should set them as vm argument in run configuration in eclipse, but I dont know how to do it. (I mean the command I should write). Can you help please? – Narges Jul 24 '12 at 05:50
  • 1
    Sounds like from your answer, you eventually understood what I was saying. – Vishal Rao Jul 24 '12 at 15:25