Skip to content

Commit

Permalink
updated pom with latest versions, examples with latest automon versio…
Browse files Browse the repository at this point in the history
…n, and added tests
  • Loading branch information
stevensouza committed Apr 26, 2019
1 parent 85718d6 commit 533aeab
Show file tree
Hide file tree
Showing 25 changed files with 184 additions and 68 deletions.
28 changes: 15 additions & 13 deletions automon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,39 @@
<parent>
<groupId>org.automon</groupId>
<artifactId>automon_parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.3</version>
</parent>

<groupId>org.automon</groupId>
<artifactId>automon</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.3</version>
<packaging>jar</packaging>
<name>automon</name>
<description>Automon combines the power of AOP (AspectJ) with any monitoring or logging tools you already use to declaratively monitor
your Java code, the JDK, and dependent libraries. This module generates the core automon aspect library.
</description>

<properties>
<metrics.version>3.1.0</metrics.version>
<metrics.version>4.0.5</metrics.version>
<jamonapi.version>2.81</jamonapi.version>
<javasimon.version>4.1.1</javasimon.version>
<assertj.version>1.7.0</assertj.version>
<aspectj.version>1.8.2</aspectj.version>
<javasimon.version>4.1.4</javasimon.version>
<assertj.version>3.12.2</assertj.version>
<aspectj.version>1.9.3</aspectj.version>
<mojo.ajc.version>1.7</mojo.ajc.version>
<mojo.execution.version>1.3.2</mojo.execution.version>
<mockito.version>1.9.5</mockito.version>
<junit.version>4.11</junit.version>
<mockito.version>1.10.19</mockito.version>
<junit.version>4.12</junit.version>
<perf4j.version>0.9.16</perf4j.version>
<newrelic.version>3.29.0</newrelic.version>
<ejb.version>3.2</ejb.version>
<spring.version>4.1.1.RELEASE</spring.version>
<spring.aop.version>1.8.0</spring.aop.version>
<jaxrs.version>2.0.1</jaxrs.version>
<newrelic.version>5.0.0</newrelic.version>
<ejb.version>3.2.2</ejb.version>
<spring.version>5.1.6.RELEASE</spring.version>
<spring.aop.version>1.9.3</spring.aop.version>
<jaxrs.version>2.1.1</jaxrs.version>
<jpa.version>1.0.1.Final</jpa.version>
<statsd.version>3.1.0</statsd.version>
<micrometer.version>1.1.4</micrometer.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
Expand Down
22 changes: 20 additions & 2 deletions automon/src/main/java/org/automon/implementations/Micrometer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
/**
* {@link org.automon.implementations.OpenMon} implementation that https://micrometer.io to time methods, and count exceptions.
* Note micrometer is a wrapper for many underlying monitoring api's. It is also the default monitoring api of Spring.
*
* To have this object share the same MeterRegistry as spring simply access it MetricRegistry via @Autowired and then call
* this classes Micrometer.setMeterRegistry(springMeterRegistry) with Springs value. Example:
*
* @Autowired
* public MetricsController(MeterRegistry registry) {
* Micrometer.setMeterRegistry(registry);
* }
*
* # For spring see see data at http://localhost:8080/actuator/metrics
* # or you can look at an individual metric like this
*
* # http://localhost:8080/actuator/metrics/execution(int org.tempuri.AddResponse.getAddResult())
* # or
* # http://localhost:8080/actuator/metrics/execution(int%20org.tempuri.AddResponse.getAddResult())
*
* To enable this class for monitoring put the following in automon.properties
* #org.automon=micrometer
*/
public class Micrometer extends OpenMonBase<TimerContext> {

Expand Down Expand Up @@ -43,7 +61,7 @@ protected void trackException(JoinPoint jp, Throwable throwable) {
*/
protected Timer getTimer(String methodName) {
return Timer.builder(methodName)
.tag("automon.method", "org.automon.Method")
.tag("automon", "method")
.description("automon.org method timer")
.register(registry);
}
Expand All @@ -56,7 +74,7 @@ protected Timer getTimer(String methodName) {
*/
protected Counter getCounter(String exceptionName) {
return Counter.builder(exceptionName)
.tag("automon.exception", EXCEPTION_LABEL)
.tag("automon", "exception")
.description("automon.org exception counter")
.register(registry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public class MetricsTest {

@Before
public void setUp() throws Exception {
Metrics.setMetricRegistry(new MetricRegistry());
JoinPoint.StaticPart staticPart = mock(JoinPoint.StaticPart .class);
when(staticPart.toString()).thenReturn(SharedConstants.LABEL);
}
@After
public void tearDown() throws Exception {
Metrics.setMetricRegistry(new MetricRegistry());
}

@Test
Expand Down Expand Up @@ -60,8 +62,8 @@ public void testException() throws Exception {
@Test
public void setMetricRegistry() throws Exception {
MetricRegistry newMetricRegistry = new MetricRegistry();
openMon.setMetricRegistry(newMetricRegistry);
assertThat(openMon.getMetricRegistry()).isEqualTo(newMetricRegistry);
Metrics.setMetricRegistry(newMetricRegistry);
assertThat(Metrics.getMetricRegistry()).isEqualTo(newMetricRegistry);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.automon.implementations;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.aspectj.lang.JoinPoint;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;


public class MicrometerTest {
private Micrometer openMon = new Micrometer();
private JoinPoint jp = mock(JoinPoint.class);
private JoinPoint.StaticPart staticPart = mock(JoinPoint.StaticPart .class);

@Before
public void setUp() throws Exception {
Micrometer.setMeterRegistry(new SimpleMeterRegistry());
when(staticPart.toString()).thenReturn(SharedConstants.LABEL);
}
@After
public void tearDown() throws Exception {
Micrometer.setMeterRegistry(new SimpleMeterRegistry());
}

@Test
public void testStart() throws Exception {
TimerContext mon = openMon.start(staticPart);
assertThat(openMon.getTimer(staticPart.toString()).count()).describedAs("A timer that wasn't started should not have a count").isEqualTo(0);
}

@Test
public void testStop() throws Exception {
TimerContext mon = openMon.start(staticPart);
sleep(250);
openMon.stop(mon);
assertThat(openMon.getTimer(staticPart.toString()).count())
.describedAs("The timer should have completed/been stopped").isEqualTo(1);
assertThat(openMon.getTimer(staticPart.toString()).totalTime(TimeUnit.MILLISECONDS))
.describedAs("The timer should have expected time").isGreaterThanOrEqualTo(250);
}

private void sleep(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

@Test
public void testTimerNotNull() {
assertThat(openMon.getTimer(staticPart.toString())).isNotNull();
}

@Test
public void testCounterNotNull() {
assertThat(openMon.getCounter(SharedConstants.EXCEPTION_LABEL)).isNotNull();
}

@Test
public void testStopWithException() throws Exception {
TimerContext mon = openMon.start(staticPart);
openMon.stop(mon, new RuntimeException("my exception"));
assertThat(openMon.getTimer(staticPart.toString()).count())
.describedAs("The timer should have completed/been stopped").isEqualTo(1);
}

@Test
public void testException() throws Exception {
assertThat(openMon.getCounter(SharedConstants.EXCEPTION_LABEL).count())
.describedAs("No exception should exist yet").isEqualTo(0);
openMon.exception(jp, SharedConstants.EXCEPTION);
assertThat(openMon.getCounter(SharedConstants.EXCEPTION_LABEL).count())
.describedAs("One exception should exist").isEqualTo(1);
}


@Test
public void setMetricRegistry() throws Exception {
MeterRegistry registry = new SimpleMeterRegistry();
Micrometer.setMeterRegistry(registry);
assertThat( Micrometer.getMeterRegistry()).isEqualTo(registry);
}

}
2 changes: 1 addition & 1 deletion examples/change-version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Note make sure the following command doesn't execute against this file!
# This could be done by renaming this file temporarily and manually
# executing the command
# sed -i.tmp "s/1.0.1/1.0.2-SNAPSHOT/g" *.sh
# sed -i.tmp "s/1.0.3-SNAPSHOT/1.0.3/g" *.sh
2 changes: 1 addition & 1 deletion examples/example-with-annotions-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# The following executes a simple program and monitors any classes/methods with the automon Monitor annotation
# Load time weaving is performed so the aspectjweaver.jar is used.
# The program being monitored is in playground-1.0.jar
java -Dorg.automon=sysout -Dorg.aspectj.weaver.loadtime.configuration=file:config/ajc-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:libs/playground-1.0.jar com.stevesouza.automon.annotations.AnnotationTester
java -Dorg.automon=sysout -Dorg.aspectj.weaver.loadtime.configuration=file:config/ajc-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:libs/playground-1.0.jar com.stevesouza.automon.annotations.AnnotationTester
4 changes: 2 additions & 2 deletions examples/hello-world-jamon-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
# Yammer Metrics or JavaSimon could be done in a similar way. Note -Dorg.automon=jamon is not specified below. Instead
# Automon recognizes that Jamon is available and so uses it.

java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:../helloworld_unwoven_jamon/target/helloworld_unwoven_jamon-1.0.3-SNAPSHOT.jar:libs/jamon-2.81.jar com.stevesouza.jamon.JamonHelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:../helloworld_unwoven_jamon/target/helloworld_unwoven_jamon-1.0.3.jar:libs/jamon-2.81.jar com.stevesouza.jamon.JamonHelloWorld
# to run the program in a loop for 1000 times (allows time to look at automon jmx in jconsole)
#java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:../helloworld_unwoven_jamon/target/helloworld_unwoven_jamon-1.0.3-SNAPSHOT.jar:libs/jamon-2.81.jar com.stevesouza.jamon.JamonHelloWorld 1000
#java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:../helloworld_unwoven_jamon/target/helloworld_unwoven_jamon-1.0.3.jar:libs/jamon-2.81.jar com.stevesouza.jamon.JamonHelloWorld 1000
6 changes: 3 additions & 3 deletions examples/hello-world-javasimon-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# StatsD or JAMon could be done in a similar way. Note -Dorg.automon=javasimon is not specified below. Instead
# Automon recognizes that Metrics is in the class path and so uses it.

# java -Dorg.automon=javasimon -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld
# java -Dorg.automon=javasimon -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld

# to run the program in a loop for 1000 times (allows time to look at automon jmx in jconsole)
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld 1000
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/javasimon-core-4.1.1.jar com.stevesouza.helloworld.HelloWorld 1000
6 changes: 3 additions & 3 deletions examples/hello-world-metrics-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# StatsD or JavaSimon could be done in a similar way. Note -Dorg.automon=metrics is not specified below. Instead
# Automon recognizes that Metrics is in the class path and so uses it.

# java -Dorg.automon=metrics -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld
# java -Dorg.automon=metrics -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld

# to run the program in a loop for 1000 times (allows time to look at automon jmx in jconsole)
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld 1000
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/metrics-core-3.1.0.jar com.stevesouza.helloworld.HelloWorld 1000
6 changes: 3 additions & 3 deletions examples/hello-world-newrelic-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# StatsD or JavaSimon could be done in a similar way. Note -Dorg.automon=newrelic is not specified below. Instead
# Automon recognizes that Metrics is in the class path and so uses it.

# java -Dorg.automon=newrelic -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld
# java -Dorg.automon=newrelic -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld

# to run the program in a loop for 1000 times (allows time to look at automon jmx in jconsole)
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld 1000
# java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/newrelic-api-3.29.0.jar com.stevesouza.helloworld.HelloWorld 1000
6 changes: 3 additions & 3 deletions examples/hello-world-statsd-ltw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# Automon recognizes that StatsD is in the class path and so uses it. Note the StatsD server must be up and running for the
# sample program to save data.

#java -Dorg.automon=statsd -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld 100
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld
#java -Dorg.automon=statsd -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld 100
java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld

# to run the program in a loop for 1000 times (allows time to look at automon jmx in jconsole)
#java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3-SNAPSHOT.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3-SNAPSHOT.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld 100
#java -Dorg.aspectj.weaver.loadtime.configuration=file:config/hello-world-unwoven-aop.xml -javaagent:libs/aspectjweaver.jar -classpath ../automon/target/automon-1.0.3.jar:../helloworld_unwoven/target/helloworld_unwoven-1.0.3.jar:libs/java-statsd-client-3.1.0.jar com.stevesouza.helloworld.HelloWorld 100
Loading

0 comments on commit 533aeab

Please sign in to comment.