Browse code

FEATBL-441 Feat: init webserver metrics

Thomas Cataldo authored on 08/06/2018 10:14:06
Showing 5 changed files
... ...
@@ -4,11 +4,5 @@ tick_conf=/usr/share/bm-tick-config
4 4
 chmod +x /usr/local/bin/unixget
5 5
 
6 6
 cp ${tick_conf}/bm-telegraf.conf /etc/telegraf/telegraf.d/
7
-cp ${tick_conf}/chronograf.default /etc/default/chronograf
8
-cp ${tick_conf}/tick.conf /etc/nginx/bm-local.d/
9 7
 
10
-invoke-rc.d bm-nginx restart 0>/dev/null 1>/dev/null 2>/dev/null 3>/dev/null || true
11
-invoke-rc.d influxdb restart 0>/dev/null 1>/dev/null 2>/dev/null 3>/dev/null || true
12 8
 invoke-rc.d telegraf restart 0>/dev/null 1>/dev/null 2>/dev/null 3>/dev/null || true
13
-invoke-rc.d kapacitor restart 0>/dev/null 1>/dev/null 2>/dev/null 3>/dev/null || true
14
-invoke-rc.d chronograf restart 0>/dev/null 1>/dev/null 2>/dev/null 3>/dev/null || true
... ...
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
12 12
  net.bluemind.utils,
13 13
  net.bluemind.eclipse.common,
14 14
  net.bluemind.core.commons,
15
- net.bluemind.common.freemarker
15
+ net.bluemind.common.freemarker,
16
+ net.bluemind.metrics.registry
16 17
 Closure-Bundle-Type: Embedded
17 18
 Web-Resources: web-resources
18 19
 Closure-Inputs: BundlesManager.js
... ...
@@ -27,6 +27,7 @@ import java.util.HashSet;
27 27
 import java.util.Map;
28 28
 import java.util.Map.Entry;
29 29
 import java.util.Set;
30
+import java.util.concurrent.TimeUnit;
30 31
 
31 32
 import org.slf4j.Logger;
32 33
 import org.slf4j.LoggerFactory;
... ...
@@ -35,8 +36,12 @@ import org.vertx.java.core.buffer.Buffer;
35 35
 import org.vertx.java.core.http.HttpServerRequest;
36 36
 import org.vertx.java.core.http.HttpServerResponse;
37 37
 
38
+import com.netflix.spectator.api.Registry;
39
+
38 40
 import freemarker.template.Configuration;
39 41
 import freemarker.template.Template;
42
+import net.bluemind.metrics.registry.IdFactory;
43
+import net.bluemind.metrics.registry.MetricsRegistry;
40 44
 import net.bluemind.webmodule.server.JsEntry;
41 45
 import net.bluemind.webmodule.server.LogoVersion;
42 46
 import net.bluemind.webmodule.server.WebModule;
... ...
@@ -48,6 +53,9 @@ public abstract class AbstractAppCacheHandler implements Handler<HttpServerReque
48 48
 	private Template mainTemplate;
49 49
 	private WebModule module;
50 50
 
51
+	private final Registry registry = MetricsRegistry.get();
52
+	private final IdFactory idFactory = new IdFactory(registry, "appCache");
53
+
51 54
 	public AbstractAppCacheHandler() {
52 55
 		Configuration freemarkerCfg = new Configuration();
53 56
 		freemarkerCfg.setClassForTemplateLoading(this.getClass(), "/templates");
... ...
@@ -63,7 +71,8 @@ public abstract class AbstractAppCacheHandler implements Handler<HttpServerReque
63 63
 
64 64
 	@Override
65 65
 	public void handle(HttpServerRequest request) {
66
-
66
+		registry.counter(idFactory.name("requests")).increment();
67
+		long start = registry.clock().monotonicTime();
67 68
 		StringWriter sw = new StringWriter();
68 69
 
69 70
 		Set<String> files = new HashSet<>();
... ...
@@ -101,6 +110,8 @@ public abstract class AbstractAppCacheHandler implements Handler<HttpServerReque
101 101
 		resp.write(new Buffer(data));
102 102
 		resp.setStatusCode(200);
103 103
 		resp.end();
104
+		registry.timer(idFactory.name("requestTime")).record(registry.clock().monotonicTime() - start,
105
+				TimeUnit.NANOSECONDS);
104 106
 
105 107
 	}
106 108
 
... ...
@@ -26,9 +26,17 @@ import org.vertx.java.core.http.HttpServerRequest;
26 26
 import org.vertx.java.core.http.HttpServerResponse;
27 27
 import org.vertx.java.core.json.JsonObject;
28 28
 
29
+import com.netflix.spectator.api.Registry;
30
+
31
+import net.bluemind.metrics.registry.IdFactory;
32
+import net.bluemind.metrics.registry.MetricsRegistry;
33
+
29 34
 public class LogHandler implements Handler<HttpServerRequest> {
30 35
 	private static final Logger logger = LoggerFactory.getLogger(LogHandler.class);
31 36
 
37
+	private final Registry registry = MetricsRegistry.get();
38
+	private final IdFactory idFactory = new IdFactory(registry, "jsErrors");
39
+
32 40
 	@Override
33 41
 	public void handle(final HttpServerRequest request) {
34 42
 		request.expectMultiPart(true);
... ...
@@ -60,6 +68,7 @@ public class LogHandler implements Handler<HttpServerRequest> {
60 60
 		String name = formAttributes.get("name");
61 61
 
62 62
 		logger.error("[" + login + "] [" + name + "] " + msg);
63
+		registry.counter(idFactory.name("logReceived")).increment();
63 64
 
64 65
 		String exception = formAttributes.get("exception");
65 66
 		if (exception != null && !"undefined".equals(exception) && !"".equals(exception)) {
... ...
@@ -28,6 +28,10 @@ import org.vertx.java.core.file.FileSystem;
28 28
 import org.vertx.java.core.http.HttpServerRequest;
29 29
 import org.vertx.mods.web.Headers;
30 30
 
31
+import com.netflix.spectator.api.Registry;
32
+
33
+import net.bluemind.metrics.registry.IdFactory;
34
+import net.bluemind.metrics.registry.MetricsRegistry;
31 35
 import net.bluemind.webmodule.server.WebModuleServerActivator;
32 36
 import net.bluemind.webmodule.server.WebResource;
33 37
 
... ...
@@ -52,6 +56,9 @@ public class StaticFileHandler implements Handler<HttpServerRequest> {
52 52
 	private List<WebResource> resources;
53 53
 	private String index;
54 54
 
55
+	private final Registry registry = MetricsRegistry.get();
56
+	private final IdFactory idFactory = new IdFactory(registry, StaticFileHandler.class);
57
+
55 58
 	public StaticFileHandler(Vertx vertx, String webRoot, String index, List<WebResource> resources, boolean gzipFiles,
56 59
 			boolean caching) {
57 60
 		super();
... ...
@@ -190,6 +197,7 @@ public class StaticFileHandler implements Handler<HttpServerRequest> {
190 190
 				if ("HEAD".equals(req.method())) {
191 191
 					req.response().end();
192 192
 				} else {
193
+					registry.counter(idFactory.name("request", "status", "200")).increment();
193 194
 					req.response().sendFile(fileName);
194 195
 				}
195 196
 			}
... ...
@@ -224,6 +232,7 @@ public class StaticFileHandler implements Handler<HttpServerRequest> {
224 224
 	}
225 225
 
226 226
 	private void sendError(HttpServerRequest req, int error, String message) {
227
+		registry.counter(idFactory.name("request", "status", Integer.toString(error))).increment();
227 228
 		req.response().setStatusMessage(message);
228 229
 		req.response().setStatusCode(error);
229 230
 		req.response().end();