Showing posts with label JBoss. Show all posts
Showing posts with label JBoss. Show all posts

Wednesday, December 23, 2009

Monitoring in JBoss

While at a client site or within a testing environment, have you ever started to wonder how many users are on the application? How is your application running with regards to memory (heap size)? Are you close to using all of the database connections in the connection pool? For answers to some questions, maybe your application container provides a status (tomcat) or monitoring screen (WebLogic).

To facilitate recording of these statistics when using JBoss, JBoss has included the ability to log/monitor JMX Mbean values. And it's not difficult to install. Once values are being logged, you no longer have to continue refreshing the JMX console to see the values updated.

For installing and monitoring of your web application(s), perform the following steps:
  1. Copy monitor XML files into $JBOSS/server/server_name/deploy
  2. Copy $JBOSS/docs/examples/jmx/logging-monitor/lib/logging-monitor.jar into $JBOSS/server/server_name/lib
  3. Create monitor XML files to monitor JMX MBeans (samples below)
And there you have statistics being saved in a log file...ready for you to parse and create pretty little graphs for the rest of the world to read and understand. For our deployments, we used these logs to track & monitor the following items. As a side affect of monitoring, you also get to see the peak usage times and potentially performance / memory related issues.
  • DB connections
    • In use
    • Available
    • Max Connections In Use
  • JVM activity
    • Heap size
    • Threads
For additional reading or research on monitoring within JBoss, check out the following links:
DB Connection Monitoring Sample
Here's the XML necessary to monitor a JDBC connection pool (XML comments omitted)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC
"-//JBoss//DTD MBean Service 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">

<server>
<mbean code="org.jboss.services.loggingmonitor.LoggingMonitor"
name="jboss.monitor:type=LoggingMonitor,name=MY-DSMonitor">

<attribute name="Filename">${jboss.server.home.dir}/log/my-ds.log</attribute>

<attribute name="AppendToFile">false</attribute>

<attribute name="RolloverPeriod">DAY</attribute>

<attribute name="MonitorPeriod">10000</attribute>

<attribute name="MonitoredObjects">
<configuration>
<monitoredmbean name="jboss.jca:name=MY-DS,service=ManagedConnectionPool"
logger="jca.my-ds">
<attribute>InUseConnectionCount</attribute>
<attribute>AvailableConnectionCount</attribute>
<attribute>ConnectionCreatedCount</attribute>
<attribute>ConnectionDestroyedCount</attribute>
<attribute>MaxConnectionsInUseCount</attribute>
</monitoredmbean>
</configuration>
</attribute>

<depends>jboss.jca:name=MY-DS,service=ManagedConnectionPool</depends>
</mbean>

</server>

Friday, December 7, 2007

JBoss: Configuring Data Sources

Configuring data sources in JBoss is quite simple but documentation may be a little difficult to find. Hopefully, this will demonstrate HOW simple it really is.

First, let's say that you have a web application (or some other application) that is expecting a data source to be present in JNDI. Maybe you have designed the application that needs to support multiple databases (kudos to you). Or maybe the application will be deployed into multiple environments and you do not want to force clients to configure the data source your way with your connection information. Whatever the reason, the data source configured within the container and handed to your application.

Next comes the real easy steps. To configure the data source in jboss, you need to perform 2 steps.

  1. Drop the JDBC driver jar file into the JBoss classpath. If you're running the 'default' server under JBoss, drop the jar file in $JBOSS_HOME/server/default/lib. JBoss will pick it when the server starts. Here are 2 links to JDBC driver jars:

    • PostgreSql
    • SQL Server
    • Oracle drivers are located under the Oracle installation directory. For 10g, look under C:\oracle\product\10.2.0\db_1\jdbc\lib.

  2. Create the data source XML file in the deploy directory. Once again, if you're running the 'default' server, create the XML file in $JBOSS_HOME/server/default/deploy. Upon startup, JBoss will load this DS file and configure the data source according to the XML file. Sample XML files for the different DBs are located in the $JBOSS_HOME/docs/examples/jca directory.

    • Sample Oracle DS

      <datasources>
      <local-tx-datasource>
      <jndi-name>COP-DS</jndi-name>
      <connection-url>jdbc:oracle:thin:@localhost:1521:ORCL</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>user</user-name>
      <password>password</password>
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      <min-pool-size>2</min-pool-size>
      <max-pool-size>5</max-pool-size>
      <metadata>
      <type-mapping>Oracle9i</type-mapping>
      </metadata>
      </local-tx-datasource>
      </datasources>


    • Sample SQL Server DS

      <datasources>
      <local-tx-datasource>
      <jndi-name>COP-DS</jndi-name>
      <connection-url>jdbc:jtds:sqlserver://localhost:1433/cop</connection-url>
      <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
      <user-name>affor</user-name>
      <password>password</password>
      <check-valid-connection-sql>select 1</check-valid-connection-sql>
      <min-pool-size>2</min-pool-size>
      <max-pool-size>10</max-pool-size>

      <metadata>
      <type-mapping>MS SQLSERVER2000</type-mapping>
      </metadata>
      </local-tx-datasource>
      </datasources>



BEWARE: The data source file must be name with '-ds.xml'. That's a dash and NOT an underscore. That little character cost me a few hours of troubleshooting only to be identified by another person.

For more detailed information or for other DB configurations, visit the JBoss wiki on data sources.