New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL monitoring in Apache OpenEJB in TomEE #104

Closed
GoogleCodeExporter opened this Issue Jun 21, 2015 · 19 comments

Comments

Projects
None yet
1 participant
@GoogleCodeExporter

GoogleCodeExporter commented Jun 21, 2015

Hi,

i tried javamelody to monitor openejb (ejb counter in particular) but i didn't 
succeed to have call stats, is there a known issue?

My runtime environment was openejb 3.1.4 embeded into tomcat 6.0.29.


Original issue reported on code.google.com by rmannibucau@gmail.com on 12 Apr 2011 at 8:22

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

There is no known issue or information about openejb into tomcat.
You can try to debug with breakpoints in the constructor and in the intercept 
method of net.bull.javamelody.MonitoringInterceptor.

Original comment by evernat@free.fr on 12 Apr 2011 at 9:18

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

The interceptor finally works :).

However i don't know how to monitor the datasources. I tried to add to tomcat 
-Djavamelody.datasources=java:openejb/Resource/jdbc/Mydatasource but it doesn't 
do anything :(. I wanted to put the jdbcdriver but it is not possible in 
openejb.

Did i miss something?

Original comment by rmannibucau@gmail.com on 13 Apr 2011 at 9:31

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

First, I advise a quick check to know if you are in the same case that issue 
105.
And I suppose that you don't use Spring for the datasource, or do you?

Then, openejb is perhaps looking up the JNDI datasource and caching it before 
that javamelody is initialized with the listener and the filter of javamelody. 
In which case, you can perhaps initialize the javamelody listener sooner in 
your web.xml file.
Or you can try to set the undocumented javamelody parameter rewrap-datasources 
(try with or without your javamelody.datasources parameter) to workaround the 
supposed datasource caching. For example, add the following lines in the 
javamelody filter in your web.xml file:
        <init-param>
            <param-name>rewrap-datasources</param-name>
            <param-value>true</param-value>
        </init-param>
or use a system property -Djavamelody.rewrap-datasources=true

And otherwise, you can finally enable the debugging logs and post the 
initialization logs here to know better what is initialized in javamelody.
http://code.google.com/p/javamelody/wiki/UserGuideAdvanced#Debugging_logs

Original comment by evernat@free.fr on 25 Apr 2011 at 11:35

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

i don't use spring, i'm bound on localhost.

I'm pretty sure OpenEJB create the datasource before javamelody looks it up 
because openejb starts before all other webapps.

I set the rewrap-datasources parameter but it did nothing.

I didn't succeed to have logs (even adding log4j to the app).

I'm using this tomcat/OpenEJB installation 
https://repository.apache.org/content/groups/snapshots/org/apache/openejb/openej
b-tomee-tomcat6/4.0.0-SNAPSHOT/openejb-tomee-tomcat6-4.0.0-20110328.203626-1.zip
 . It includes ejb-example sample application. It is this application i'm 
trying to monitor.

Original comment by rmannibucau@gmail.com on 26 Apr 2011 at 11:40

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

I will try this sample application, in a few days probably. Thanks for the link.

Original comment by evernat@free.fr on 27 Apr 2011 at 6:38

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

thank you

Original comment by rmannibucau@gmail.com on 27 Apr 2011 at 6:52

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

I have tried the ejb-examples application.
And first, what file have you added/changed to make the ejb interceptor work in 
openejb? (directory, name and content of the file?)
Then I have made the log work without problem: I have added the log4j.xml 
attached in this issue in webapps/ejb-examples/WEB-INF/classes/ and I have 
added the log4j jar file in webapps/ejb-examples/WEB-INF/lib/ (beside 
javamelody.jar, jrobin-1.5.9.1.jar, itext-2.1.7.jar)

The following is not enough to monitor sql requests because the JNDI context of 
Tomee is a quite strange and particular beast in itself.
But I can now see in the logs that some DataSources are rebinded (or rewrapped, 
if rewrap-datasources=true), when I change the 
webapps/ejb-examples/WEB-INF/web.xml file by adding the following before the 
first servlet:
    <filter>
                <filter-name>monitoring</filter-name>
                <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
        <init-param>
                        <param-name>system-actions-enabled</param-name>
                        <param-value>true</param-value>
                </init-param>
        <init-param>
                        <param-name>datasources</param-name>
                        <param-value>java:openejb/Resource/My DataSource,java:openejb/Resource/My Unmanaged DataSource,java:comp/env/web.xml/Data Source,java:openejb/Resource/Default JDBC Database,java:openejb/Resource/Default Unmanaged JDBC Database</param-value>
                </init-param>
        <init-param>
                        <param-name>rewrap-datasources</param-name>
                        <param-value>false</param-value>
                </init-param>
        </filter>
        <filter-mapping>
                <filter-name>monitoring</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
        <listener>
                <listener-class>net.bull.javamelody.SessionListener</listener-class>
        </listener>

I can also see the database reports by clicking the link "database" near the 
end of the monitoring page.

Note that to correctly rewrap the openejb datasources I have changed javamelody 
a little bit in the attached javamelody.jar file (no need of this jar file if 
it is just to rebind) and of course I set rewrap-datasources to true in the 
web.xml file.

Finally, sql requests are not monitored even in rewrap mode (except if there is 
a hot deployment when I save the web.xml file...?)

Original comment by evernat@free.fr on 27 Apr 2011 at 10:47

Attachments:

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Thanks for your feedback.

I probably copy a corrupted log4j lib when i tried (my local maven repo was a 
bit dirty for a while).

To use the interceptor i simply added an ejb-jar.xml in 
WEB-INF/classes/META-INF. But i wasn't able to see datas on the monitoring/ 
page. I had to add some parameters (i didn't remember but it was something like 
counter = ejb and summaryByCounter or something like that).

Do you know what is the problem exactly?

- Romain

Original comment by rmannibucau@gmail.com on 28 Apr 2011 at 6:01

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Original comment by evernat@free.fr on 1 May 2011 at 9:57

  • Changed title: SQL monitoring in Apache OpenEJB in TomEE
@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

I have made a change to fix the SQL monitoring in TomEE (OpenEJB prebundled 
with Tomcat).
It is committed in trunk (revision 1850) and it is ready for the next release 
(1.29).

I have made a new build with the fix and it is available at:
http://javamelody.googlecode.com/files/javamelody-20110501.jar

Original comment by evernat@free.fr on 1 May 2011 at 10:04

  • Changed state: Fixed
@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Note that rewrap-datasources is not needed with the new build including the fix.
The following web.xml configuration is enough to have sql monitoring:
    <filter>
                <filter-name>monitoring</filter-name>
                <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
        <init-param>
                        <param-name>system-actions-enabled</param-name>
                        <param-value>true</param-value>
                </init-param>
        <init-param>
                        <param-name>datasources</param-name>
                        <param-value>java:openejb/Resource/My DataSource,java:openejb/Resource/My Unmanaged DataSource,java:comp/env/web.xml/Data Source,java:openejb/Resource/Default JDBC Database,java:openejb/Resource/Default Unmanaged JDBC Database</param-value>
                </init-param>
        </filter>
        <filter-mapping>
                <filter-name>monitoring</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
        <listener>
                <listener-class>net.bull.javamelody.SessionListener</listener-class>
        </listener>

I do not know exactly which of the jndi names of datasources written above is 
the one necessary to have the sql monitoring (you could test one by one)

Original comment by evernat@free.fr on 1 May 2011 at 10:12

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Great!!!

with this version everything is working perfectly, thank you very much.


Original comment by rmannibucau@gmail.com on 1 May 2011 at 2:53

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

I have tried this with a datasource defined in tomee.xml as  <Resource 
id="myDatasource"

        <init-param>
                        <param-name>datasources</param-name>
                        <param-value>java:openejb/Resource/My DataSource,java:openejb/Resource/myDatasource</param-value>
                </init-param>

Does this work with datasources defined in tomee.xml or do I need to rewrap 
datasource or define it with javamelody driver class?

(tomEE 1.7.0)
Thanks.

Original comment by cocoross...@gmail.com on 21 Sep 2014 at 9:57

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Since TomEE 1.5, OpenEJB JDBC internals have evolved and JavaMelody (1.54.0) 
JDBC monitoring no more works out-of-the-box ;-(.
In fact, JavaMelody JdbcWrapper is not up to date and TomEE DataSource 
rewrapping is no more effective (TomEE DataSource class name is now 
"org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource" and the 
inner field holding the DataSource to proxy is named "delegate").

While waiting for a fix, JavaMelody driver class 
(net.bull.javamelody.JdbcDriver) can be defined as class of driver in the 
DataSource configuration.

Frederic

Original comment by frederic...@gmail.com on 4 Dec 2014 at 9:45

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Attached a simple fix.

Original comment by frederic...@gmail.com on 4 Dec 2014 at 10:28

Attachments:

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Note that TomEE can also now add few proxy levels on top of these datasource 
depending the config so maybe try to unwrap InvocationHandler as well.

We commonly use:

{code}
    private static Object realInstance(final Object o) {
        if (o == null || !(o instanceof DataSource)) {
            return o;
        }

        Object ds = o;
        while (Proxy.isProxyClass(ds.getClass())) {
            final InvocationHandler handler = Proxy.getInvocationHandler(o);
            if (LoggingSqlDataSource.class.isInstance(handler)) {
                ds = LoggingSqlDataSource.class.cast(handler).getDelegate();
            } else if (FlushableDataSourceHandler.class.isInstance(handler)) {
                ds = FlushableDataSourceHandler.class.cast(handler).getDelegate();
            } else {
                break;
            }
        }

        return ds;
    }
{code}

"luck" is all datasources are in "delegate" fields in InvocationHandlers. I 
think for javamelody LoggingSqlDataSource level could be ignore as well.

Original comment by rmannibucau@gmail.com on 5 Dec 2014 at 7:46

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Merci Frédéric.
This is fixed in trunk (revision 3989) and ready for the next release (1.55, 
because 1.54 was already done).

I have included your patch as is, without unwrapping proxies because depending 
on TomEE proxies at compile time or with reflection at runtime would be complex 
and hard coded.
By "luck", it would still work with those proxies, since all datasources are in 
"delegate" fields in InvocationHandlers.

Original comment by evernat@free.fr on 9 Dec 2014 at 2:31

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Super, merci ;-)

Original comment by frederic...@gmail.com on 10 Dec 2014 at 7:39

@GoogleCodeExporter

This comment has been minimized.

GoogleCodeExporter commented Jun 21, 2015

Thank you!

Original comment by rossello...@gmail.com on 28 Jan 2015 at 9:29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment