Hi,
i am sorry I was Just found the name of the Connection for example lo or etho etc but i need that no. of packets sent and received on this system under the Activity as in windows xp........
Please Help me .........
Thanks in Advance
Java Source Code Get Bandwidth Usage MonitorHi, i am sorry I was Just found the name of the Connection for exa
Page 1 of 1
3 Replies - 6824 Views - Last Post: 07 August 2009 - 10:03 PM
Replies To: Java Source Code Get Bandwidth Usage Monitor
#2
Re: Java Source Code Get Bandwidth Usage Monitor
Posted 07 August 2009 - 06:29 PM
talk2anbu, on 5 Aug, 2009 - 10:16 PM, said:
Hi,
i am sorry I was Just found the name of the Connection for example lo or etho etc but i need that no. of packets sent and received on this system under the Activity as in windows xp........
Please Help me .........
Thanks in Advance
i am sorry I was Just found the name of the Connection for example lo or etho etc but i need that no. of packets sent and received on this system under the Activity as in windows xp........
Please Help me .........
Thanks in Advance
What is exactly your question ?
#3
Re: Java Source Code Get Bandwidth Usage Monitor
Posted 07 August 2009 - 09:39 PM
Java is not the best environment for this kind of thing because it requires low level access to the OS. You can do it but you will find yourself jumping though hoops that are much more trouble then you need.
I recently made a post
in another thread where I gave some links on how one might go about this. I don't know if this is indeed the direction you need to go, but this would be my first direction of inquery. I think that WMI can do what you need -- perhaps you could post a question to microsoft's scripting guys (they seem to be the WMI experts out there)
the Win32_PerfRawData_Tcpip_NetworkInterface class has BytesReceivedPerSec which sounds like the kind of thing you are interested in.
I recently made a post
in another thread where I gave some links on how one might go about this. I don't know if this is indeed the direction you need to go, but this would be my first direction of inquery. I think that WMI can do what you need -- perhaps you could post a question to microsoft's scripting guys (they seem to be the WMI experts out there)the Win32_PerfRawData_Tcpip_NetworkInterface class has BytesReceivedPerSec which sounds like the kind of thing you are interested in.
#4
Re: Java Source Code Get Bandwidth Usage Monitor
Posted 07 August 2009 - 10:03 PM
Here is a full example of how to use JACOB to query WMI to get information on the network usage statistics:
The code is a little ugly because I just did some regex/replace - copy/paste work to get all of the elements that get returned.
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.EnumVariant;
import com.jacob.com.Variant;
public class NetworkInterfaceQuery {
/**
* List the network interfaces and thier statistics.
*
* @param args
*/
public static void main(String[] args) {
String host = "localhost"; //Technically you should be able to connect to other hosts, but it takes setup
String connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);
String query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; //Started = 1 means the service is running.
ActiveXComponent axWMI = new ActiveXComponent(connectStr);
//Execute the query
Variant vCollection = axWMI.invoke("ExecQuery", new Variant(query));
//Our result is a collection, so we need to work though the.
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
Dispatch item = null;
while (enumVariant.hasMoreElements()) {
item = enumVariant.nextElement().toDispatch();
//Dispatch.call returns a Variant which we can convert to a java form.
String BytesReceivedPerSec = Dispatch.call(item,"BytesReceivedPerSec").toString();
String BytesSentPerSec = Dispatch.call(item,"BytesSentPerSec").toString();
String BytesTotalPerSec = Dispatch.call(item,"BytesTotalPerSec").toString();
String Caption = Dispatch.call(item,"Caption").toString();
String CurrentBandwidth = Dispatch.call(item,"CurrentBandwidth").toString();
String Description = Dispatch.call(item,"Description").toString();
String Frequency_Object = Dispatch.call(item,"Frequency_Object").toString();
String Frequency_PerfTime = Dispatch.call(item,"Frequency_PerfTime").toString();
String Frequency_Sys100NS = Dispatch.call(item,"Frequency_Sys100NS").toString();
String Name = Dispatch.call(item,"Name").toString();
String OutputQueueLength = Dispatch.call(item,"OutputQueueLength").toString();
String PacketsOutboundDiscarded = Dispatch.call(item,"PacketsOutboundDiscarded").toString();
String PacketsOutboundErrors = Dispatch.call(item,"PacketsOutboundErrors").toString();
String PacketsPerSec = Dispatch.call(item,"PacketsPerSec").toString();
String PacketsReceivedDiscarded = Dispatch.call(item,"PacketsReceivedDiscarded").toString();
String PacketsReceivedErrors = Dispatch.call(item,"PacketsReceivedErrors").toString();
String PacketsReceivedNonUnicastPerSec = Dispatch.call(item,"PacketsReceivedNonUnicastPerSec").toString();
String PacketsReceivedPerSec = Dispatch.call(item,"PacketsReceivedPerSec").toString();
String PacketsReceivedUnicastPerSec = Dispatch.call(item,"PacketsReceivedUnicastPerSec").toString();
String PacketsReceivedUnknown = Dispatch.call(item,"PacketsReceivedUnknown").toString();
String PacketsSentNonUnicastPerSec = Dispatch.call(item,"PacketsSentNonUnicastPerSec").toString();
String PacketsSentPerSec = Dispatch.call(item,"PacketsSentPerSec").toString();
String PacketsSentUnicastPerSec = Dispatch.call(item,"PacketsSentUnicastPerSec").toString();
String Timestamp_Object = Dispatch.call(item,"Timestamp_Object").toString();
String Timestamp_PerfTime = Dispatch.call(item,"Timestamp_PerfTime").toString();
String Timestamp_Sys100NS = Dispatch.call(item,"Timestamp_Sys100NS").toString();
System.out.println("Name = " + Name);
System.out.println("BytesReceivedPerSec = " + BytesReceivedPerSec);
System.out.println("BytesSentPerSec = " + BytesSentPerSec);
System.out.println("BytesTotalPerSec = " + BytesTotalPerSec);
System.out.println("Caption = " + Caption);
System.out.println("CurrentBandwidth = " + CurrentBandwidth);
System.out.println("Description = " + Description);
System.out.println("Frequency_Object = " + Frequency_Object);
System.out.println("Frequency_PerfTime = " + Frequency_PerfTime);
System.out.println("Frequency_Sys100NS = " + Frequency_Sys100NS);
System.out.println("OutputQueueLength = " + OutputQueueLength);
System.out.println("PacketsOutboundDiscarded = " + PacketsOutboundDiscarded);
System.out.println("PacketsOutboundErrors = " + PacketsOutboundErrors);
System.out.println("PacketsPerSec = " + PacketsPerSec);
System.out.println("PacketsReceivedDiscarded = " + PacketsReceivedDiscarded);
System.out.println("PacketsReceivedErrors = " + PacketsReceivedErrors);
System.out.println("PacketsReceivedNonUnicastPerSec = " + PacketsReceivedNonUnicastPerSec);
System.out.println("PacketsReceivedPerSec = " + PacketsReceivedPerSec);
System.out.println("PacketsReceivedUnicastPerSec = " + PacketsReceivedUnicastPerSec);
System.out.println("PacketsReceivedUnknown = " + PacketsReceivedUnknown);
System.out.println("PacketsSentNonUnicastPerSec = " + PacketsSentNonUnicastPerSec);
System.out.println("PacketsSentPerSec = " + PacketsSentPerSec);
System.out.println("PacketsSentUnicastPerSec = " + PacketsSentUnicastPerSec);
System.out.println("Timestamp_Object = " + Timestamp_Object);
System.out.println("Timestamp_PerfTime = " + Timestamp_PerfTime);
System.out.println("Timestamp_Sys100NS = " + Timestamp_Sys100NS);
System.out.println("-------------------------------------------");
}
}
}
The code is a little ugly because I just did some regex/replace - copy/paste work to get all of the elements that get returned.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|