1

I recently added some external jar file from hyperic sigar, name log4j.jar and sigar.jar. The purpose is to get the system(Operating System)'s download(bytes receive per second) and uploadspeed(bytes send per second) speed like 40 kb/s or 1.3 kb/s for a system in developing to monitor the computers performance.

I run across some of the classes in this library like NetInterfaceStat that have function such as NetInterfaceStat.getRxBytes and NetInterfaceStat.getTxBytes. However i believe that NetInterfaceStat class need some initialization/constructor.

Could anyone teach me how to initialize this class? Here is a example of my code.. Im developing on Mac Osx Snow Leopard and Windows 7

package pack;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Map.Entry;
import java.lang.management.*;
import org.hyperic.sigar.*;

public class systemMonitor extends Thread {
    private static Sigar sigar;
    NetInterfaceStat netstat;
    boolean truefalse=true;
public void run(){

try{

Thread.sleep(5000);
sigar = new Sigar();
System.out.print("System Monitor Started\n");
netstat = sigar.getNetInterfaceStat("en1");
System.out.print(sigar.getNetInterfaceList().toString());
}
catch(Exception e){
    System.out.print(e);
}

while(truefalse){

if(data.firstExecution!=true){
    try{
        System.out.print(netstat.getRxBytes()+" "+netstat.getTxBytes());
    }
    catch(Exception e){
    System.out.print(e);
    break;
    }
}
}
}

Im sorry if i did not provide any detailed information^^ some external links to my question... http://www.hyperic.com/support/docs/sigar/

also i found a almost similar thread in the forum too, but lack of informations... Sigar network speed

Community
  • 1
  • 1
Chris
  • 612
  • 2
  • 9
  • 23
  • `while(truefalse)` I... uh... what? – Rob Wagner Jun 29 '12 at 15:28
  • its a boolean value, i would like to later on create a function to stop the loop. But that is a later.By default the value is true. Right now im stuck with this NetInterfaceStat Class^^ – Chris Jun 29 '12 at 15:36
  • I understand what it is, haha its just the worst boolean name I've ever seen. You also don't need to "create a function" just put your break condition inside the loop. `while(data.firstExecution==true)` – Rob Wagner Jun 29 '12 at 15:44
  • ^^ maybe my coding is abit bad. Ya maybe adding a break will be better. But i dont have problem with the loop. I just need to know how to use the NetInterfaceStat class. Do you have any example of that? – Chris Jun 29 '12 at 15:47
  • this is just part of the code. There are other classes in my project. – Chris Jun 29 '12 at 15:48
  • this maybe years since asked, but I really want to have this answer since I've been in the same situation and finally found an answer, here's the link: https://stackoverflow.com/questions/11034753/sigar-network-speed?noredirect=1&lq=1 – Polar Dec 08 '17 at 11:10

0 Answers0