How to monitor DataSource connection pool statistics in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7
- 6
Issue
- How can datasource connection pool statistics be obtained?
- How can datasource connection usage be monitored?
- Unable to obtain pool usage statistics
- How can JDBC runtime metrics be obtained using jboss-cli.sh?
- How can datasource pool statistics be obtained using JConsole?
- Why was the default for database statistics changed to Disabled?
- Please provide the command to permanently enable capturing jbdc stats
Resolution
To view/monitor pool statistics, the following options exist:
- The Command Line Interface (CLI)
- The EAP Web Management Console
- JConsole
Note: In EAP 6.3 and later, DataSource statistics need to be explicitly enabled as they are disabled by default to minimize performance impact. See the EAP 6.3+ info to enable DataSource statistics.
Please refer to this Explanation of the JCA JDBC pool statistics for JBoss EAP. See also How to run JBoss CLI in non-interactive mode for details that may be useful for adding CLI commands to a script that can be run to periodically collect data.
CLI command for Standalone mode:
- Change
"data-source=ExampleDS"according to the environment.
[standalone@localhost:9999 /] /subsystem=datasources/data-source=ExampleDS/statistics=pool:read-resource(include-runtime=true)
Result (note that actual counter/statistic set may vary with EAP version):
{
"outcome" => "success",
"result" => {
"ActiveCount" => "0",
"AvailableCount" => "20",
"AverageBlockingTime" => "0",
"AverageCreationTime" => "0",
"CreatedCount" => "0",
"DestroyedCount" => "0",
"InUseCount" => "0",
"MaxCreationTime" => "0",
"MaxUsedCount" => "0",
"MaxWaitCount" => "0",
"MaxWaitTime" => "0",
"TimedOut" => "0",
"TotalBlockingTime" => "0",
"TotalCreationTime" => "0",
"statistics-enabled" =>true
}
}
CLI command for Domain mode:
- Change
"/host=master/server=server-one"and"data-source=ExampleDS"according to the environment.
[domain@localhost:9999 /] /host=master/server=server-one/subsystem=datasources/data-source=ExampleDS/statistics=pool:read-resource(include-runtime=true)
Result (note that actual counter/statistic set may vary with EAP version):
{
"outcome" => "success",
"result" => {
"ActiveCount" => "0",
"AvailableCount" => "20",
"AverageBlockingTime" => "0",
"AverageCreationTime" => "0",
"CreatedCount" => "0",
"DestroyedCount" => "0",
"InUseCount" => "0",
"MaxCreationTime" => "0",
"MaxUsedCount" => "0",
"MaxWaitCount" => "0",
"MaxWaitTime" => "0",
"TimedOut" => "0",
"TotalBlockingTime" => "0",
"TotalCreationTime" => "0",
"statistics-enabled" =>true
}
}
Scripting Statistic Collection
CLI comands might be run in a script using a command like the following (for a standalone configuration). Output could be redirected to a file (in an OS specific manner) to preserve history. Writing a date to the file for each collection to identify the timeframe of the data collection is recommended.
> bin/jboss-cli.sh --connect '/subsystem=datasources/data-source=ExampleDS/statistics=pool:read-resource(include-runtime=true)'
Web Management Console
Statistics may be viewed via the Runtime tab of the management console.
- In the Runtime section of the console, navigate to the DataSources subsystem, select a pool and navigate to the "Pool Statistics" tab.
- Depending on EAP version a subset of the available statics may be exposed through the web console.
JConsole
Browse JConsole down the following path to view statistics (note that actual counter/statistic set may vary with EAP version), for example for ExampleDS: jboss.as:subsystem=datasources,data-source=ExampleDS,statistics=pool, and select Attributes
+ jboss-as
+ datasources
+ ExampleDS
+ pool
+ Attributes
ActiveCount
AvailableCount
AverageBlockingTime
AverageCreationTime
CreatedCount
DestroyedCount
InUseCount
MaxCreationTime
MaxUsedCount
MaxWaitCount
MaxWaitTime
TimedOut
TotalBlockingTime
TotalCreationTime
Enabling Statistics for EAP 6.3+
As highlighted above, users will need to enable the monitoring for statistics first which is set to false ("statistics-enabled" => false) by default. After enabling DataSource statistics by any of the methods below, restart the JVM(s) for the changes to take effect.
CLI command for Standalone mode
[standalone@localhost:9999 /] /subsystem=datasources/data-source=ExampleDS:write-attribute(name=statistics-enabled,value=true)
Result:
{
"outcome" => "success",
"response-headers" => {
"operation-requires-reload" => true,
"process-state" => "reload-required"
}
}
CLI command for Domain mode
To enable the statistics , change via the profile (ie. used by the server whose pool statistics need to be monitored)
[domain@localhost:9999 /] /profile=full/subsystem=datasources/data-source=ExampleDS:write-attribute(name=statistics-enabled,value=true)
Result:
{
"outcome" => "success",
"result" => undefined,
"server-groups" => {"main-server-group" => {"host" => {"master" => {
"server-one" => {"response" => {
"outcome" => "success",
"response-headers" => {
"operation-requires-restart" => true,
"process-state" => "restart-required"
}
}},
"server-two" => {"response" => {
"outcome" => "success",
"response-headers" => {
"operation-requires-restart" => true,
"process-state" => "restart-required"
}
}}
}}}}
Editing the XML
Alternatively DataSource pool statistics could be enabled by setting statistics-enabled attribute to true in the standalone*.xml or domain.xml respectively. Care must be taken not to corrupt the XML when editing. Use of CLI is recommended as it reduces the likelihood of corruption of the configuration.
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="true">
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.