From ffe552af836fb4efa36474a639425f0d058c8bb9 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 21 Mar 2015 22:59:21 +0200 Subject: [PATCH] modify metric --- .../org/baeldung/web/controller/RootController.java | 6 ++++++ .../java/org/baeldung/web/metric/MetricService.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java index 88399eaa9d..95b3f996ec 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java @@ -45,4 +45,10 @@ public class RootController { public String getMetric() { return metricService.getFullMetric(); } + + @RequestMapping(value = "/status-metric", method = RequestMethod.GET) + @ResponseBody + public String getStatusMetric() { + return metricService.getStatusMetric(); + } } diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java b/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java index 42d150d2ed..4fd7955b75 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/metric/MetricService.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; public class MetricService { private static HashMap> metricMap = new HashMap>(); + private static HashMap statusMetric = new HashMap(); public MetricService() { super(); @@ -27,9 +28,20 @@ public class MetricService { } statusMap.put(status, count); metricMap.put(request, statusMap); + + final Integer statusCount = statusMetric.get(status); + if (statusCount == null) { + statusMetric.put(status, 1); + } else { + statusMetric.put(status, statusCount + 1); + } } public String getFullMetric() { return metricMap.entrySet().toString(); } + + public String getStatusMetric() { + return statusMetric.entrySet().toString(); + } }