0

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 ?

mo0206
  • 791
  • 5
  • 20
  • 36
  • Could you please let us know what are you trying to accomplish with this? Why e.g. putting 600 instead of 5 won't work for you? If you're trying to correlate an issue which GC events, I think you can try using `-XX:+PrintGCDetails -XX:+PrintGCTimeStamps` and / or external tools capturing some of that e.g. [jvisualvm](http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/index.html) – Ivan Oct 12 '16 at 19:17
  • you want to get past stats while it gives live stats so unless you put the stats into a file and you query the file, I'm not sure it can be done – Nicolas Filotto Oct 12 '16 at 19:18
  • I am building a monitoring tool which when triggered (runs at specific times) should collect the past GC stats(for 5 or 10 min) and verify. (like gc count should not be more than 2 in the past 5 min) – mo0206 Oct 12 '16 at 20:23
  • 1
    @MonicaThaneer in that case I join the Nicolas opinion on collecting everything into a file and then filtering the relevant portion – Ivan Oct 13 '16 at 06:46

1 Answers1

1

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 
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
  • but this would collect the stats for the next 5 min after launch right ? which means i have to wait for 5 min. rather I am trying to get the past 5 min samples from the current time... (I am trying to monitor the stats at particular intervals and would want way to fetch the past stats rather than waiting to collect the stats.) – mo0206 Oct 12 '16 at 20:18
  • or is there any other way other than jstat that I could use? – mo0206 Oct 12 '16 at 20:20
  • once again `jstat` provides only the live stats not the previous stats so I believe that it is the best you can do – Nicolas Filotto Oct 13 '16 at 11:24