Я хочу интегрировать журнал GC со своим собственным регистратором на основе http, чтобы избежать регистрации на основе файлов. Я следил: http://www.fasterj.com/articles/gcnotifs.shtml статья. Начиная с JDk 7, мы можем добавить нашего собственного слушателя события GC, который работает нормально. Но я хочу, чтобы мои журналы gc печатались так же, как мы регистрировали их ранее.
Как показано ниже.
2019-11-04T10:12:33.754+0000: 3.199: [GC pause (G1 Evacuation Pause) (young)
Desired survivor size 50331648 bytes, new threshold 15 (max 15)
, 0.0300627 secs]
[Parallel Time: 18.2 ms, GC Workers: 8]
[GC Worker Start (ms): Min: 3198.9, Avg: 3198.9, Max: 3199.0, Diff: 0.1]
[Ext Root Scanning (ms): Min: 0.7, Avg: 2.7, Max: 11.7, Diff: 11.0, Sum: 21.3]
[Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]
[Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
[Code Root Scanning (ms): Min: 0.0, Avg: 0.6, Max: 2.6, Diff: 2.6, Sum: 4.5]
[Object Copy (ms): Min: 0.8, Avg: 9.9, Max: 16.1, Diff: 15.3, Sum: 79.4]
[Termination (ms): Min: 0.0, Avg: 4.8, Max: 5.6, Diff: 5.6, Sum: 38.6]
[Termination Attempts: Min: 1, Avg: 1.0, Max: 1, Diff: 0, Sum: 8]
[GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.1]
[GC Worker Total (ms): Min: 17.9, Avg: 18.0, Max: 18.1, Diff: 0.1, Sum: 143.9]
[GC Worker End (ms): Min: 3216.9, Avg: 3216.9, Max: 3217.0, Diff: 0.1]
[Code Root Fixup: 0.9 ms]
[Code Root Purge: 0.1 ms]
[Clear CT: 0.2 ms]
[Other: 10.8 ms]
Итак, я из уведомления, которое я могу напечатать:
end of minor GC: - 1342 ParNew (from Allocation Failure) 26 milliseconds; start-end times 67212728-67212754
end of minor GC: - 1343 ParNew (from Allocation Failure) 28 milliseconds; start-end times 68412633-68412661
end of major GC: - 54 ConcurrentMarkSweep (from System.gc()) 147 milliseconds; start-end times 68563369-68563516
end of minor GC: - 1344 ParNew (from Allocation Failure) 109 milliseconds; start-end times 70212722-70212831
end of minor GC: - 1345 ParNew (from Allocation Failure) 39 milliseconds; start-end times 71413175-71413214
end of minor GC: - 1346 ParNew (from Allocation Failure) 42 milliseconds; start-end times 72013977-72014019
public void handleNotification(Notification notification, Object handback) {
//get the information associated with this notification
//get all the info and pretty print it
GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());
LOG.info(info.getGcAction() + ": - " + info.getGcInfo().getId()+ " " + info.getGcName() + " (from " + info.getGcCause()+") "+info.getGcInfo().getDuration() + " milliseconds; start-end times " + info.getGcInfo().getStartTime()+ "-" + info.getGcInfo().getEndTime());
}