-
-
Notifications
You must be signed in to change notification settings - Fork 743
LiferayPlugin
To monitor a Liferay server v6.1 or later, you can install a Liferay javamelody plugin:
- Download the latest Liferay plugin file from releases
- Copy the file into the "deploy" directory of your Liferay server and wait a few seconds
- Liferay automatically deploys the file and removes it from "deploy" That's it!
You can browse the monitoring page at http://<host>:<port>/monitoring
. For example, if the server is local: http://localhost:8080/monitoring
Authentication and portal "Administrator" role are required to access this monitoring page.
The Liferay plugin is also published in the Liferay marketplace.
Then, if you want to monitor the SQL requests executed by Liferay and the jdbc connections used:
- Configure Liferay to use a JNDI datasource. For example, add a
portal-ext.properties file
in the directory$TOMCAT_HOME/webapps/ROOT/WEB-INF/classes
with the following line :
jdbc.default.jndi.name=jdbc/LiferayPool
- From Liferay 7.0, thanks to Adrián Rodríguez, also modify the default
module.framework.system.packages.extra
inportal-ext.properties
to add the packageorg.apache.naming.factory
at the end.
Example with the portal properties of Liferay Portal 7.2 from https://docs.liferay.com/ce/portal/7.2-latest/propertiesdoc/portal.properties.html#Module%20Framework
module.framework.system.packages.extra=\
com.ibm.crypto.provider,\
com.ibm.db2.jcc,\
com.microsoft.sqlserver.jdbc,\
com.mysql.cj.jdbc,\
com.mysql.jdbc,\
com.p6spy.engine.spy,\
com.sun.security.auth.module,\
com.sybase.jdbc4.jdbc,\
oracle.jdbc,\
org.postgresql,\
org.hsqldb.jdbc,\
org.mariadb.jdbc,\
sun.misc,\
sun.net.util,\
sun.security.provider,\
\
#
# WebSocket Support
#
\
com.ibm.websphere.wsoc,\
io.undertow.websockets.jsr,\
javax.websocket,\
javax.websocket.server,\
org.apache.tomcat.websocket.server,\
weblogic.websocket.tyrus,\
org.apache.naming.factory
- Add a resource link with a name starting with "jdbc/" in the
$TOMCAT_HOME/conf/context.xml
file:
<Context>
...
<ResourceLink name="jdbc/LiferayPool" global="jdbc/LiferayPool" type="javax.sql.DataSource"/>
...
</Context>
- Add a datasource inside
GlobalNamingResources
of the$TOMCAT_HOME/conf/server.xml
file:
...
<!-- If you're using Liferay 6.2 and Tomcat 7 or below ; change maxTotal to maxActive -->
<GlobalNamingResources>
<!-- Example using the HSQL database -->
<Resource name="jdbc/LiferayPool" auth="Container" type="javax.sql.DataSource"
url="jdbc:hsqldb:/opt/liferay/data/hsql/lportal" driverClassName="org.hsqldb.jdbc.JDBCDriver"
username="SA"
maxTotal="20" maxIdle="10" maxWait="10000"
/>
<!-- Example using the MySQL database -->
<Resource name="jdbc/LiferayPool" auth="Container" type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8"
driverClassName="com.mysql.jdbc.Driver"
username="root" password=""
maxTotal="20" maxIdle="10" maxWait="10000"
/>
</GlobalNamingResources>
...
You can look at more parameters for DBCP v2 to configure the datasource when using Tomcat 8 or parameters for DBCP v1 when using Tomcat 7.
And if you have developed a portlet using a database, you can do the same to monitor your SQL requests:
- Add a resource link with a name starting with "jdbc/" in the
$TOMCAT_HOME/conf/context.xml
file. - Add a datasource inside the
GlobalNamingResources
of the$TOMCAT_HOME/conf/server.xml
file. - Use the JNDI datasource in your portlet. For example, in your hibernate.cfg.xml file if you use Hibernate with MySQL :
<property name="hibernate.connection.datasource">java:comp/env/jdbc/MyDataSource</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
The data files will be stored by default in $TOMCAT_HOME/temp/javamelody/
. If you want to use another storage directory, add a "javamelody.storage-directory" system property (in $TOMCAT_HOME/bin/setenv.sh
or in $TOMCAT_HOME/conf/catalina.properties
). For example:
... -Djavamelody.storage-directory=/my/path
You can configure other parameters, see Optional parameters.
In Liferay, you can also send weekly, daily or monthly reports in pdf format by mail to one or several people. This is explained in the chapter Weekly, daily or monthly reports by mail.
For Liferay, add the following Resource and Parameter lines in the $TOMCAT_HOME/conf/context.xml
file:
...
<Context ... >
...
<Resource name="mail/JavaMelodySession" auth="Container" type="javax.mail.Session"
mail.smtp.host="mailhost.foo.bar"
mail.smtp.user="someLoginIfNeeded"
mail.from="javamelody@foo.bar"
/>
<Parameter name='javamelody.admin-emails' value='admin1@company.com,admin2@company.com' override='false'/>
<Parameter name='javamelody.mail-session' value='java:comp/env/mail/JavaMelodySession' override='false'/>
<Parameter name='javamelody.mail-periods' value='day,week,month' override='false'/>
</Context>
...
Read Weekly, daily or monthly reports by mail for more parameters if needed.