Yes, Hibernate provides live statistics. Usage example from the Hibernate book:
Statistics stats = HibernateUtil.getSessionFactory().getStatistics();
stats.setStatisticsEnabled(true);
...
stats.getSessionOpenCount();
stats.logSummary();
EntityStatistics itemStats = stats.getEntityStatistics("auction.model.Item");
itemStats.getFetchCount();
The statistics interfaces are Statistics
for global information, EntityStatistics
for information about a particular entity, CollectionStatistics
for a particular collection role, QueryStatistics
for SQL and HQL queries, and SecondLevelCacheStatistics
for detailed runtime information about a particular region in the optional second-level data cache. A convenient method is logSummary()
, which prints out a complete summary to the console with a single call. If you want to enable the collection of statistics through the configuration, and not programmatically, set the hibernate.generate_statistics
configuration property to true. See the API documentation for more information about the various statistics retrieval methods.
If you are running in an app server, you can also configure JMX to provide you statistics.