Hi,
Many thanks for the
clarification – it works ok now.
Best regards,
Alvaro
De:
rhq-users-bounces@lists.fedorahosted.org en nombre de John Mazzitelli
Enviado el: mié 13/01/2010 23:27
Para: rhq-users@lists.fedorahosted.org
Asunto: Re: question about RHQ
2.3.1 not discovering Hibernate MBean deployedon a Jboss instance
From
the hibernate plugin descriptor, you can see the default name of
the MBean should follow this pattern
"Hibernate:application=%application%,type=statistics" where
%application% is some name you provide when you registered the MBean.
Specifically, see this in the plugin-config:
<c:simple-property name="objectName" readOnly="true"
default="Hibernate:application=%application%,type=statistics"/>
found in the descriptor of the hibernate plugin at
modules/plugins/hibernate (fedorahosted.org is currently down, can't
post a link).
Here's the help text found in the descriptor file that explains how you
can deploy the hibernate bean using Java code:
<p>In order
to monitor Hibernate statistics via JON, the
Hibernate Session Manager MBean
must be deployed
to an object name of the format
<tt>_"Hibernate:application=%application%,type=statistics"_</tt>,
and
statistics must be enabled.</p>
<p>Some
example code is provided below to register the
Hibernate Session MBean within an EJB3 application.</p>
<code><pre>
public static void enableHibernateStatistics(EntityManager
entityManager)
{
try
{
StatisticsService mBean = new
StatisticsService();
SessionFactory sessionFactory =
getHibernateSession(entityManager).getSessionFactory();
mBean.setSessionFactory(sessionFactory);
ObjectName objectName = new
ObjectName(HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
MBeanServer jbossMBeanServer =
getJBossMBeanServer();
jbossMBeanServer.registerMBean(mBean, objectName);
sessionFactory.getStatistics().setStatisticsEnabled(true);
}
catch (InstanceAlreadyExistsException iaee)
{
LOG.info("Duplicate MBean
registration ignored: " +
HIBERNATE_STATISTICS_MBEAN_OBJECTNAME);
}
catch (Exception e)
{
LOG.warn("Couldn't register
Hibernate statistics MBean.", e);
}
}
private static Session getHibernateSession(EntityManager entityManager)
{
Session session;
if (entityManager.getDelegate() instanceof
EntityManagerImpl) {
EntityManagerImpl
entityManagerImpl = (EntityManagerImpl)
entityManager.getDelegate();
session =
entityManagerImpl.getSession();
} else {
session = (Session)
entityManager.getDelegate();
}
return session;
}
private static MBeanServer getJBossMBeanServer() {
List<MBeanServer> servers =
MBeanServerFactory.findMBeanServer(null);
MBeanServer jbossServer = null;
for (MBeanServer server : servers) {
if
("jboss".equals(server.getDefaultDomain())) {
jbossServer = server;
}
}
if (jbossServer == null) {
jbossServer =
ManagementFactory.getPlatformMBeanServer();
}
return jbossServer;
}
</pre></code>
<p>See also
<a
href="http://hibernate.org/216.html">Publishing
statistics through
JMX</a> and
<a
href="http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.3/doc/hibernate/Hibernate_Reference_Guide/Optional_configuration_properties-Hibernate_statistics.html">Enabling
Hibernate statistics</a></p>
On 01/13/2010 05:17 PM, Alvaro
> I'm having problems trying to get RHQ discover a Hibernate Statistics
> mbean deployed inside an application over a Jboss 4.2.3 server. Also, it
> happens the same when the app is inside a Tomcat container.
>
> All jmx access/level flags (unauthenticated access, no ssl, port
> established) are in place in the JVM invocation , etc.
>
> ## run.conf for the Jboss instance
> JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote"
> JAVA_OPTS="$JAVA_OPTS
-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl"
> JAVA_OPTS="$JAVA_OPTS -Djboss.platform.mbeanserver"
> JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=9003"
> JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
> JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
>
> Tried some methods from
> http://www.rhq-project.org/display/RHQ/Plugins+-+Demos+-+Monitoring+Hibe
> rnate to no avail (manually adding a service of type JMX Server)
>
> I'm and dev team are kinda puzzled by this. The app uses Spring and
> Hibernate 3.1. A printscreen from Jconsole (below), or querying
> explicitly the mbean via RMI ..works ok.Tried also using excellent
> jmx_console app from Phillip Traeder, and works ok too:
>
> root@fuchinos:/opt/jmxtools# ./jmx_console.sh get_attribute
--host=j2ee
> --port=9003 --object_name=org.hibernate:type=statistics
> --attribute_name=Queries
>
> org.hibernate:type=statistics/Queries : select p from
> ParametroConfiguracion p
>
> root@fuchinos:/opt/jmxtools#
>
> I'm not a java developer, but I'm guessing there would be some sort of
> deviation in the manner the dev team initialized the Hibernate JMX
> mbean, perhaps the naming is not being recognized by the Hibernate RHQ
> plugin because of that?
>
> Any help is much appreciated. Sorry the length and the print screens
> below, they are meant to illustrate a work ok/no ok view (the Hibernate
> plugin folder missing from "j2ee" Jboss instance).
>
> N.b.: print screens erased, since they exceed the maximum for the list.
>
> Regards,
>
> Alvaro
_______________________________________________
rhq-users mailing list
rhq-users@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/rhq-users