5

I'm new on Java, so i don't know who to get the downloading zip-file (hyperic-sigar-1.6.4.zip) in the project where i've to use the Sigar-classes.

I already try to import the Sigar.Jar file, but the problem is then that the sources are unknown for each class in sigar.

So i use Eclipse Indigo for programming, may someone can help me :)

Very Thanksfull greets

Marcus

lakshman
  • 2,641
  • 6
  • 37
  • 63
Marcus Se
  • 63
  • 1
  • 2
  • 5

2 Answers2

5

First You need to add Sigar.jar to your library, then add .so file to your library (you need to pick file for your OS what you are using). You can find these files in "hyperic-sigar-1.6.4/sigar-bin/lib". You can find the usage of Mem function in the example code:

import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;


import org.hyperic.sigar.Mem;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class MemExample {

    private static Sigar sigar = new Sigar();

    public static void getInformationsAboutMemory() {
        System.out.println("**************************************");
        System.out.println("*** Informations about the Memory: ***");
        System.out.println("**************************************\n");

        Mem mem = null;
        try {
            mem = sigar.getMem();
        } catch (SigarException se) {
            se.printStackTrace();
        }

        System.out.println("Actual total free system memory: "
                + mem.getActualFree() / 1024 / 1024+ " MB");
        System.out.println("Actual total used system memory: "
                + mem.getActualUsed() / 1024 / 1024 + " MB");
        System.out.println("Total free system memory ......: " + mem.getFree()
                / 1024 / 1024+ " MB");
        System.out.println("System Random Access Memory....: " + mem.getRam()
                + " MB");
        System.out.println("Total system memory............: " + mem.getTotal()
                / 1024 / 1024+ " MB");
        System.out.println("Total used system memory.......: " + mem.getUsed()
                / 1024 / 1024+ " MB");

        System.out.println("\n**************************************\n");


    }

    public static void main(String[] args) throws Exception{

                getInformationsAboutMemory();

                }

}
Vinesh
  • 933
  • 2
  • 7
  • 22
  • So i add the sigar.jar file to my JRE System Library and i copying all .so files from hyperic-sigar-1.6.4/sigar-bin/lib to Java/jre6/lib But now i always get the message:
    Failed to load sigar-amd64-winnt: java.lang.NullPointerException org.hyperic.sigar.SigarException: Failed to load sigar-amd64-winnt: java.lang.NullPointerException at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:170) at org.hyperic.sigar.Sigar.(Sigar.java:100) at MemExample.(MemExample.java:14) 
    
    so what's wrong?
    – Marcus Se Aug 31 '12 at 13:25
  • Also add this file sigar-x86-winnt.lib to your library. – Vinesh Sep 01 '12 at 05:15
  • I'm using Win 7, 64 Bit, so whats the sence of using the 32Bit lib? But i tried and the result is the same. May is it possible that the sigar-function get bugs. But i didn't get a look in the classes, so i'm at a loss. – Marcus Se Sep 01 '12 at 08:57
  • i add the complete sigar library to my jre6/lib so it shouldn't care using the jre6/lib (with the sigar files) or the sigar file. – Marcus Se Sep 01 '12 at 09:41
  • In my case i am using Ubuntu(64 bit), I placed sigar.jar & libsigar-x86-linux.so in my projects lib folder (i.e /home/project/Metrics/lib/) it works fine for me... – Vinesh Sep 01 '12 at 09:54
  • hm. may the win file is defect, is it possible? Otherwise i didnt found anything in the hyperic-sigar-forum about this problem, only for the version 1.6.0. – Marcus Se Sep 01 '12 at 10:06
3

The downloaded zip will contain a folder or two giving examples in how to use some of the functions. Example of the folder can be found at:

"hyperic-sigar-1.6.4/bindings/java/examples"

Jamie Burke
  • 194
  • 1
  • 1
  • 8