Link to home
Start Free TrialLog in
Avatar of Lamvuong
Lamvuong

asked on

Network usage monitoring, CPU and memory % usage for Java

I know this is a difficult task and that there is no API for it, I have come across a memory usage and cpu program before but it will only monitor the cpu usage of that thread. I was wondering if someone can help me to write a program that will just print out the current CPU percentage usage and memory of the whole pc, and also the current usage of bandwidth. This does not need to be updated regularly but just a once off print at a percise time when the program is executed. Thanks
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's some sample c# for available memory:

ManagementScope mScope;
mScope = new ManagementScope("root\\cimv2");
mScope.Connect();

System.Management.ObjectQuery oqr = new
System.Management.ObjectQuery("SELECT * FROM Win32_PerfRawData_PerfOS_Memory");

ManagementObjectSearcher srch     = new ManagementObjectSearcher(mScope,oqr);
ManagementObjectCollection coll   = srch.Get();            
foreach(ManagementObject m in coll)
       {
       return (UInt64)m["AvailableBytes"];
       }  
Hi Lamvuong,
you can use jni to achive this. or use an external executable which prints the details required to a file. then let ur program read this file and extract the data

Regards,
Bhagyesh
Avatar of Lamvuong
Lamvuong

ASKER

This was not really the answer i was looking for... The question was clearly stating for java, not c# as someone has already done it in c# so that did not really helped. yeah Bhagyesh JNI is how to do it, but i have  no idea how to do it, there is hardly any documentation for these type of things and was wondering anyone have made a JNI code for it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial