Search in sources :

Example 11 with GcInfo

use of com.sun.management.GcInfo in project jvm-tools by aragozin.

the class GcAdapter method report.

public void report() {
    try {
        GcInfo lastGc = gc.getLastGcInfo();
        if (lastGc == null || lastGc.getId() == gcCount) {
            return;
        } else {
            int missed = (int) (lastGc.getId() - 1 - gcCount);
            if (gcCount < 0) {
                missed = 0;
            }
            long gcInterval = lastGc.getStartTime() - prevCollectionEndTime;
            prevCollectionEndTime = lastGc.getEndTime();
            if (gcCount < 0) {
                gcInterval = -1;
            }
            if (lastGc.getEndTime() == 0) {
                // no GC so far
                prevCollectionEndTime = 0;
                gcCount = lastGc.getId();
            } else {
                gcCount = lastGc.getId();
                sampler.report(name, missed, new Report(lastGc, gcInterval));
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : GcInfo(com.sun.management.GcInfo) GcReport(org.gridkit.jvmtool.gcflow.GarbageCollectionSampler.GcReport) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 12 with GcInfo

use of com.sun.management.GcInfo in project graylog2-server by Graylog2.

the class GarbageCollectionWarningThread method doRun.

@Override
public void doRun() {
    for (final GarbageCollectorMXBean gc : garbageCollectors) {
        switch(gc.getName()) {
            case "ParNew":
            case "ConcurrentMarkSweep":
                LOG.debug("Skipping GC warning listener for concurrent collector {}.", gc.getName());
                continue;
        }
        LOG.debug("Installing GC warning listener for collector {}, total runtime threshold is {}.", gc.getName(), gcWarningThreshold);
        final NotificationEmitter emitter = (NotificationEmitter) gc;
        final NotificationListener listener = new NotificationListener() {

            @SuppressForbidden("Deliberate usage of GcInfo and GarbageCollectionNotificationInfo")
            @Override
            public void handleNotification(javax.management.Notification notification, Object handback) {
                if (GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) {
                    final GcInfo gcInfo = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData()).getGcInfo();
                    final Duration duration = Duration.milliseconds(gcInfo.getDuration());
                    if (duration.compareTo(gcWarningThreshold) > 0) {
                        LOG.warn("Last GC run with {} took longer than {} (last duration={})", gc.getName(), gcWarningThreshold, duration);
                        final Notification systemNotification = notificationService.buildNow().addNode(nodeId.toString()).addTimestamp(Tools.nowUTC()).addSeverity(Notification.Severity.URGENT).addType(Notification.Type.GC_TOO_LONG).addDetail("gc_name", gc.getName()).addDetail("gc_duration_ms", duration.toMilliseconds()).addDetail("gc_threshold_ms", gcWarningThreshold.toMilliseconds()).addDetail("gc_collection_count", gc.getCollectionCount()).addDetail("gc_collection_time", gc.getCollectionTime());
                        if (!notificationService.publishIfFirst(systemNotification)) {
                            LOG.debug("Couldn't publish notification: {}", notification);
                        }
                    }
                }
            }
        };
        emitter.addNotificationListener(listener, null, null);
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) GcInfo(com.sun.management.GcInfo) CompositeData(javax.management.openmbean.CompositeData) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) Duration(com.github.joschi.jadconfig.util.Duration) Notification(org.graylog2.notifications.Notification) NotificationListener(javax.management.NotificationListener)

Aggregations

GcInfo (com.sun.management.GcInfo)12 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)5 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)3 MemoryUsage (java.lang.management.MemoryUsage)3 NotificationEmitter (javax.management.NotificationEmitter)3 CompositeData (javax.management.openmbean.CompositeData)3 Map (java.util.Map)2 Notification (javax.management.Notification)2 NotificationListener (javax.management.NotificationListener)2 Duration (com.github.joschi.jadconfig.util.Duration)1 GarbageCollectorMXBeanImpl (com.ibm.java.lang.management.internal.GarbageCollectorMXBeanImpl)1 GarbageCollectorMXBean (com.sun.management.GarbageCollectorMXBean)1 IOException (java.io.IOException)1 java.lang.management (java.lang.management)1 MemoryManagerMXBean (java.lang.management.MemoryManagerMXBean)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 javax.management (javax.management)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1