Skip to content

Commit 4018ee5

Browse files
committed
refactor: remove dead MetricsHandler and demote noisy logs to debug level
1 parent 51f6af9 commit 4018ee5

2 files changed

Lines changed: 4 additions & 43 deletions

File tree

src/main/java/org/damon233/performtrackermod/controller/TrackerController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public synchronized void start(MinecraftServer server) {
130130

131131
serverCollector.reset();
132132

133-
LOGGER.info("Performance tracking started, sessionId: {}", sessionId);
133+
LOGGER.debug("Performance tracking started, sessionId: {}", sessionId);
134134
}
135135

136136
private boolean hasAnyMetricEnabled() {
@@ -158,7 +158,7 @@ public synchronized void stop() {
158158
httpService.stop();
159159
}
160160

161-
LOGGER.info("Performance tracking stopped, samples: {}", sampleCount);
161+
LOGGER.debug("Performance tracking stopped, samples: {}", sampleCount);
162162

163163
state.set(TrackerState.IDLE);
164164
lastOutputTime = 0;
@@ -191,7 +191,7 @@ private void onServerTick(MinecraftServer server) {
191191
if (ConfigAccess.isExportEnabled() && metricsWriter != null) {
192192
String newFormat = ConfigAccess.getOutputFormat();
193193
if (!newFormat.equals(currentOutputFormat)) {
194-
LOGGER.info("Output format changed from {} to {}, creating new file", currentOutputFormat, newFormat);
194+
LOGGER.debug("Output format changed from {} to {}, creating new file", currentOutputFormat, newFormat);
195195
try {
196196
metricsWriter.close();
197197
metricsWriter = createMetricsWriter();

src/main/java/org/damon233/performtrackermod/network/HttpService.java

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
import java.io.IOException;
30-
import java.io.InputStream;
3130
import java.io.OutputStream;
3231
import java.net.InetSocketAddress;
3332
import java.net.URI;
@@ -123,7 +122,6 @@ private boolean startServerInternal() {
123122
server.setExecutor(serverExecutor);
124123

125124
server.createContext("/api/deviceinfo", new DeviceInfoHandler());
126-
server.createContext("/api/metrics", new MetricsHandler());
127125

128126
server.start();
129127
serverRunning.set(true);
@@ -137,7 +135,7 @@ private boolean startServerInternal() {
137135

138136
private void startSender() {
139137
if (senderRunning.compareAndSet(false, true)) {
140-
LOGGER.info("HttpService sender started, target: {}", remoteUrl);
138+
LOGGER.debug("HttpService sender started, target: {}", remoteUrl);
141139
senderExecutor.execute(this::sendLoop);
142140
}
143141
}
@@ -258,41 +256,4 @@ private void sendResponse(HttpExchange exchange, int statusCode, String body) {
258256
}
259257
}
260258
}
261-
262-
private static class MetricsHandler implements HttpHandler {
263-
@Override
264-
public void handle(HttpExchange exchange) {
265-
if (!"POST".equalsIgnoreCase(exchange.getRequestMethod())) {
266-
sendResponse(exchange, 405, "{\"error\":\"Method not allowed\"}");
267-
return;
268-
}
269-
270-
try {
271-
int contentLength = Integer.parseInt(exchange.getRequestHeaders().getFirst("Content-Length"));
272-
if (contentLength > 0) {
273-
try (InputStream is = exchange.getRequestBody()) {
274-
byte[] body = is.readAllBytes();
275-
LOGGER.debug("Received metrics payload: {} bytes", body.length);
276-
}
277-
}
278-
} catch (Exception e) {
279-
LOGGER.debug("Failed to read metrics payload: {}", e.getMessage());
280-
}
281-
282-
sendResponse(exchange, 200, "{\"status\":\"ok\"}");
283-
}
284-
285-
private void sendResponse(HttpExchange exchange, int statusCode, String body) {
286-
try {
287-
exchange.getResponseHeaders().set("Content-Type", "application/json");
288-
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
289-
exchange.sendResponseHeaders(statusCode, bytes.length);
290-
try (OutputStream os = exchange.getResponseBody()) {
291-
os.write(bytes);
292-
}
293-
} catch (IOException e) {
294-
LOGGER.debug("Failed to send response: {}", e.getMessage());
295-
}
296-
}
297-
}
298259
}

0 commit comments

Comments
 (0)