javalinuxgarbage-collectionjvmjstat

collecting JVM GC samples within a specific time range


I am trying to fetch the JVM GC stats using 'jstat' gcutil command.

jstat -gcutil -t 32351

This is returning me a single sample from current time.

I also understand using $ jstat -gcutil -t 32351 1s 5 will return me 5 samples with 1s interval from current time.

I want to be able to get the GC stats for last 5 minutes. or within a specific time range. I tried browsing online and could not figure it out. Can anyone please guide me on this ?


Solution

  • The command jstat only provides live stats, if you want to have access to past stats, you should redirect the output stream into a file and query the file.

    So for example let's say that you want the stats of your java process every seconds, you could launch

    jstat -gcutil <process-id> 1s > mystats
    

    Then to get the last 5 minutes you could simply display the last 300 lines

    tail -300 mystats