1

Is it possible to get the current RAM usage of a java Process that is created with Runtime.getRuntime().exec(...);. I am creating a minecraft server instance and I need to monitor the resource usage of the server.

Here is exactly how I am creating the process.

private void runStartCommand(){
    try {
        lines = new ArrayList<>();
        String cmd = "cmd.exe /c cd " + service.getLocation() + "& java -jar -Xmx2G -Xms2G "+service.getLocation()+"spigot-1.9.2.jar";
        process = Runtime.getRuntime().exec(cmd);
        input = new BufferedReader(new InputStreamReader(process.getInputStream()),8*1024);
        writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
        running = true;
    } catch (IOException e) {
        e.printStackTrace();
    }

}
6
  • Is this server on Unix? Commented Jun 14, 2016 at 6:02
  • @SamuelToh He executes cmd.exe so he is under Windows Commented Jun 14, 2016 at 6:04
  • No. currently it is running on Windows on my computer and in the future it will run on Centos and Windows servers Commented Jun 14, 2016 at 6:05
  • Probably worth Googling for powershell commands to do something equivalent to unix's 'top' command then grep for the process. superuser.com/questions/176624/… Commented Jun 14, 2016 at 6:08
  • Shelling out from Java to launch another Java process is... not such a great practice. Better to add the other Java process as a dependency to your project, and start a new Thread that invokes its main() method. This greatly reduces the JVM overhead, means you're not restricted to one OS, and makes it much easier to monitor and control the other process. Commented Jun 15, 2016 at 14:08

3 Answers 3

2

Bukkit already provides a custom plugin for monitoring and managing Minecraft server performance that should suit you perfectly.

Usually you would use something like Java Melody or a JMX console to monitor the application server process. You can also instrument and monitor it with the built-in VisualVM.

Sign up to request clarification or add additional context in comments.

2 Comments

Sounds like a great solution. +1 for it
What im doing is creating a Gaming Control Panel so adding a plugin be useful to me
0

http://linux.die.net/man/1/dstat

if you are under linux, you can try dstat. We use it to take control over cpu, disk e ram usage

Comments

0

You could try to run systeminfo but you should really consider not doing it from Java but running some other tool (your could use nagios) on the OS - that way your monitoring isn't dependent on the app you're running.

1 Comment

Im creating a control panel for multiple game servers so managing it within the control panel would be essential

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.