public class

StatisticsService

extends Object
implements StatisticsServiceMBean
java.lang.Object
   ↳ org.hibernate.jmx.StatisticsService

Class Overview

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.

Summary

Public Constructors
StatisticsService()
Public Methods
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)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.jmx.StatisticsServiceMBean
From interface org.hibernate.stat.Statistics

Public Constructors

public StatisticsService ()

Public Methods

public void clear ()

reset all statistics

See Also

public long getCloseStatementCount ()

The number of prepared statements that were released

public long getCollectionFetchCount ()

Global number of collections fetched

public long getCollectionLoadCount ()

Global number of collections loaded

public long getCollectionRecreateCount ()

Global number of collections recreated

public long getCollectionRemoveCount ()

Global number of collections removed

public String[] getCollectionRoleNames ()

Get the names of all collection roles

public CollectionStatistics getCollectionStatistics (String role)

Get collection statistics per role

Parameters
role collection role
Returns
  • CollectionStatistics

public long getCollectionUpdateCount ()

Global number of collections updated

public 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)

public long getEntityDeleteCount ()

Get global number of entity deletes

Returns
  • entity deletion count

public long getEntityFetchCount ()

Get global number of entity fetchs

Returns
  • entity fetch (from DB)

public long getEntityInsertCount ()

Get global number of entity inserts

Returns
  • entity insertion count

public long getEntityLoadCount ()

Get global number of entity loads

Returns
  • entity load (from DB)

public String[] getEntityNames ()

Get the names of all entities

public EntityStatistics getEntityStatistics (String entityName)

find entity statistics per name

Parameters
entityName entity name
Returns
  • EntityStatistics object

public long getEntityUpdateCount ()

Get global number of entity updates

Returns
  • entity update

public long getFlushCount ()

Get the global number of flush executed by sessions (either implicit or explicit)

See Also

public long getOptimisticFailureCount ()

The number of StaleObjectStateExceptions that occurred

public long getPrepareStatementCount ()

The number of prepared statements that were acquired

public String[] getQueries ()

Get all executed query strings

public long getQueryCacheHitCount ()

Get the global number of cached queries successfully retrieved from cache

public long getQueryCacheMissCount ()

Get the global number of cached queries *not* found in cache

public long getQueryCachePutCount ()

Get the global number of cacheable queries put in cache

public long getQueryExecutionCount ()

Get global number of executed queries

Returns
  • query execution count

public long getQueryExecutionMaxTime ()

Get the time in milliseconds of the slowest query.

public String getQueryExecutionMaxTimeQueryString ()

Get the query string for the slowest query.

public QueryStatistics getQueryStatistics (String hql)

Query statistics from query string (HQL or SQL)

Parameters
hql query string
Returns
  • QueryStatistics

public long getSecondLevelCacheHitCount ()

Global number of cacheable entities/collections successfully retrieved from the cache

public long getSecondLevelCacheMissCount ()

Global number of cacheable entities/collections not found in the cache and loaded from the database.

public long getSecondLevelCachePutCount ()

Global number of cacheable entities/collections put in the cache

public String[] getSecondLevelCacheRegionNames ()

Get all second-level cache region names

public SecondLevelCacheStatistics getSecondLevelCacheStatistics (String regionName)

Second level cache statistics per region

Parameters
regionName region name
Returns
  • SecondLevelCacheStatistics

public long getSessionCloseCount ()

Global number of sessions closed

public long getSessionOpenCount ()

Global number of sessions opened

public long getStartTime ()

See Also

public long getSuccessfulTransactionCount ()

The number of transactions we know to have been successful

public long getTransactionCount ()

The number of transactions we know to have completed

public boolean isStatisticsEnabled ()

Are statistics logged

public void logSummary ()

log in info level the main statistics

public void setSessionFactory (SessionFactory sf)

Useful to init this MBean wo a JNDI session factory name

Parameters
sf session factory to register

public void setSessionFactoryJNDIName (String sfJNDIName)

Publish the statistics of a session factory bound to the default JNDI context

Parameters
sfJNDIName session factory jndi name

public void setStatisticsEnabled (boolean enable)

Enable statistics logs (this is a dynamic parameter)