2

I am looking for a way to ge remote systems CPU and memory information using java. Although it can be done using windows command which can be put in java program. Here are the commands.

wmic /node:HOSTNAME cpu get loadpercentage

This will give you the CPU load for a remote system.

wmic /node:HOSTNAME OS get FreePhysicalMemory

This will give you free memory for a remote system.

But, with these, I have to depend on the windows command when using these in java using Runtime.getRuntime().exec.

Is there any java native library present which can do this work ?

Thanks

Harshit
  • 5,147
  • 9
  • 46
  • 93
  • If what you've got works, why do you want to try it with another approach? I can't envision any other way to get the kind of info you're after *without* using some external command... – Makoto Sep 11 '15 at 05:08
  • The above approach is system dependent, if somebody don't have wmic installed or any other problem! – Harshit Sep 11 '15 at 05:36
  • The `System.getProperties().list(System.out);` provides minimal information on OS. And `Runtime` provides some more. Check [this](http://stackoverflow.com/questions/25552/get-os-level-system-information) – bprasanna Sep 11 '15 at 05:52
  • @learningloop, it will only show current system information, but I need remote system info. – Harshit Sep 11 '15 at 06:08
  • You need to be able to execute a command remotely e.g. `ssh` otherwise you can't do this as this is the sort of thing security is designed to prevent. – Peter Lawrey Sep 11 '15 at 07:28
  • The command I above posted `wmic` does the same i.e. execute the command on remote system but it also takes username & password. If the java program takes username & password, I have no problem. – Harshit Sep 11 '15 at 07:32

1 Answers1

2

No, there is no way Java can natively do this. If you want a pure Java solution you will have to run a Java application on the machines that you want to get the information from. From the central machine, a seperate Java application (or any other kind of client really) can connect to the Java applications on the indiviual machines.

The (probably unacceptable) downside of this is that you would have to install this Java application on all the client machines. At that point, you are probably better off using wmic.

David ten Hove
  • 2,748
  • 18
  • 33