how to get memory usage for every request in grails application

524 Views Asked by At

Are there any tools/plugins that can identify the profile like memory, cpu and other usage information on each request in grails web application.

1

There are 1 best solutions below

0
On

Try this:

public class CrunchifyJVMParameters {


    public static void main(String[] args) {

        int mb = 1024 * 1024; 

        // get Runtime instance
        Runtime instance = Runtime.getRuntime();

        System.out.println("***** Heap utilization statistics [MB] *****\n");

        // available memory
        System.out.println("Total Memory: " + instance.totalMemory() / mb);

        // free memory
        System.out.println("Free Memory: " + instance.freeMemory() / mb);

        // used memory
        System.out.println("Used Memory: "
                + (instance.totalMemory() - instance.freeMemory()) / mb);

        // Maximum available memory
        System.out.println("Max Memory: " + instance.maxMemory() / mb);
    }
}

Source https://crunchify.com/java-runtime-get-free-used-and-total-memory-in-java/