|
@@ -51,10 +51,10 @@ public class HttpService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void SendResponse(HttpExchange exh, int code, String contentType, String response) throws IOException {
|
|
private void SendResponse(HttpExchange exh, int code, String contentType, String response) throws IOException {
|
|
|
- exh.sendResponseHeaders(code, response.length());
|
|
|
|
|
if (contentType != null)
|
|
if (contentType != null)
|
|
|
exh.getResponseHeaders().add("Content-Type", contentType +"; charset=" +Charset.defaultCharset().displayName());
|
|
exh.getResponseHeaders().add("Content-Type", contentType +"; charset=" +Charset.defaultCharset().displayName());
|
|
|
- // FIXME cache control
|
|
|
|
|
|
|
+ exh.getResponseHeaders().add("Content-Cache", "max-age=60"); // 1 minutes cache
|
|
|
|
|
+ exh.sendResponseHeaders(code, response.length());
|
|
|
OutputStream os = exh.getResponseBody();
|
|
OutputStream os = exh.getResponseBody();
|
|
|
os.write(response.getBytes());
|
|
os.write(response.getBytes());
|
|
|
os.flush();
|
|
os.flush();
|
|
@@ -81,12 +81,15 @@ public class HttpService {
|
|
|
private void ServeMetrics(HttpExchange httpExchange) throws IOException {
|
|
private void ServeMetrics(HttpExchange httpExchange) throws IOException {
|
|
|
if (FilterRequests(httpExchange))
|
|
if (FilterRequests(httpExchange))
|
|
|
return;
|
|
return;
|
|
|
- StringBuilder os = new StringBuilder();
|
|
|
|
|
- for (CollectorValue i : CollectorManager.GetInstance()) {
|
|
|
|
|
- os.append("# HELP ").append(i.fName).append(" ").append(i.fHelp).append("\n");
|
|
|
|
|
- os.append("# TYPE ").append(i.fName).append(" ").append(i.fType.fName).append("\n");
|
|
|
|
|
- os.append(i.fName).append(" ").append(i.toString()).append("\n");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ final StringBuilder os = new StringBuilder();
|
|
|
|
|
+ CollectorManager.GetInstance().forEach(new CollectorManager.Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void Run(CollectorValue i) {
|
|
|
|
|
+ os.append("# HELP ").append(i.fName).append(" ").append(i.fHelp).append("\n");
|
|
|
|
|
+ os.append("# TYPE ").append(i.fName).append(" ").append(i.fType.fName).append("\n");
|
|
|
|
|
+ os.append(i.fName).append(" ").append(i.toString()).append("\n");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
SendResponse(httpExchange, 200, "text/plain", os.toString());
|
|
SendResponse(httpExchange, 200, "text/plain", os.toString());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|