forked from j62/ctbrec
1
0
Fork 0

debug statistics page

This commit is contained in:
reusedname 2024-12-03 14:24:01 +05:00
parent a003f84e70
commit 5bc8a6fdf9
2 changed files with 13 additions and 1 deletions

View File

@ -37,6 +37,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
@Slf4j @Slf4j
public abstract class HttpClient { public abstract class HttpClient {
@Getter
private static final ConnectionPool GLOBAL_HTTP_CONN_POOL = new ConnectionPool(10, 2, TimeUnit.MINUTES); private static final ConnectionPool GLOBAL_HTTP_CONN_POOL = new ConnectionPool(10, 2, TimeUnit.MINUTES);
@Getter @Getter

View File

@ -1,6 +1,7 @@
package ctbrec.recorder.server; package ctbrec.recorder.server;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.io.HttpClient;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject; import org.json.JSONObject;
@ -24,6 +25,7 @@ public class DebugServlet extends AbstractCtbrecServlet {
public static final String BASE_URL = "/debug"; public static final String BASE_URL = "/debug";
private static final Pattern URL_PATTERN_DEBUG_STACK = Pattern.compile(BASE_URL + "/stack(/.*?)"); 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() public DebugServlet()
{} {}
@ -57,9 +59,18 @@ public class DebugServlet extends AbstractCtbrecServlet {
} }
}); });
log.debug("Stacks Request {} - {}", threadUrl, stacks); log.debug("Stacks Request {}", threadUrl);
resp.setContentType("text/plain"); resp.setContentType("text/plain");
sendResponse(resp, SC_OK, box.text); sendResponse(resp, SC_OK, box.text);
} else if ((m = URL_PATTERN_DEBUG_STATS.matcher(requestURI)).matches()) {
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());
log.debug("Stats Request");
resp.setContentType("text/plain");
sendResponse(resp, SC_OK, text);
} else } else
sendResponse(resp, SC_NOT_FOUND, ""); sendResponse(resp, SC_NOT_FOUND, "");
} catch (Exception e) { } catch (Exception e) {