Server Statistics
The MuStats class can give you various statistics about your server.
public class StatisticsExample {
public static void main(String[] args) {
MuServer server = httpServer()
.addHandler((req, resp) -> {
MuStats stats = req.server().stats();
long completedRequests = stats.completedRequests();
long bytesRead = stats.bytesRead();
long bytesSent = stats.bytesSent();
resp.write("There have been " + completedRequests + " requests with " + bytesRead
+ " uploaded and " + bytesSent + " downloaded.");
return true;
})
.start();
System.out.println("Server started at " + server.uri().resolve("/handle-it"));
}
}
(see full file)
Here are some stats for this website:
Active connections | 1 |
---|---|
Completed connections | 1,639 |
Active requests | 1 |
Completed requests | 2,067 |
Bytes uploaded | 1,181,713 |
Bytes downloaded | 5,786,800 |
Invalid requests | 126 |
SSL connection errors | 12 |
Rejected requests | 0 |
Connection info
You can access all the existing connections to your server by calling server.activeConnections()
which returns a set of HttpConnection objects. This allows you to see
which HTTP protocols are in use, which TLS versions are used, the ciphers used, etc. This can be useful
when analysing which TLS settings will not impact your users.
The MuRequest object also gives you access to the current connection via
the connection()
method. For example, you are accessing this web page over
HTTP/2 using TLSv1.3 with the
TLS_AES_256_GCM_SHA384 cipher. This connection, started at 2024-11-21T06:32:27.555120833Z
has served 0 requests.