Skip to content

Commit

Permalink
Fixed up metrics so that all metrics are correctly shared across the …
Browse files Browse the repository at this point in the history
…application.
  • Loading branch information
Jesse Eichar committed May 9, 2014
1 parent 9918ba1 commit cad1210
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 26 deletions.
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
"com.codahale.metrics:metrics-servlet:$metricsVersion",
"com.codahale.metrics:metrics-httpclient:$metricsVersion",
"com.codahale.metrics:metrics-servlets:$metricsVersion",
"com.codahale.metrics:metrics-jvm:$metricsVersion",
"com.codahale.metrics:metrics-logback:$metricsVersion"
)
def geotoolsVersion = "11.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2014 Camptocamp
*
* This file is part of MapFish Print
*
* MapFish Print is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MapFish Print is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MapFish Print. If not, see <http://www.gnu.org/licenses/>.
*/

package org.mapfish.print.metrics;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.jvm.FileDescriptorRatioGauge;
import com.codahale.metrics.jvm.GarbageCollectorMetricSet;
import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
import com.codahale.metrics.jvm.ThreadStatesGaugeSet;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;

/**
* A bean that will add several gauges and metric sets for tracking the JVM stats.
*
* @author Jesse on 5/9/2014.
*/
public final class JvmMetricsConfigurator {

@Autowired
private MetricRegistry metricRegistry;

/**
* Add several jvm metrics.
*/
@PostConstruct
public void init() {
this.metricRegistry.register(name("gc"), new GarbageCollectorMetricSet());
this.metricRegistry.register(name("memory"), new MemoryUsageGaugeSet());
this.metricRegistry.register(name("thread-states"), new ThreadStatesGaugeSet());
this.metricRegistry.register(name("fd-usage"), new FileDescriptorRatioGauge());
}

private String name(final String metricName) {
return "jvm-" + metricName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2014 Camptocamp
~
~ This file is part of MapFish Print
~
~ MapFish Print is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ MapFish Print is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with MapFish Print. If not, see <http://www.gnu.org/licenses/>.
-->

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
This file is intentionally left empty. Other plugins/configurations can add a file with the same name and the beans
in that file will override the beans defined in the other default spring configuration files
-->
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
~ along with MapFish Print. If not, see <http://www.gnu.org/licenses/>.
-->

<beans default-lazy-init="true" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<beans default-lazy-init="false" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="mapfish-spring-attributes.xml" />
Expand Down Expand Up @@ -61,7 +61,8 @@
<constructor-arg index="1" ref="metricNameStrategy" />
</bean>
<bean id="metricNameStrategy" class="org.mapfish.print.metrics.MetricsNameStrategyFactory" factory-method="hostAndMethod" />
<bean id="loggingMetricsConfigurator" class="org.mapfish.print.metrics.LoggingMetricsConfigurator" />
<bean id="loggingMetricsConfigurator" class="org.mapfish.print.metrics.LoggingMetricsConfigurator" lazy-init="false"/>
<bean id="jvmMetricsConfigurator" class="org.mapfish.print.metrics.JvmMetricsConfigurator" lazy-init="false"/>

<bean id="forkJoinPool" class="jsr166y.ForkJoinPool" destroy-method="shutdownNow">
<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:mapfish-spring-application-context.xml"/>
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<context:annotation-config/>
<bean id="servlet" class="org.mapfish.print.servlet.OldAPIMapPrinterServlet"/>
<bean id="mapPrinterFactory" class="org.mapfish.print.servlet.ServletMapPrinterFactory">
<property name="configurationFiles">
<map>
<entry key="default" value="servlet:///config.yaml" />
</map>
</property>
</bean>

</beans>
26 changes: 26 additions & 0 deletions core/src/main/webapp/WEB-INF/mapfish-print-printer-factory.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2014 Camptocamp
~
~ This file is part of MapFish Print
~
~ MapFish Print is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ MapFish Print is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with MapFish Print. If not, see <http://www.gnu.org/licenses/>.
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mapPrinterFactory" class="org.mapfish.print.servlet.ServletMapPrinterFactory">
<property name="appsRootDirectory" value="servlet:///print-apps" />
</bean>
</beans>
11 changes: 5 additions & 6 deletions core/src/main/webapp/WEB-INF/mapfish-print-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
-->

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:mapfish-spring-application-context.xml"/>
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<context:annotation-config/>
<bean id="servlet" class="org.mapfish.print.servlet.MapPrinterServlet">
<property name="maxCreateAndGetWaitTimeInSeconds" value="30" />
</bean>
<bean id="mapPrinterFactory" class="org.mapfish.print.servlet.ServletMapPrinterFactory">
<property name="appsRootDirectory" value="servlet:///print-apps" />
</bean>

<import resource="classpath*:mapfish-spring-application-context-override.xml" />
</beans>
23 changes: 16 additions & 7 deletions core/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
-->

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:mapfish-spring-application-context.xml,/WEB-INF/mapfish-print-printer-factory.xml,classpath*:mapfish-spring-application-context-override.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Expand All @@ -36,12 +42,6 @@
<listener-class>org.mapfish.print.metrics.MapfishPrintInstrumentedFilterContextListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:mapfish-spring-application-context.xml
</param-value>
</context-param>

<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
Expand All @@ -55,6 +55,15 @@
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>instrumentedFilter</filter-name>
<filter-class>com.codahale.metrics.servlet.InstrumentedFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>instrumentedFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>metrics-servlet</servlet-name>
<servlet-class>com.codahale.metrics.servlets.AdminServlet</servlet-class>
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ function splitJvmOpts() {
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "${JVM_OPTS[@]}" "-XX:MaxPermSize=128M" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ set CMD_LINE_ARGS=%$
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" "-XX:MaxPermSize=128M" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
Expand Down

0 comments on commit cad1210

Please sign in to comment.