Commits

Micha Kops committed 5fa860e

Initial import.

  • Participants

Comments (0)

Files changed (5)

+.project
+.settings
+.classpath
+target
+# Java EE 7 Metrics JMX Tutorial
+
+Examples showing how to aggregate performance indicators in a Java EE 7 Web application running on WildFly and using the Metrics library.
+
+For more detailed information, please feel free to have a look at [my blog].
+
+----
+
+**2014 Micha Kops / hasCode.com**
+
+   [my blog]:http://www.hascode.com/
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.hascode.tutorial</groupId>
+	<artifactId>metrics-jmx-reporting</artifactId>
+	<version>1.0.0</version>
+	<packaging>war</packaging>
+
+	<name>metrics-jmx-reporting</name>
+	
+	<prerequisites>
+		<maven>3.0.4</maven>
+	</prerequisites>
+
+	<properties>
+		<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
+
+	<dependencies>
+		<dependency>
+			<groupId>javax</groupId>
+			<artifactId>javaee-web-api</artifactId>
+			<version>7.0</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.yammer.metrics</groupId>
+			<artifactId>metrics-core</artifactId>
+			<version>2.2.0</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.1</version>
+				<configuration>
+					<source>1.7</source>
+					<target>1.7</target>
+					<compilerArguments>
+						<endorseddirs>${endorsed.dir}</endorseddirs>
+					</compilerArguments>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-war-plugin</artifactId>
+				<version>2.3</version>
+				<configuration>
+					<failOnMissingWebXml>false</failOnMissingWebXml>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<version>2.6</version>
+				<executions>
+					<execution>
+						<phase>validate</phase>
+						<goals>
+							<goal>copy</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${endorsed.dir}</outputDirectory>
+							<silent>true</silent>
+							<artifactItems>
+								<artifactItem>
+									<groupId>javax</groupId>
+									<artifactId>javaee-endorsed-api</artifactId>
+									<version>7.0</version>
+									<type>jar</type>
+								</artifactItem>
+							</artifactItems>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.wildfly.plugins</groupId>
+				<artifactId>wildfly-maven-plugin</artifactId>
+				<version>1.0.2.Final</version>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>

src/main/java/com/hascode/tutorial/ejb/ExampleMetricsBean.java

+package com.hascode.tutorial.ejb;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.Schedule;
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+
+import com.yammer.metrics.core.Counter;
+import com.yammer.metrics.core.MetricsRegistry;
+import com.yammer.metrics.reporting.JmxReporter;
+
+@Singleton
+@Startup
+public class ExampleMetricsBean {
+	private Counter numReqSend;
+	private MetricsRegistry registry;
+	private JmxReporter reporter;
+
+	@PostConstruct
+	protected void onBeanConstruction() {
+		registry = new MetricsRegistry();
+		numReqSend = registry.newCounter(ExampleMetricsBean.class, "Number-of-Request");
+		reporter = new JmxReporter(registry);
+		reporter.start();
+	}
+
+	@PreDestroy
+	protected void onBeanDestruction() {
+		reporter.shutdown();
+		registry.shutdown();
+	}
+
+	@Schedule(second = "*/10", minute = "*", hour = "*")
+	public void doSth() {
+		System.err.println("xxxxxx");
+		numReqSend.inc();
+	}
+}

src/main/webapp/index.html

+<!DOCTYPE html>
+<html>
+    <head>
+        <title>Start Page</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    </head>
+    <body>
+        <h1>Hello World!</h1>
+    </body>
+</html>