use of com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage in project lavaplayer by sedmelluq.
the class MusicController method buildReportForNode.
private String buildReportForNode(RemoteNode node) {
StringBuilder builder = new StringBuilder();
builder.append("--- ").append(node.getAddress()).append(" ---\n");
builder.append("Connection state: ").append(node.getConnectionState()).append("\n");
NodeStatisticsMessage statistics = node.getLastStatistics();
builder.append("Node global statistics: \n").append(statistics == null ? "unavailable" : "");
if (statistics != null) {
builder.append(" playing tracks: ").append(statistics.playingTrackCount).append("\n");
builder.append(" total tracks: ").append(statistics.totalTrackCount).append("\n");
builder.append(" system CPU usage: ").append(statistics.systemCpuUsage).append("\n");
builder.append(" process CPU usage: ").append(statistics.processCpuUsage).append("\n");
}
builder.append("Minimum tick interval: ").append(node.getTickMinimumInterval()).append("\n");
builder.append("Tick history capacity: ").append(node.getTickHistoryCapacity()).append("\n");
List<RemoteNode.Tick> ticks = node.getLastTicks(false);
builder.append("Number of ticks in history: ").append(ticks.size()).append("\n");
if (ticks.size() > 0) {
int tail = Math.min(ticks.size(), 3);
builder.append("Last ").append(tail).append(" ticks:\n");
for (int i = ticks.size() - tail; i < ticks.size(); i++) {
RemoteNode.Tick tick = ticks.get(i);
builder.append(" [duration ").append(tick.endTime - tick.startTime).append("]\n");
builder.append(" start time: ").append(tick.startTime).append("\n");
builder.append(" end time: ").append(tick.endTime).append("\n");
builder.append(" response code: ").append(tick.responseCode).append("\n");
builder.append(" request size: ").append(tick.requestSize).append("\n");
builder.append(" response size: ").append(tick.responseSize).append("\n");
}
}
List<AudioTrack> tracks = node.getPlayingTracks();
builder.append("Number of playing tracks: ").append(tracks.size()).append("\n");
if (tracks.size() > 0) {
int head = Math.min(tracks.size(), 3);
builder.append("First ").append(head).append(" tracks:\n");
for (int i = 0; i < head; i++) {
AudioTrack track = tracks.get(i);
builder.append(" [identifier ").append(track.getInfo().identifier).append("]\n");
builder.append(" name: ").append(track.getInfo().author).append(" - ").append(track.getInfo().title).append("\n");
builder.append(" progress: ").append(track.getPosition()).append(" / ").append(track.getDuration()).append("\n");
}
}
builder.append("Balancer penalties: ").append(tracks.size()).append("\n");
for (Map.Entry<String, Integer> penalty : node.getBalancerPenaltyDetails().entrySet()) {
builder.append(" ").append(penalty.getKey()).append(": ").append(penalty.getValue()).append("\n");
}
return builder.toString();
}
use of com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage in project lavaplayer by sedmelluq.
the class RemoteNodeProcessor method handleResponseBody.
private boolean handleResponseBody(InputStream inputStream, TickBuilder tickBuilder) {
CountingInputStream countingStream = new CountingInputStream(inputStream);
DataInputStream input = new DataInputStream(countingStream);
RemoteMessage message;
try {
while ((message = mapper.decode(input)) != null) {
if (message instanceof TrackStartResponseMessage) {
handleTrackStartResponse((TrackStartResponseMessage) message);
} else if (message instanceof TrackFrameDataMessage) {
handleTrackFrameData((TrackFrameDataMessage) message);
} else if (message instanceof TrackExceptionMessage) {
handleTrackException((TrackExceptionMessage) message);
} else if (message instanceof NodeStatisticsMessage) {
handleNodeStatistics((NodeStatisticsMessage) message);
}
}
} catch (InterruptedException interruption) {
log.error("Node {} processing thread was interrupted.", nodeAddress);
Thread.currentThread().interrupt();
return false;
} catch (Throwable e) {
log.error("Error when processing response from node {}.", nodeAddress, e);
ExceptionTools.rethrowErrors(e);
} finally {
tickBuilder.responseSize = countingStream.getCount();
}
return true;
}
use of com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage in project lavaplayer by sedmelluq.
the class AbandonedTrackManager method findAdopters.
private List<Adopter> findAdopters(List<RemoteNodeProcessor> nodes) {
List<Adopter> adopters = new ArrayList<>();
for (RemoteNodeProcessor node : nodes) {
int penalty = node.getBalancerPenalty();
NodeStatisticsMessage statistics = node.getLastStatistics();
if (penalty >= CRITICAL_PENALTY || statistics == null) {
continue;
}
int maximumAdoptions = Math.max(5, statistics.playingTrackCount / 15);
adopters.add(new Adopter(node, maximumAdoptions));
}
return adopters;
}
use of com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage in project lavaplayer by sedmelluq.
the class RemoteNodeProcessor method getBalancerPenaltyDetails.
@Override
public Map<String, Integer> getBalancerPenaltyDetails() {
Map<String, Integer> details = new HashMap<>();
NodeStatisticsMessage statistics = lastStatistics;
if (isUnavailableForTracks(statistics)) {
details.put("unavailable", Integer.MAX_VALUE);
} else {
details.put("playing", getPenaltyForPlayingTracks(statistics));
details.put("paused", getPenaltyForPausedTracks(statistics));
details.put("cpu", getPenaltyForCpuUsage(statistics));
details.put("timings", requestTimingPenalty);
}
int total = 0;
for (int value : details.values()) {
total += value;
}
details.put("total", total);
return details;
}
Aggregations