Search in sources :

Example 1 with NodeStatisticsMessage

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();
}
Also used : RemoteNode(com.sedmelluq.discord.lavaplayer.remote.RemoteNode) AudioTrack(com.sedmelluq.discord.lavaplayer.track.AudioTrack) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage) Map(java.util.Map)

Example 2 with NodeStatisticsMessage

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;
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) TrackExceptionMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage) TrackStartResponseMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DataInputStream(java.io.DataInputStream) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Example 3 with NodeStatisticsMessage

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;
}
Also used : ArrayList(java.util.ArrayList) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Example 4 with NodeStatisticsMessage

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Aggregations

NodeStatisticsMessage (com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)4 RemoteNode (com.sedmelluq.discord.lavaplayer.remote.RemoteNode)1 RemoteMessage (com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage)1 TrackExceptionMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage)1 TrackFrameDataMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage)1 TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)1 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)1 DataInputStream (java.io.DataInputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1