IcyRelic
IcyRelic

Reputation: 25

How to get MemoryUsage statistics for a java Process object

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();
    }

}

Upvotes: 1

Views: 212

Answers (3)

BobMcGee
BobMcGee

Reputation: 20120

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.

Upvotes: 2

tirpitz.verus
tirpitz.verus

Reputation: 140

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.

Upvotes: 0

CiroRa
CiroRa

Reputation: 510

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

Upvotes: 0

Related Questions