org.hibernate.jmx
Class StatisticsService

java.lang.Object
  extended by org.hibernate.jmx.StatisticsService
All Implemented Interfaces:
StatisticsServiceMBean, Statistics

public class StatisticsService
extends Object
implements StatisticsServiceMBean

JMX service for Hibernate statistics

Register this MBean in your JMX server for a specific session factory

 //build the ObjectName you want
 Hashtable tb = new Hashtable();
 tb.put("type", "statistics");
 tb.put("sessionFactory", "myFinancialApp");
 ObjectName on = new ObjectName("hibernate", tb);
 StatisticsService stats = new StatisticsService();
 stats.setSessionFactory(sessionFactory);
 server.registerMBean(stats, on);
 
And call the MBean the way you want

Register this MBean in your JMX server with no specific session factory
 //build the ObjectName you want
 Hashtable tb = new Hashtable();
 tb.put("type", "statistics");
 tb.put("sessionFactory", "myFinancialApp");
 ObjectName on = new ObjectName("hibernate", tb);
 StatisticsService stats = new StatisticsService();
 server.registerMBean(stats, on);
 
And call the MBean by providing the SessionFactoryJNDIName first. Then the session factory will be retrieved from JNDI and the statistics loaded.

Author:
Emmanuel Bernard

Constructor Summary
StatisticsService()
           
 
Method Summary
 void clear()
          reset all statistics
 long getCloseStatementCount()
          The number of prepared statements that were released
 long getCollectionFetchCount()
          Global number of collections fetched
 long getCollectionLoadCount()
          Global number of collections loaded
 long getCollectionRecreateCount()
          Global number of collections recreated
 long getCollectionRemoveCount()
          Global number of collections removed
 String[] getCollectionRoleNames()
          Get the names of all collection roles
 CollectionStatistics getCollectionStatistics(String role)
          Get collection statistics per role
 long getCollectionUpdateCount()
          Global number of collections updated
 long getConnectCount()
          Get the global number of connections asked by the sessions (the actual number of connections used may be much smaller depending whether you use a connection pool or not)
 long getEntityDeleteCount()
          Get global number of entity deletes
 long getEntityFetchCount()
          Get global number of entity fetchs
 long getEntityInsertCount()
          Get global number of entity inserts
 long getEntityLoadCount()
          Get global number of entity loads
 String[] getEntityNames()
          Get the names of all entities
 EntityStatistics getEntityStatistics(String entityName)
          find entity statistics per name
 long getEntityUpdateCount()
          Get global number of entity updates
 long getFlushCount()
          Get the global number of flush executed by sessions (either implicit or explicit)
 long getOptimisticFailureCount()
          The number of StaleObjectStateExceptions that occurred
 long getPrepareStatementCount()
          The number of prepared statements that were acquired
 String[] getQueries()
          Get all executed query strings
 long getQueryCacheHitCount()
          Get the global number of cached queries successfully retrieved from cache
 long getQueryCacheMissCount()
          Get the global number of cached queries *not* found in cache
 long getQueryCachePutCount()
          Get the global number of cacheable queries put in cache
 long getQueryExecutionCount()
          Get global number of executed queries
 long getQueryExecutionMaxTime()
          Get the time in milliseconds of the slowest query.
 String getQueryExecutionMaxTimeQueryString()
          Get the query string for the slowest query.
 QueryStatistics getQueryStatistics(String hql)
          Query statistics from query string (HQL or SQL)
 long getSecondLevelCacheHitCount()
          Global number of cacheable entities/collections successfully retrieved from the cache
 long getSecondLevelCacheMissCount()
          Global number of cacheable entities/collections not found in the cache and loaded from the database.
 long getSecondLevelCachePutCount()
          Global number of cacheable entities/collections put in the cache
 String[] getSecondLevelCacheRegionNames()
          Get all second-level cache region names
 SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName)
          Second level cache statistics per region
 long getSessionCloseCount()
          Global number of sessions closed
 long getSessionOpenCount()
          Global number of sessions opened
 long getStartTime()
           
 long getSuccessfulTransactionCount()
          The number of transactions we know to have been successful
 long getTransactionCount()
          The number of transactions we know to have completed
 boolean isStatisticsEnabled()
          Are statistics logged
 void logSummary()
          log in info level the main statistics
 void setSessionFactory(SessionFactory sf)
          Useful to init this MBean wo a JNDI session factory name
 void setSessionFactoryJNDIName(String sfJNDIName)
          Publish the statistics of a session factory bound to the default JNDI context
 void setStatisticsEnabled(boolean enable)
          Enable statistics logs (this is a dynamic parameter)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatisticsService

public StatisticsService()
Method Detail

setSessionFactoryJNDIName

public void setSessionFactoryJNDIName(String sfJNDIName)
Description copied from interface: StatisticsServiceMBean
Publish the statistics of a session factory bound to the default JNDI context

Specified by:
setSessionFactoryJNDIName in interface StatisticsServiceMBean
Parameters:
sfJNDIName - session factory jndi name
See Also:
StatisticsServiceMBean.setSessionFactoryJNDIName(java.lang.String)

setSessionFactory

public void setSessionFactory(SessionFactory sf)
Useful to init this MBean wo a JNDI session factory name

Parameters:
sf - session factory to register

clear

public void clear()
Description copied from interface: Statistics
reset all statistics

Specified by:
clear in interface Statistics
See Also:
Statistics.clear()

getEntityStatistics

public EntityStatistics getEntityStatistics(String entityName)
Description copied from interface: Statistics
find entity statistics per name

Specified by:
getEntityStatistics in interface Statistics
Parameters:
entityName - entity name
Returns:
EntityStatistics object
See Also:
Statistics.getEntityStatistics(java.lang.String)

getCollectionStatistics

public CollectionStatistics getCollectionStatistics(String role)
Description copied from interface: Statistics
Get collection statistics per role

Specified by:
getCollectionStatistics in interface Statistics
Parameters:
role - collection role
Returns:
CollectionStatistics
See Also:
Statistics.getCollectionStatistics(java.lang.String)

getSecondLevelCacheStatistics

public SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName)
Description copied from interface: Statistics
Second level cache statistics per region

Specified by:
getSecondLevelCacheStatistics in interface Statistics
Parameters:
regionName - region name
Returns:
SecondLevelCacheStatistics
See Also:
Statistics.getSecondLevelCacheStatistics(java.lang.String)

getQueryStatistics

public QueryStatistics getQueryStatistics(String hql)
Description copied from interface: Statistics
Query statistics from query string (HQL or SQL)

Specified by:
getQueryStatistics in interface Statistics
Parameters:
hql - query string
Returns:
QueryStatistics
See Also:
Statistics.getQueryStatistics(java.lang.String)

getEntityDeleteCount

public long getEntityDeleteCount()
Description copied from interface: Statistics
Get global number of entity deletes

Specified by:
getEntityDeleteCount in interface Statistics
Returns:
entity deletion count
See Also:
Statistics.getEntityDeleteCount()

getEntityInsertCount

public long getEntityInsertCount()
Description copied from interface: Statistics
Get global number of entity inserts

Specified by:
getEntityInsertCount in interface Statistics
Returns:
entity insertion count
See Also:
Statistics.getEntityInsertCount()

getEntityLoadCount

public long getEntityLoadCount()
Description copied from interface: Statistics
Get global number of entity loads

Specified by:
getEntityLoadCount in interface Statistics
Returns:
entity load (from DB)
See Also:
Statistics.getEntityLoadCount()

getEntityFetchCount

public long getEntityFetchCount()
Description copied from interface: Statistics
Get global number of entity fetchs

Specified by:
getEntityFetchCount in interface Statistics
Returns:
entity fetch (from DB)
See Also:
Statistics.getEntityFetchCount()

getEntityUpdateCount

public long getEntityUpdateCount()
Description copied from interface: Statistics
Get global number of entity updates

Specified by:
getEntityUpdateCount in interface Statistics
Returns:
entity update
See Also:
Statistics.getEntityUpdateCount()

getQueryExecutionCount

public long getQueryExecutionCount()
Description copied from interface: Statistics
Get global number of executed queries

Specified by:
getQueryExecutionCount in interface Statistics
Returns:
query execution count
See Also:
Statistics.getQueryExecutionCount()

getQueryCacheHitCount

public long getQueryCacheHitCount()
Description copied from interface: Statistics
Get the global number of cached queries successfully retrieved from cache

Specified by:
getQueryCacheHitCount in interface Statistics

getQueryExecutionMaxTime

public long getQueryExecutionMaxTime()
Description copied from interface: Statistics
Get the time in milliseconds of the slowest query.

Specified by:
getQueryExecutionMaxTime in interface Statistics

getQueryCacheMissCount

public long getQueryCacheMissCount()
Description copied from interface: Statistics
Get the global number of cached queries *not* found in cache

Specified by:
getQueryCacheMissCount in interface Statistics

getQueryCachePutCount

public long getQueryCachePutCount()
Description copied from interface: Statistics
Get the global number of cacheable queries put in cache

Specified by:
getQueryCachePutCount in interface Statistics

getFlushCount

public long getFlushCount()
Description copied from interface: Statistics
Get the global number of flush executed by sessions (either implicit or explicit)

Specified by:
getFlushCount in interface Statistics
See Also:
Statistics.getFlushCount()

getConnectCount

public long getConnectCount()
Description copied from interface: Statistics
Get the global number of connections asked by the sessions (the actual number of connections used may be much smaller depending whether you use a connection pool or not)

Specified by:
getConnectCount in interface Statistics
See Also:
Statistics.getConnectCount()

getSecondLevelCacheHitCount

public long getSecondLevelCacheHitCount()
Description copied from interface: Statistics
Global number of cacheable entities/collections successfully retrieved from the cache

Specified by:
getSecondLevelCacheHitCount in interface Statistics
See Also:
Statistics.getSecondLevelCacheHitCount()

getSecondLevelCacheMissCount

public long getSecondLevelCacheMissCount()
Description copied from interface: Statistics
Global number of cacheable entities/collections not found in the cache and loaded from the database.

Specified by:
getSecondLevelCacheMissCount in interface Statistics
See Also:
Statistics.getSecondLevelCacheMissCount()

getSecondLevelCachePutCount

public long getSecondLevelCachePutCount()
Description copied from interface: Statistics
Global number of cacheable entities/collections put in the cache

Specified by:
getSecondLevelCachePutCount in interface Statistics
See Also:
Statistics.getSecondLevelCachePutCount()

getSessionCloseCount

public long getSessionCloseCount()
Description copied from interface: Statistics
Global number of sessions closed

Specified by:
getSessionCloseCount in interface Statistics
See Also:
Statistics.getSessionCloseCount()

getSessionOpenCount

public long getSessionOpenCount()
Description copied from interface: Statistics
Global number of sessions opened

Specified by:
getSessionOpenCount in interface Statistics
See Also:
Statistics.getSessionOpenCount()

getCollectionLoadCount

public long getCollectionLoadCount()
Description copied from interface: Statistics
Global number of collections loaded

Specified by:
getCollectionLoadCount in interface Statistics
See Also:
Statistics.getCollectionLoadCount()

getCollectionFetchCount

public long getCollectionFetchCount()
Description copied from interface: Statistics
Global number of collections fetched

Specified by:
getCollectionFetchCount in interface Statistics
See Also:
Statistics.getCollectionFetchCount()

getCollectionUpdateCount

public long getCollectionUpdateCount()
Description copied from interface: Statistics
Global number of collections updated

Specified by:
getCollectionUpdateCount in interface Statistics
See Also:
Statistics.getCollectionUpdateCount()

getCollectionRemoveCount

public long getCollectionRemoveCount()
Description copied from interface: Statistics
Global number of collections removed

Specified by:
getCollectionRemoveCount in interface Statistics
See Also:
Statistics.getCollectionRemoveCount()

getCollectionRecreateCount

public long getCollectionRecreateCount()
Description copied from interface: Statistics
Global number of collections recreated

Specified by:
getCollectionRecreateCount in interface Statistics
See Also:
Statistics.getCollectionRecreateCount()

getStartTime

public long getStartTime()
Specified by:
getStartTime in interface Statistics
Returns:
start time in ms (JVM standards System.currentTimeMillis())
See Also:
Statistics.getStartTime()

isStatisticsEnabled

public boolean isStatisticsEnabled()
Description copied from interface: Statistics
Are statistics logged

Specified by:
isStatisticsEnabled in interface Statistics
See Also:
Statistics.isStatisticsEnabled()

setStatisticsEnabled

public void setStatisticsEnabled(boolean enable)
Description copied from interface: Statistics
Enable statistics logs (this is a dynamic parameter)

Specified by:
setStatisticsEnabled in interface Statistics
See Also:
Statistics.setStatisticsEnabled(boolean)

logSummary

public void logSummary()
Description copied from interface: Statistics
log in info level the main statistics

Specified by:
logSummary in interface Statistics

getCollectionRoleNames

public String[] getCollectionRoleNames()
Description copied from interface: Statistics
Get the names of all collection roles

Specified by:
getCollectionRoleNames in interface Statistics

getEntityNames

public String[] getEntityNames()
Description copied from interface: Statistics
Get the names of all entities

Specified by:
getEntityNames in interface Statistics

getQueries

public String[] getQueries()
Description copied from interface: Statistics
Get all executed query strings

Specified by:
getQueries in interface Statistics

getSecondLevelCacheRegionNames

public String[] getSecondLevelCacheRegionNames()
Description copied from interface: Statistics
Get all second-level cache region names

Specified by:
getSecondLevelCacheRegionNames in interface Statistics

getSuccessfulTransactionCount

public long getSuccessfulTransactionCount()
Description copied from interface: Statistics
The number of transactions we know to have been successful

Specified by:
getSuccessfulTransactionCount in interface Statistics

getTransactionCount

public long getTransactionCount()
Description copied from interface: Statistics
The number of transactions we know to have completed

Specified by:
getTransactionCount in interface Statistics

getCloseStatementCount

public long getCloseStatementCount()
Description copied from interface: Statistics
The number of prepared statements that were released

Specified by:
getCloseStatementCount in interface Statistics

getPrepareStatementCount

public long getPrepareStatementCount()
Description copied from interface: Statistics
The number of prepared statements that were acquired

Specified by:
getPrepareStatementCount in interface Statistics

getOptimisticFailureCount

public long getOptimisticFailureCount()
Description copied from interface: Statistics
The number of StaleObjectStateExceptions that occurred

Specified by:
getOptimisticFailureCount in interface Statistics

getQueryExecutionMaxTimeQueryString

public String getQueryExecutionMaxTimeQueryString()
Description copied from interface: Statistics
Get the query string for the slowest query.

Specified by:
getQueryExecutionMaxTimeQueryString in interface Statistics


Copyright © 2009 Hibernate.org. All Rights Reserved.