Skip to content

Commit

Permalink
Merge branch 'dev' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Jun 9, 2018
2 parents 57b5911 + a5e04ef commit 9d04b57
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 15 deletions.
1 change: 1 addition & 0 deletions LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lavalink:
local: false
bufferDurationMs: 400
youtubePlaylistLoadLimit: 600
gc-warnings: true

metrics:
prometheus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class AudioPlayerConfiguration {
public AudioPlayerManager audioPlayerManager(AudioSourcesConfig sources, ServerConfig serverConfig) {

AudioPlayerManager audioPlayerManager = new DefaultAudioPlayerManager();
audioPlayerManager.enableGcMonitoring();

if (serverConfig.isGcWarnings()) {
audioPlayerManager.enableGcMonitoring();
}

if (sources.isYoutube()) {
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
public class ServerConfig {

private String password;
private String sentryDsn = "";
@Nullable
private Integer bufferDurationMs;
@Nullable
private Integer youtubePlaylistLoadLimit;
private boolean gcWarnings = true;

public String getPassword() {
return password;
Expand All @@ -41,8 +47,6 @@ public void setPassword(String password) {
this.password = password;
}

private String sentryDsn = "";

/**
* @deprecated use {@link SentryConfigProperties} instead.
*/
Expand All @@ -55,9 +59,6 @@ public void setSentryDsn(String sentryDsn) {
this.sentryDsn = sentryDsn;
}

@Nullable
public Integer bufferDurationMs;

@Nullable
public Integer getBufferDurationMs() {
return bufferDurationMs;
Expand All @@ -67,9 +68,6 @@ public void setBufferDurationMs(@Nullable Integer bufferDurationMs) {
this.bufferDurationMs = bufferDurationMs;
}

@Nullable
private Integer youtubePlaylistLoadLimit;

@Nullable
public Integer getYoutubePlaylistLoadLimit() {
return youtubePlaylistLoadLimit;
Expand All @@ -78,4 +76,12 @@ public Integer getYoutubePlaylistLoadLimit() {
public void setYoutubePlaylistLoadLimit(@Nullable Integer youtubePlaylistLoadLimit) {
this.youtubePlaylistLoadLimit = youtubePlaylistLoadLimit;
}

public boolean isGcWarnings() {
return gcWarnings;
}

public void setGcWarnings(boolean gcWarnings) {
this.gcWarnings = gcWarnings;
}
}
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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import javax.management.NotificationEmitter;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;

/**
* Created by napster on 08.05.18.
*/
Expand All @@ -30,6 +34,14 @@ public PrometheusMetrics() {
//jvm (hotspot) metrics
DefaultExports.initialize();

//gc pause buckets
final GcNotificationListener gcNotificationListener = new GcNotificationListener();
for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
if (gcBean instanceof NotificationEmitter) {
((NotificationEmitter) gcBean).addNotificationListener(gcNotificationListener, null, gcBean);
}
}

log.info("Prometheus metrics set up");
}
}
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
subprojects {
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
springBootVersion = '2.0.2.RELEASE'
gradleGitVersion = '1.4.21'
}
repositories {
Expand All @@ -40,23 +40,23 @@ subprojects {
//@formatter:off

lavaplayerVersion = '1.2.64'
jdaAudioVersion = '91438c36d7107cf838c2f2eb147b08f989d929db'
jdaAudioVersion = '4d7abb48aec49f0a996ba0d87df34fdc67f71275'
jdaNasVersion = '1.0.6.2-JDA-Audio'
jappVersion = '1.2'
jdaVersion = '3.6.0_355'
jdaVersion = '3.6.0_367'

springBootVersion = "${springBootVersion}"
javaWebSocketVersion = '1.3.8'
logbackVersion = '1.2.3'
slf4jVersion = '1.7.25'
sentryLogbackVersion = '1.7.0'
oshiVersion = '3.4.4'
oshiVersion = '3.5.0'
jsonOrgVersion = '20180130'
spotbugsAnnotationsVersion = '3.1.3'
prometheusVersion = '0.4.0'

junitJupiterVersion = '5.1.0'
junitPlatformVersion = '1.1.0'
junitJupiterVersion = '5.2.0'
junitPlatformVersion = '1.2.0'
unirestVersion = '1.4.9'

//@formatter:on
Expand Down

0 comments on commit 9d04b57

Please sign in to comment.