Menu

JAMon Spring integration

Mike Guo
2015-04-16
2016-04-19
  • Mike Guo

    Mike Guo - 2015-04-16

    hi

    I am trying to configure JAMon into my Spring application, in order to
    monitor requests and transactions.

    However now I am still confused about how to deploy jamon.jar to allow both
    Spring application and jamon.war use the jamon.jar at same time.

    The jamon.jar must somehow expose to Spring application to enable the
    configuration in ApplicationContext.xml

    <!-- JAMon performance monitoring -->
     <bean id="jamonAspect" class="com.jamonapi.aop.spring.JamonAspect">
        <!-- <property name="exceptionBufferListener" value="true" />
        <property name="useArgsWithExceptionDetails" value="true"/>
        <property name="useArgsWithMethodDetails" value="true"/>  -->
    </bean>
    <aop:config>
        <aop:pointcut id="jamonMonitoringPointcut"
                      expression="execution(*
    

    com.transoftinc.vlm.carrierweb.controller...(..)) || execution(
    com.transoftinc.vlm.carrierweb.service..
    .*(..)) "/>
    <aop:aspect id="jamonSpringAspect" ref="jamonAspect">
    <aop:around pointcut-ref="jamonMonitoringPointcut" method="monitor"/>
    </aop:aspect>
    </aop:config>

    but jamon.jar should not include in appliction's WEB-INF/lib in application
    server, so I have to avoid it

        <dependency>
            <groupId>com.jamonapi</groupId>
            <artifactId>jamon</artifactId>
            <version>2.81</version>
            <!--avoid it! not included in deployment lib folder-->
            <scope>provided</scope>
        </dependency>
    

    However, jamon-2.81.pom requires other parent dependencies, including
    log4j, aspectj-xxx

    aspectjrt-1.7.4.jar
    aspectjtools-1.7.4.jar
    aspectjweaver-1.7.4.jar
    jamon-2.81.jar
    log4j-1.2.17.jar

    which are also dependencies in the Spring application, so I have to copy
    those dependencies from maven repository to Catalina_home/lib, then I get
    this error

    log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    log4j:ERROR [WebappClassLoader
    context: /OptiVLM-CarrierWeb
    delegate: false
    repositories:
    /WEB-INF/classes/
    ----------> Parent Classloader:
    org.apache.catalina.loader.StandardClassLoader@4f8235ed
    ]
    whereas object of type
    log4j:ERROR "com.jamonapi.log4j.JAMonAppender" was loaded by
    [org.apache.catalina.loader.StandardClassLoader@4f8235ed].
    log4j:ERROR Could not instantiate appender named "jamonAppender".

    If I only leave jamon-2.81.jar in the CATALINA_HOME/lib

    aspectjrt-1.7.4.jar
    aspectjtools-1.7.4.jar
    aspectjweaver-1.7.4.jar
    jamon-2.81.jar
    log4j-1.2.17.jar

    I got

    java.lang.NoClassDefFoundError: org/apache/log4j/AppenderSkeleton
    and
    java.lang.ClassNotFoundException: org.aspectj.lang.ProceedingJoinPoint

    so it looks like both log4j and aspectj dependencies are not found(they
    definitely exist in WEB-INF/lib, but jamon-2.81.jar from CATALINA_HOME/lib
    cannot find them.

    If I remove the <scope>provided</scope> tag, of course there will be not
    error but also there won't be any message show up on jamon console(because
    there are different jamon.jar works for spring application and jamon.war
    respectively)

    This made me wondering may be JAMon is not sutable for this kind of
    situation? is there anyway we can fix it, so both Spring and Jamon.war can
    running on same jamon.jar?

    Thanks a lot in advance

     
  • Steve Souza

    Steve Souza - 2015-04-16

    This should work. Jamon should have no other dependencies required. i.e. you don't need to install aspectj, log4j etc unless some other library uses them.

    For example it shouldn't need log4j unless you specifically use the jamon log4j appender.

    "java.lang.NoClassDefFoundError: org/apache/log4j/AppenderSkeleton
    and
    java.lang.ClassNotFoundException: org.aspectj.lang.ProceedingJoinPoint "
    What caused this?

    Follow the directions here for tomcat. You don't have to install the valve if it isn't needed: http://jamonapi.sourceforge.net/http_monitoring.html

     

    Last edit: Steve Souza 2015-04-16
  • Steve Souza

    Steve Souza - 2015-04-16

    "If I remove the <scope>provided</scope> tag, of course there will be not
    error but also there won't be any message show up on jamon console(because
    there are different jamon.jar works for spring application and jamon.war
    respectively)"

    • The spring application and jamon.war need to share the same jamon-2.81.jar file which should be put at the server level (tomcat /lib directory).
    • Jamon jar has no further dependencies. The other dependencies are used to compile jamon, but aren't needed at runtime unless you use these capabilities which Spring does not.
    • Maybe I could improve this intent with the pom.xml file. Ideas?
     

    Last edit: Steve Souza 2015-04-16
    • Mike Guo

      Mike Guo - 2015-04-16
      • Maybe I could improve this intent with the pom.xml file. Ideas?

      I can imagine different users of JAMon may running different version of Spring and AOP. One way to make those version configurable is take the value from external properties:

      http://mojo.codehaus.org/properties-maven-plugin/

      so you can leave default value for those <xxx-version> tags in a properties file and change them by need. But I don't think this can be helpful for a dependency from maven repository(should be plug n play?), well maven has limitations.

      But JAMon is the best ! :)

       
  • Mike Guo

    Mike Guo - 2015-04-16

    Hi Steve

    Thanks for the quick reply! Well first thanks for the awesome tool !!!! :D

    I forget to attach the log4j configuration:

    log4j.logger.com.jamonapi.log4j=DEBUG, jamonAppender
    log4j.appender.jamonAppender=com.jamonapi.log4j.JAMonAppender
    log4j.appender.jamonAppender.EnableListeners=DEBUG

    this pretty much defines how Log4j associate with JAMon and I think that's how the "class not found exception is thrown"

    "For example it shouldn't need log4j unless you specifically use the jamon log4j appender."

    really??????
    so jamon log4j appender is not required?

    then that brings another question:

    how jamon.war can feel the update from spring application? is it through hsql and jetty?

    if jamon log4j appender, how jamon can persist the performance information and how jamon.war detect the update?

    Mike Guo

     
  • Steve Souza

    Steve Souza - 2015-04-16

    "really??????
    so jamon log4j appender is not required?"
    Correct. The log4j appender counts method calls to INFO, WARN, DEBUG, ERROR, FATAL. If you don't need this capability then you don't need to install log4j.

    This capability has nothing to do with spring. Here is more info on it. Jamon support was built into spring and so spring calls jamon natively. No other libraries are required.

    "if jamon log4j appender, how jamon can persist the performance information.."
    Data is in memory. The jamon persister can save the data to disk on a timer though. I think that is done by default.

    "and how jamon.war detect the update?"
    Like any other shared libary. Both spring and jamon war have access to it because it is in the server's /lib directory. Spring writes to it and jamon.war reads from it. Note you can also view the data in jmx.

     

    Last edit: Steve Souza 2015-04-16
    • Mike Guo

      Mike Guo - 2015-04-16

      Awesome !

      one more question: I go over threads in the forum and it looks JAMon is capable of persist the log into db as well --- but it will have impact on performance by itself I think? Then I assume the best way to persist the log information is through Jamon war to export from UI?

       
  • Steve Souza

    Steve Souza - 2015-04-16

    "Well first thanks for the awesome tool !!!! :D"
    Thanks, appreciation is always appreciated :)

     

    Last edit: Steve Souza 2015-04-16
  • Steve Souza

    Steve Souza - 2015-04-16

    "one more question: I go over threads in the forum and it looks JAMon is capable of persist the log into db as well --- but it will have impact on performance by itself I think? "
    The whole jamon structure is serializable so I suppose that could be serialized into a database.
    i.e MonitorComposite serializeMe = MonitorFactory. getRootMonitor();

    Check out this link http://jamonapi.sourceforge.net/distributed_jamon.html. It focuses on 'saving' data with hazelcast, but the principle is pretty generic...Serialize the jamon data anywhere on a timer. In particular you might want to look at the videos on this page as well as look at the JamonDataPersister interface: https://sourceforge.net/p/jamonapi/jamonapi/ci/master/tree/jamon/src/main/java/com/jamonapi/distributed/JamonDataPersister.java

    You could provide an implementation of this to save data to a database.

    Here is a paragraph from the link: Saving of JAMon data is done with a "JamonDataPersister. Developers can provide their own implementations too. JAMon implements this capability with a new interface (JamonDataPersister) which is called from the timer. A JamonDataPersister implementation enables a developer to do anything they want with the serializable JAMon data (MonitorComposite). JamonDataPersister has three primary methods: put, get, remove. They are used to save, retrieve, and delete JAMon data associated with a specific server."

    "Then I assume the best way to persist the log information is through Jamon war to export from UI?"
    This could be done too. You should be able to use the rest api to grab the data in xml, or csv. I would probably implement it by providing an implementation of JamonDataPersister.

     

    Last edit: Steve Souza 2015-04-16
    • Mike Guo

      Mike Guo - 2015-04-17

      Hi Steve

      Thanks for the information, so with above description, is jamon.war required if just use org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor? I see the api provided by Spring is very handy, but not sure how to establish the result (on ui or in the log, ui gonna be preferred :) ).

       
  • Steve Souza

    Steve Souza - 2015-04-16

    Also I have a new open source project that is complimentary to JAMon called Automon (automon.org). It let's you define in an xml file what parts of your code you want to monitor (much like spring. it should work directly in spring though I haven't tried it). One advantage of automon is that you can swap the jamon implementation for any other monitoring api that you would want to use.

    Having said that using Jamon and spring directly is great too. An advantage of automon is that you aren't limited to monitoring only spring beans.

    Here's an article that tells you what it does and how it works: http://jaxenter.com/advanced-java-monitoring-with-automon-116079.html

     
    • Mike Guo

      Mike Guo - 2015-04-17

      Hi Steve, sorry about the late response. Is the new tool to replace the pointcuts and aspect in JAMon Spring support? Sounds like the new tool can work for POJO projects and Spring appliction :) that's pretty cool.

       
  • Steve Souza

    Steve Souza - 2015-04-17

    "Sounds like the new tool can work for POJO projects and Spring appliction :) that's pretty cool."
    Correct. And you can use tools like yammer metrics, etsy or anything else you choose.

     
  • Steve Souza

    Steve Souza - 2015-04-17

    "Hi Steve

    Thanks for the information, so with above description, is jamon.war required if just use org.springframework.aop.interceptor.JamonPerformanceMonitorInterceptor? I see the api provided by Spring is very handy, but not sure how to establish the result (on ui or in the log, ui gonna be preferred :) )."
    Jamon war is only needed if you want to display the data (in your case spring data) collected in the provided web app. You can also display data with jamon jmx capabilities

     
  • Umesh Singh

    Umesh Singh - 2015-04-30

    Hi Steve,
    I am trying to integrate the jamon api with spring aop method monitoring. However everything is running fine, method is also intercepting and the monitor data is generating successfully(I've seen it in debug log of my application). But the problem is "Jamon admin GUI is not showing the collected data".
    The Environment which i have used is as Java 8, tomcat 8 and spring 3.6 with jamon api 2.8.
    Attaching my capture of the data has been collected.

    Below is the structure of my spring config file :

    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!-- Root Context: defines shared resources visible to all other web components -->
    

    <context:annotation-config/>
    <aop:aspectj-autoproxy/>
    <context:component-scan base-package="com.jamonapi">
    <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
    </context:component-scan>

    <bean id="monitorMe" class="com.one97.jamonTrial.beans.Record"/>

    <bean id="jamonAopKeyHelper" class="com.jamonapi.aop.spring.JamonAopKeyHelper">
      <property name="useArgsWithMethodDetails" value="true" />
      <property name="useArgsWithExceptionDetails" value="true" />
    </bean>
    

    <bean id="jamonAspect" class="com.jamonapi.aop.spring.JamonAspect">
    <property name="exceptionBufferListener" value="true"/>
    <property name="useArgsWithExceptionDetails" value="true"/>
    <property name="useArgsWithMethodDetails" value="true"/>

        <!-- look how to enable/disable exception fifo buffer listener on all values -->
        <constructor-arg ref="jamonAopKeyHelper" />
    

    </bean>

         <aop:config>
        <aop:pointcut id="jamonMonitoringPointcut4"
                      expression="execution(* com.one97.jamonTrial.beans.Record.get*(..))"/>
        <aop:aspect id="jamonSpringAspect" ref="jamonAspect">
            <aop:around
                    pointcut-ref="jamonMonitoringPointcut4"
                    method="monitor"/>
        </aop:aspect>
    </aop:config>
    

    </beans>

     
  • Umesh Singh

    Umesh Singh - 2015-05-01

    Hi Steve,
    I have solved the issue. The issue was happening because of loading of the library jamon-2.81.jar two times in jvm.

    I have removed it from my Spring-application. And now it's working like Charm :).

    Great Piece of software in a simplest possible way.

     

    Last edit: Umesh Singh 2015-05-01
  • Steve Souza

    Steve Souza - 2015-05-01

    Umesh,thanks for getting back to me on this. It helps other users of jamon too.

    And for anyone reading this post 99% of the problems reported about jamon are when the developer has 2 copies of the jamon jar in the classpath. The symptom of this is that both your application and jamon war do not not throw jamon class not found exceptions, but there is no data to view.

    This happens because your app 'writes' to a version of the jamon classes in one jamon jar, and jamon war 'reads' jamon values from another version of the jar.

    Also, next time open a new ticket instead of reusing this old one.

    And, finally check out my latest open source offering automon.org that lets you monitor ANY pojo and not just spring classes. In addition you can swap out jamon for any other monitoring api you might want to use.

    Cheers,
    Steve

     
  • Ernad Besirevic

    Ernad Besirevic - 2016-04-18

    Hey guys,

    first of all: thanks for the great tool.

    Currently I am trying to integrate the Jamon into one of our products and I get the same exception as the Mike Guo described at the beginning of this thread:

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.aspectj.AspectJAroundAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/ProceedingJoinPoint
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:282) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
    

    Here the steps I made to add Jamon to my project:

    1. Maven dependency added to the project
    <dependency>
                    <groupId>com.jamonapi</groupId>
                    <artifactId>jamon</artifactId>
                    <version>2.81</version>
                    <scope>provided</scope>
    </dependency>
    
    1. spring AOP declaration added to the web.beans.xml (version 3.0)
    2. <aop:aspectj-autoproxy/>, jamonAspect bean and also <aop:config> with custom pointcuts added to the web.beans.xml
    3. jamon-2.81.jar added to the Tomacat/lib folder
    4. I skipped the Valve change in Tomcat's server.xml
    5. jamon.war added to the Tomcat/webapps

    When I start the Tomcat I get the exception as described above. If i remove the scope definition from the pom.xml I don't get any exception but I don't get any results in Jamon-UI neither... Is there any way to deploy the jamon.war to another Tomcat instance?

    Thanks and best regards,
    erno

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.