diff --git a/common/src/main/java/ctbrec/recorder/download/RecordingProcess.java b/common/src/main/java/ctbrec/recorder/download/RecordingProcess.java index f502a6b9..30ee8612 100644 --- a/common/src/main/java/ctbrec/recorder/download/RecordingProcess.java +++ b/common/src/main/java/ctbrec/recorder/download/RecordingProcess.java @@ -62,4 +62,8 @@ public interface RecordingProcess extends Callable { void awaitEnd(); AtomicLong getDownloadedBytes(); + + default String getStats() { + return ""; + } } diff --git a/common/src/main/java/ctbrec/recorder/download/hls/MergedFfmpegHlsDownload.java b/common/src/main/java/ctbrec/recorder/download/hls/MergedFfmpegHlsDownload.java index 89a206f2..ceedd7cf 100644 --- a/common/src/main/java/ctbrec/recorder/download/hls/MergedFfmpegHlsDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/hls/MergedFfmpegHlsDownload.java @@ -32,6 +32,14 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload { protected OutputStream ffmpegStdIn; protected BlockingQueue> queue = new LinkedBlockingQueue<>(); protected Lock ffmpegStreamLock = new ReentrantLock(); + + public String getStats() { + String text = (running ? "RUN" : "stp") + String.format(" %d: ", queue.size()); + for (var elem : queue) { + text += elem.isDone() ? "|" : "-"; + } + return text; + } public MergedFfmpegHlsDownload(HttpClient client) { super(client); diff --git a/server/src/main/java/ctbrec/recorder/server/DebugServlet.java b/server/src/main/java/ctbrec/recorder/server/DebugServlet.java index 22a9cf47..d0a069b3 100644 --- a/server/src/main/java/ctbrec/recorder/server/DebugServlet.java +++ b/server/src/main/java/ctbrec/recorder/server/DebugServlet.java @@ -2,6 +2,7 @@ package ctbrec.recorder.server; import ctbrec.Config; import ctbrec.io.HttpClient; +import ctbrec.recorder.Recorder; import ctbrec.recorder.SimplifiedLocalRecorder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,8 +29,12 @@ public class DebugServlet extends AbstractCtbrecServlet { private static final Pattern URL_PATTERN_DEBUG_STACK = Pattern.compile(BASE_URL + "/stack(/.*?)"); private static final Pattern URL_PATTERN_DEBUG_STATS = Pattern.compile(BASE_URL + "/stats"); - public DebugServlet() - {} + protected Recorder recorder; + + public DebugServlet(Recorder rec) + { + this.recorder = rec; + } @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) { @@ -64,7 +69,7 @@ public class DebugServlet extends AbstractCtbrecServlet { resp.setContentType("text/plain"); sendResponse(resp, SC_OK, box.text); } else if ((m = URL_PATTERN_DEBUG_STATS.matcher(requestURI)).matches()) { - String text = ""; + String text = ""; text += String.format("GLOBAL_HTTP_CONN_POOL: connectionCount=%d, idleConnectionCount=%d\n", HttpClient.getGLOBAL_HTTP_CONN_POOL().connectionCount(), HttpClient.getGLOBAL_HTTP_CONN_POOL().idleConnectionCount()); @@ -77,8 +82,20 @@ public class DebugServlet extends AbstractCtbrecServlet { rlock.unlock(); } + text += "\nRecording stats:\n"; + text = text.replace("\n", "
"); + + for (var rec : recorder.getRecordings()) { + var proc = rec.getRecordingProcess(); + if (proc == null) continue; + text += String.format("\n", proc.getModel().getDisplayName(), proc.getStats()); + } + + text += "
%s%s
"; + text += ""; + log.debug("Stats Request"); - resp.setContentType("text/plain"); + resp.setContentType("text/html"); sendResponse(resp, SC_OK, text); } else sendResponse(resp, SC_NOT_FOUND, ""); diff --git a/server/src/main/java/ctbrec/recorder/server/HttpServer.java b/server/src/main/java/ctbrec/recorder/server/HttpServer.java index 0b507503..4f9e26af 100644 --- a/server/src/main/java/ctbrec/recorder/server/HttpServer.java +++ b/server/src/main/java/ctbrec/recorder/server/HttpServer.java @@ -259,7 +259,7 @@ public class HttpServer { holder = new ServletHolder(modelServlet); defaultContext.addServlet(holder, ModelServlet.BASE_URL + "/*"); - DebugServlet debugServlet = new DebugServlet(); + DebugServlet debugServlet = new DebugServlet(recorder); holder = new ServletHolder(debugServlet); defaultContext.addServlet(holder, DebugServlet.BASE_URL + "/*");