cleanup work after metrics no longer needed in custom project

This commit is contained in:
eugenp 2013-08-11 13:37:48 +03:00
parent dce40f3492
commit a72cec5f10
6 changed files with 6 additions and 80 deletions

View File

@ -6,7 +6,6 @@
### Relevant Articles:
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
- [Redirect to different pages after Login with Spring Security](http://www.baeldung.com/spring_redirect_after_login)
- [HttpSessionListener Example Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)
### Build the Project

View File

@ -93,12 +93,12 @@
</dependency>
<!-- ops -->
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.1</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.codahale.metrics</groupId> -->
<!-- <artifactId>metrics-core</artifactId> -->
<!-- <version>3.0.1</version> -->
<!-- </dependency> -->
<!-- test scoped -->

View File

@ -1,25 +0,0 @@
package org.baeldung.monitoring;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
public final class MetricRegistrySingleton {
public static final MetricRegistry metrics = new MetricRegistry();
static {
Logger logger = LoggerFactory.getLogger("org.baeldung.monitoring");
final Slf4jReporter reporter = Slf4jReporter.forRegistry(metrics).outputTo(logger).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.start(5, TimeUnit.MINUTES);
}
private MetricRegistrySingleton() {
throw new AssertionError();
}
}

View File

@ -1,43 +0,0 @@
package org.baeldung.web;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.baeldung.monitoring.MetricRegistrySingleton;
import com.codahale.metrics.Counter;
public class SessionListenerWithMetrics implements HttpSessionListener {
private final AtomicInteger activeSessions;
private final Counter counterOfActiveSessions;
public SessionListenerWithMetrics() {
super();
activeSessions = new AtomicInteger();
counterOfActiveSessions = MetricRegistrySingleton.metrics.counter("web.sessions.active.count");
}
// API
public final int getTotalActiveSession() {
return activeSessions.get();
}
@Override
public final void sessionCreated(final HttpSessionEvent event) {
activeSessions.incrementAndGet();
counterOfActiveSessions.inc();
}
@Override
public final void sessionDestroyed(final HttpSessionEvent event) {
activeSessions.decrementAndGet();
counterOfActiveSessions.dec();
}
}

View File

@ -9,9 +9,6 @@
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<listener>
<listener-class>org.baeldung.web.SessionListenerWithMetrics</listener-class>
</listener>
<!-- Spring root -->
<context-param>

View File

@ -4,8 +4,6 @@
### Relevant Articles:
- [Spring Security Remember Me](http://www.baeldung.com/spring-security-remember-me)
- [Redirect to different pages after Login with Spring Security](http://www.baeldung.com/spring_redirect_after_login)
- [HttpSessionListener Example Monitoring](http://www.baeldung.com/httpsessionlistener_with_metrics)