Move boot metric to rest full
This commit is contained in:
parent
a703253af9
commit
fb3645d1e8
|
@ -24,7 +24,6 @@ public class SampleLDAPApplication extends WebMvcConfigurerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
public void addViewControllers(ViewControllerRegistry registry) {
|
||||||
registry.addViewController("/login").setViewName("login");
|
registry.addViewController("/login").setViewName("login");
|
||||||
registry.addViewController("/graph").setViewName("graph");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,15 +7,11 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.baeldung.metric.IMetricService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring Controller Definitions.
|
* Spring Controller Definitions.
|
||||||
|
@ -23,9 +19,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
@Controller
|
@Controller
|
||||||
public class MyController {
|
public class MyController {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IMetricService metricService;
|
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public String init(Map<String, Object> model, Principal principal) {
|
public String init(Map<String, Object> model, Principal principal) {
|
||||||
model.put("title", "PUBLIC AREA");
|
model.put("title", "PUBLIC AREA");
|
||||||
|
@ -44,12 +37,6 @@ public class MyController {
|
||||||
return "home";
|
return "home";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/metric-graph-data", method = RequestMethod.GET)
|
|
||||||
@ResponseBody
|
|
||||||
public Object[][] getMetricData() {
|
|
||||||
return metricService.getGraphData();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUserName(Principal principal) {
|
private String getUserName(Principal principal) {
|
||||||
if (principal == null) {
|
if (principal == null) {
|
||||||
return "anonymous";
|
return "anonymous";
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package org.baeldung.metric;
|
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.FilterConfig;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.ServletResponse;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class MetricFilter implements Filter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IMetricService metricService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(final FilterConfig config) throws ServletException {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws java.io.IOException, ServletException {
|
|
||||||
chain.doFilter(request, response);
|
|
||||||
|
|
||||||
final int status = ((HttpServletResponse) response).getStatus();
|
|
||||||
metricService.increaseCount(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Metric Graph</title>
|
|
||||||
<script
|
|
||||||
src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
|
||||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
google.load("visualization", "1", {
|
|
||||||
packages : [ "corechart" ]
|
|
||||||
});
|
|
||||||
|
|
||||||
function drawChart() {
|
|
||||||
$.get("http://localhost:8080/metric-graph-data",
|
|
||||||
function(mydata) {
|
|
||||||
|
|
||||||
var data = google.visualization.arrayToDataTable(mydata);
|
|
||||||
var options = {
|
|
||||||
title : 'Website Metric',
|
|
||||||
hAxis : {
|
|
||||||
title : 'Time',
|
|
||||||
titleTextStyle : {
|
|
||||||
color : '#333'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
vAxis : {
|
|
||||||
minValue : 0
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var chart = new google.visualization.AreaChart(document
|
|
||||||
.getElementById('chart_div'));
|
|
||||||
chart.draw(data, options);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body onload="drawChart()">
|
|
||||||
<div id="chart_div" style="width: 900px; height: 500px;"></div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -9,17 +9,35 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- Spring Boot Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- <dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency> -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.aspectj</groupId>
|
||||||
|
<artifactId>aspectjweaver</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- Spring Security -->
|
<!-- Spring Security -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-web</artifactId>
|
<artifactId>spring-security-web</artifactId>
|
||||||
<version>${org.springframework.security.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-config</artifactId>
|
<artifactId>spring-security-config</artifactId>
|
||||||
<version>${org.springframework.security.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
|
@ -27,7 +45,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>commons-logging</artifactId>
|
<artifactId>commons-logging</artifactId>
|
||||||
|
@ -38,43 +55,35 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-jdbc</artifactId>
|
<artifactId>spring-jdbc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-aop</artifactId>
|
<artifactId>spring-aop</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-tx</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-expression</artifactId>
|
<artifactId>spring-expression</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Querydsl -->
|
<!-- Querydsl -->
|
||||||
|
@ -113,17 +122,14 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-orm</artifactId>
|
<artifactId>spring-orm</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-jpa</artifactId>
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
<version>${spring-data-jpa.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
<artifactId>hibernate-entitymanager</artifactId>
|
<artifactId>hibernate-entitymanager</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xml-apis</groupId>
|
<groupId>xml-apis</groupId>
|
||||||
|
@ -133,12 +139,10 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javassist</groupId>
|
<groupId>org.javassist</groupId>
|
||||||
<artifactId>javassist</artifactId>
|
<artifactId>javassist</artifactId>
|
||||||
<version>3.19.0-GA</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>${mysql-connector-java.version}</version>
|
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -147,7 +151,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.0.1</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -162,7 +165,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -184,24 +186,20 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
<!-- <scope>runtime</scope> -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
|
@ -209,7 +207,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>spring-test</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -266,7 +263,6 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.7</source>
|
||||||
<target>1.7</target>
|
<target>1.7</target>
|
||||||
|
@ -276,13 +272,11 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>${maven-war-plugin.version}</version>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/*IntegrationTest.java</exclude>
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.baeldung.spring;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main Application Class - uses Spring Boot. Just run this as a normal Java
|
||||||
|
* class to run up a Jetty Server (on http://localhost:8080)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@EnableScheduling
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@ComponentScan("org.baeldung")
|
||||||
|
public class Application extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
|
public static void main(final String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.baeldung.web.metric.IActuatorMetricService;
|
||||||
import org.baeldung.web.metric.IMetricService;
|
import org.baeldung.web.metric.IMetricService;
|
||||||
import org.baeldung.web.util.LinkUtil;
|
import org.baeldung.web.util.LinkUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -23,6 +24,9 @@ public class RootController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMetricService metricService;
|
private IMetricService metricService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IActuatorMetricService actMetricService;
|
||||||
|
|
||||||
public RootController() {
|
public RootController() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -62,4 +66,10 @@ public class RootController {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/metric-graph-data", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public Object[][] getActuatorMetricData() {
|
||||||
|
return actMetricService.getGraphData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.baeldung.metric;
|
package org.baeldung.web.metric;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -13,7 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MetricService implements IMetricService {
|
public class ActuatorMetricService implements IActuatorMetricService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MetricRepository repo;
|
private MetricRepository repo;
|
||||||
|
@ -25,7 +25,7 @@ public class MetricService implements IMetricService {
|
||||||
private final List<String> statusList;
|
private final List<String> statusList;
|
||||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
public MetricService() {
|
public ActuatorMetricService() {
|
||||||
super();
|
super();
|
||||||
statusMetric = new ArrayList<ArrayList<Integer>>();
|
statusMetric = new ArrayList<ArrayList<Integer>>();
|
||||||
statusList = new ArrayList<String>();
|
statusList = new ArrayList<String>();
|
|
@ -1,6 +1,6 @@
|
||||||
package org.baeldung.metric;
|
package org.baeldung.web.metric;
|
||||||
|
|
||||||
public interface IMetricService {
|
public interface IActuatorMetricService {
|
||||||
|
|
||||||
void increaseCount(final int status);
|
void increaseCount(final int status);
|
||||||
|
|
|
@ -9,15 +9,20 @@ import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class MetricFilter implements Filter {
|
public class MetricFilter implements Filter {
|
||||||
|
|
||||||
private MetricService metricService;
|
@Autowired
|
||||||
|
private IMetricService metricService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IActuatorMetricService actMetricService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(final FilterConfig config) throws ServletException {
|
public void init(final FilterConfig config) throws ServletException {
|
||||||
metricService = (MetricService) WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext()).getBean("metricService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +34,7 @@ public class MetricFilter implements Filter {
|
||||||
|
|
||||||
final int status = ((HttpServletResponse) response).getStatus();
|
final int status = ((HttpServletResponse) response).getStatus();
|
||||||
metricService.increaseCount(req, status);
|
metricService.increaseCount(req, status);
|
||||||
|
actMetricService.increaseCount(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue