forked from lavalink-devs/Lavalink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Histogram for GC pauses (lavalink-devs#106)
* Make lavaplayer gc warnings optional * [Metrics] Add Histogram for GC pauses
- Loading branch information
1 parent
9001c25
commit e2b28c4
Showing
5 changed files
with
70 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
LavalinkServer/src/main/java/lavalink/server/metrics/GcNotificationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package lavalink.server.metrics; | ||
|
||
import com.sun.management.GarbageCollectionNotificationInfo; | ||
import com.sun.management.GcInfo; | ||
import io.prometheus.client.Collector; | ||
import io.prometheus.client.Histogram; | ||
|
||
import javax.management.Notification; | ||
import javax.management.NotificationListener; | ||
import javax.management.openmbean.CompositeData; | ||
|
||
import static com.sun.management.GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION; | ||
import static com.sun.management.GarbageCollectionNotificationInfo.from; | ||
|
||
/** | ||
* Created by napster on 21.05.18. | ||
* <p> | ||
* General idea taken from {@link com.sedmelluq.discord.lavaplayer.tools.GarbageCollectionMonitor}, thanks! | ||
*/ | ||
public class GcNotificationListener implements NotificationListener { | ||
|
||
private final Histogram gcPauses = Histogram.build() | ||
.name("lavalink_gc_pauses_seconds") | ||
.help("Garbage collection pauses by buckets") | ||
.buckets(25, 50, 100, 200, 400, 800, 1600) | ||
.register(); | ||
|
||
@Override | ||
public void handleNotification(Notification notification, Object handback) { | ||
if (GARBAGE_COLLECTION_NOTIFICATION.equals(notification.getType())) { | ||
GarbageCollectionNotificationInfo notificationInfo = from((CompositeData) notification.getUserData()); | ||
GcInfo info = notificationInfo.getGcInfo(); | ||
|
||
if (info != null && !"No GC".equals(notificationInfo.getGcCause())) { | ||
gcPauses.observe(info.getDuration() / Collector.MILLISECONDS_PER_SECOND); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters