How to analyse and monitor gc.log garbage collecto

2019-07-16 08:15发布

问题:

I'm wondering what is the best way to visually analyse and monitor java gc.log files.

GCViewer is the most interesting tool I've found so far, but I'm wondering if there is anything better or a good solution for monitoring multiple remote gc.log files.

回答1:

I think the most effective way for analyzing the garbage collector log is by looking at the output itself. Our production server all run using the Concurrent Mark Sweep Collector and I have the log running with the options -Xloggc:$GCLOGFILE -XX:+PrintGCDetails and if the environment runs into problems I

  1. first check for the amount of Full GC by grepping for "Full GC" and
  2. Check the amount and frequency of the CMS and look for error messages in the collection phase (usually start with "failed to...").

I usually also look at the thread list and check the amount of cpu time the Garbage Collector consumes. I do this by running top with the -p <java-pid> Parameter and press "H" afterwards, with this you get to see the pids which consume the most cpu time. This then can be matched to a Thread Dump to see if gc threads are the most time consuming threads. Every thread has a pid displayed in the thread dump, which is in hex, this can be matched to the pids in top.

It is quite important to see the cpu times the GC consumes and match this to your log output. I tried the GCViewer several times but never really got useful hints from the visual display of the GC-Data.



回答2:

You can use the jconsole tool which is included into the JDK. Or when you run a java application, you can use the parameter "-verbose:gc" .



回答3:

I think you can use options to log gc activity in a log file :

-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:gc.log

You can exploit this log with software as HPJmeter