Quantcast
Channel: VMware Communities : Popular Discussions - Hyperic User Forums
Viewing all articles
Browse latest Browse all 52618

Testing Sigar.NetStat.getAllInboundTotal() and getAllOutboundTotal()

$
0
0
Hello Hyperic community,
I need to be able to collect bandwidth information from the current machine I am attempting to use Sigar API for this due to Sigar's cross-platform compatibility.

However, my test doesnt seem to be working.
All the test does is go in an infinite loop and collect bandwidth total every two seconds.
However, no matter what I am downloading, the api always returns the same values.

I also cant find anywhere in the documentation that indicates if the values are in bits, bytes, KB or other measurements.

Any clarity or help on this would be greatly appreciated.


Here is the code:
@Test
    public void incomingOutgoingDataTest() throws Exception {
        Sigar.load();
        Sigar sigar = new Sigar();

        int totalIncoming = 0;
        int totalOutgoing = 0;

        InetAddress ia = InetAddress.getLocalHost();
        sigar.getNetStat().stat(sigar, ia.getAddress(), 80);

        int i = 1;
        while(true) {
            int incoming = sigar.getNetStat().getAllInboundTotal();
            int outgoing = sigar.getNetStat().getAllOutboundTotal();
            totalIncoming += incoming;
            totalOutgoing += outgoing;

            System.out.println("incoming : "+incoming);
            System.out.println("outgoing : "+outgoing);
            System.out.println("totalIncoming : "+totalIncoming);
            System.out.println("totalOutgoing : "+totalOutgoing);

            Thread.sleep(2000);
        }
    }




And here is the output:
incoming : 1
outgoing : 115
totalIncoming : 1
totalOutgoing : 115
incoming : 1
outgoing : 115
totalIncoming : 2
totalOutgoing : 230
incoming : 1
outgoing : 115
totalIncoming : 3
totalOutgoing : 345
incoming : 1
outgoing : 115
totalIncoming : 4
totalOutgoing : 460
incoming : 1
outgoing : 117
totalIncoming : 5
totalOutgoing : 577
incoming : 1
outgoing : 116
totalIncoming : 6
totalOutgoing : 693
...
...
...

Viewing all articles
Browse latest Browse all 52618

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>