List of usage examples for org.hibernate.stat Statistics getQueryExecutionMaxTimeQueryString
String getQueryExecutionMaxTimeQueryString();
From source file:com.francetelecom.clara.cloud.scalability.helper.StatisticsHelper.java
License:Apache License
/** * Log the current statistics/*from w w w . j a v a2s. co m*/ * * @param stats hibernate statistics */ public static void logStats(Statistics stats) { logger.info("Database statistics"); logger.info(" Number of connection requests : " + stats.getConnectCount()); logger.info(" Session flushes : " + stats.getFlushCount()); logger.info(" Transactions : " + stats.getTransactionCount()); logger.info(" Successful transactions : " + stats.getSuccessfulTransactionCount()); logger.info(" Sessions opened : " + stats.getSessionOpenCount()); logger.info(" Sessions closed : " + stats.getSessionCloseCount()); logger.info(" Queries executed : " + stats.getQueryExecutionCount()); logger.info(" Max query time : " + stats.getQueryExecutionMaxTime()); logger.info(" Max time query : " + stats.getQueryExecutionMaxTimeQueryString()); logger.info("Collection statistics"); logger.info(" Collections fetched : " + stats.getCollectionFetchCount()); logger.info(" Collections loaded : " + stats.getCollectionLoadCount()); logger.info(" Collections rebuilt : " + stats.getCollectionRecreateCount()); logger.info(" Collections batch deleted : " + stats.getCollectionRemoveCount()); logger.info(" Collections batch updated : " + stats.getCollectionUpdateCount()); logger.info("Object statistics"); logger.info(" Objects fetched : " + stats.getEntityFetchCount()); logger.info(" Objects loaded : " + stats.getEntityLoadCount()); logger.info(" Objects inserted : " + stats.getEntityInsertCount()); logger.info(" Objects deleted : " + stats.getEntityDeleteCount()); logger.info(" Objects updated : " + stats.getEntityUpdateCount()); logger.info("Cache statistics"); double chit = stats.getQueryCacheHitCount(); double cmiss = stats.getQueryCacheMissCount(); logger.info(" Cache hit count : " + chit); logger.info(" Cache miss count : " + cmiss); logger.info(" Cache hit ratio : " + (chit / (chit + cmiss))); String[] entityNames = stats.getEntityNames(); Arrays.sort(entityNames); for (String entityName : entityNames) { Class<?> entityClass = null; try { entityClass = Class.forName(entityName); } catch (ClassNotFoundException e) { logger.error("Unable to load class for " + entityName, e); } entityStats(stats, entityClass); } //Uncomment these lines to trace every query (can generate a lot of logs) String[] qs = stats.getQueries(); for (String q : qs) { queryStats(stats, q); } String[] slcrn = stats.getSecondLevelCacheRegionNames(); for (String s : slcrn) { secondLevelStats(stats, s); } }
From source file:com.thoughtworks.go.server.service.support.HibernateInformationProvider.java
License:Apache License
@Override public Map<String, Object> asJson() { LinkedHashMap<String, Object> json = new LinkedHashMap<>(); Statistics statistics = sessionFactory.getStatistics(); if (!statistics.isStatisticsEnabled()) { return json; }/* w ww.ja va 2 s. c om*/ json.put("EntityDeleteCount", statistics.getEntityDeleteCount()); json.put("EntityInsertCount", statistics.getEntityInsertCount()); json.put("EntityLoadCount", statistics.getEntityLoadCount()); json.put("EntityFetchCount", statistics.getEntityFetchCount()); json.put("EntityUpdateCount", statistics.getEntityUpdateCount()); json.put("QueryExecutionCount", statistics.getQueryExecutionCount()); json.put("QueryExecutionMaxTime", statistics.getQueryExecutionMaxTime()); json.put("QueryExecutionMaxTimeQueryString", statistics.getQueryExecutionMaxTimeQueryString()); json.put("QueryCacheHitCount", statistics.getQueryCacheHitCount()); json.put("QueryCacheMissCount", statistics.getQueryCacheMissCount()); json.put("QueryCachePutCount", statistics.getQueryCachePutCount()); json.put("FlushCount", statistics.getFlushCount()); json.put("ConnectCount", statistics.getConnectCount()); json.put("SecondLevelCacheHitCount", statistics.getSecondLevelCacheHitCount()); json.put("SecondLevelCacheMissCount", statistics.getSecondLevelCacheMissCount()); json.put("SecondLevelCachePutCount", statistics.getSecondLevelCachePutCount()); json.put("SessionCloseCount", statistics.getSessionCloseCount()); json.put("SessionOpenCount", statistics.getSessionOpenCount()); json.put("CollectionLoadCount", statistics.getCollectionLoadCount()); json.put("CollectionFetchCount", statistics.getCollectionFetchCount()); json.put("CollectionUpdateCount", statistics.getCollectionUpdateCount()); json.put("CollectionRemoveCount", statistics.getCollectionRemoveCount()); json.put("CollectionRecreateCount", statistics.getCollectionRecreateCount()); json.put("StartTime", statistics.getStartTime()); json.put("SecondLevelCacheRegionNames", statistics.getSecondLevelCacheRegionNames()); json.put("SuccessfulTransactionCount", statistics.getSuccessfulTransactionCount()); json.put("TransactionCount", statistics.getTransactionCount()); json.put("PrepareStatementCount", statistics.getPrepareStatementCount()); json.put("CloseStatementCount", statistics.getCloseStatementCount()); json.put("OptimisticFailureCount", statistics.getOptimisticFailureCount()); LinkedHashMap<String, Object> queryStats = new LinkedHashMap<>(); json.put("Queries", queryStats); String[] queries = statistics.getQueries(); for (String query : queries) { queryStats.put(query, statistics.getQueryStatistics(query)); } LinkedHashMap<String, Object> entityStatistics = new LinkedHashMap<>(); json.put("EntityStatistics", entityStatistics); String[] entityNames = statistics.getEntityNames(); for (String entityName : entityNames) { entityStatistics.put(entityName, statistics.getEntityStatistics(entityName)); } LinkedHashMap<String, Object> roleStatistics = new LinkedHashMap<>(); json.put("RoleStatistics", roleStatistics); String[] roleNames = statistics.getCollectionRoleNames(); for (String roleName : roleNames) { roleStatistics.put(roleName, statistics.getCollectionStatistics(roleName)); } return json; }
From source file:de.iew.framework.hibernate.statistics.StatisticsLogger.java
License:Apache License
public void logStatistics() { Statistics statistics = this.sessionFactory.getStatistics(); statistics.setStatisticsEnabled(true); StringBuilder sb = new StringBuilder("\nStatistics"); sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount()); sb.append("\nEntityDeleteCount: ").append(statistics.getEntityDeleteCount()); sb.append("\nEntityInsertCount: ").append(statistics.getEntityInsertCount()); sb.append("\nEntityLoadCount: ").append(statistics.getEntityLoadCount()); sb.append("\nEntityFetchCount: ").append(statistics.getEntityFetchCount()); sb.append("\nEntityUpdateCount: ").append(statistics.getEntityUpdateCount()); sb.append("\nQueryExecutionCount: ").append(statistics.getQueryExecutionCount()); sb.append("\nQueryExecutionMaxTime: ").append(statistics.getQueryExecutionMaxTime()); sb.append("\nQueryExecutionMaxTimeQueryString: ").append(statistics.getQueryExecutionMaxTimeQueryString()); sb.append("\nQueryCacheHitCount: ").append(statistics.getQueryCacheHitCount()); sb.append("\nQueryCacheMissCount: ").append(statistics.getQueryCacheMissCount()); sb.append("\nQueryCachePutCount: ").append(statistics.getQueryCachePutCount()); sb.append("\nNaturalIdQueryExecutionCount: ").append(statistics.getNaturalIdQueryExecutionCount()); sb.append("\nNaturalIdQueryExecutionMaxTime: ").append(statistics.getNaturalIdQueryExecutionMaxTime()); sb.append("\nNaturalIdQueryExecutionMaxTimeRegion: ") .append(statistics.getNaturalIdQueryExecutionMaxTimeRegion()); sb.append("\nNaturalIdCacheHitCount: ").append(statistics.getNaturalIdCacheHitCount()); sb.append("\nNaturalIdCacheMissCount: ").append(statistics.getNaturalIdCacheMissCount()); sb.append("\nNaturalIdCachePutCount: ").append(statistics.getNaturalIdCachePutCount()); sb.append("\nUpdateTimestampsCacheHitCount: ").append(statistics.getUpdateTimestampsCacheHitCount()); sb.append("\nUpdateTimestampsCacheMissCount: ").append(statistics.getUpdateTimestampsCacheMissCount()); sb.append("\nUpdateTimestampsCachePutCount: ").append(statistics.getUpdateTimestampsCachePutCount()); sb.append("\nFlushCount: ").append(statistics.getFlushCount()); sb.append("\nConnectCount: ").append(statistics.getConnectCount()); sb.append("\nSecondLevelCacheHitCount: ").append(statistics.getSecondLevelCacheHitCount()); sb.append("\nSecondLevelCacheMissCount: ").append(statistics.getSecondLevelCacheMissCount()); sb.append("\nSecondLevelCachePutCount: ").append(statistics.getSecondLevelCachePutCount()); sb.append("\nSessionCloseCount: ").append(statistics.getSessionCloseCount()); sb.append("\nSessionOpenCount: ").append(statistics.getSessionOpenCount()); sb.append("\nCollectionLoadCount: ").append(statistics.getCollectionLoadCount()); sb.append("\nCollectionFetchCount: ").append(statistics.getCollectionFetchCount()); sb.append("\nCollectionUpdateCount: ").append(statistics.getCollectionUpdateCount()); sb.append("\nCollectionRemoveCount: ").append(statistics.getCollectionRemoveCount()); sb.append("\nCollectionRecreateCount: ").append(statistics.getCollectionRecreateCount()); sb.append("\nStartTime: ").append(statistics.getStartTime()); sb.append("\nQueries: ").append(statistics.getQueries()); sb.append("\nEntityNames: ").append(statistics.getEntityNames()); sb.append("\nCollectionRoleNames: ").append(statistics.getCollectionRoleNames()); sb.append("\nSecondLevelCacheRegionNames: ").append(statistics.getSecondLevelCacheRegionNames()); sb.append("\nSuccessfulTransactionCount: ").append(statistics.getSuccessfulTransactionCount()); sb.append("\nTransactionCount: ").append(statistics.getTransactionCount()); sb.append("\nPrepareStatementCount: ").append(statistics.getPrepareStatementCount()); sb.append("\nCloseStatementCount: ").append(statistics.getCloseStatementCount()); sb.append("\nOptimisticFailureCount: ").append(statistics.getOptimisticFailureCount()); if (log.isDebugEnabled()) { log.debug(sb);/*from w ww. ja va2 s . c om*/ } }
From source file:gr.interamerican.bo2.impl.open.hibernate.HibernateBo2Utils.java
License:Open Source License
/** * Logs {@link SessionFactory} statistics. * // w ww. ja va 2s. c om * @param sessionFactory */ @SuppressWarnings("nls") public static void logSessionFactoryStatistics(SessionFactory sessionFactory) { Statistics statistics = sessionFactory.getStatistics(); Object[] stats = new Object[] { statistics.getCollectionFetchCount(), statistics.getCollectionLoadCount(), statistics.getEntityFetchCount(), statistics.getEntityLoadCount(), statistics.getFlushCount(), statistics.getOptimisticFailureCount(), statistics.getQueryExecutionMaxTime(), statistics.getQueryExecutionMaxTimeQueryString(), statistics.getSessionOpenCount(), statistics.getSecondLevelCacheHitCount(), statistics.getSecondLevelCacheMissCount() }; StringBuilder sb = new StringBuilder(); for (Object o : stats) { String s = (o == null) ? "null" : o.toString(); sb.append(s + StringConstants.COMMA + StringConstants.SPACE); } sb.setLength(sb.length() - 2); Debug.debug(logger, "Factory statistics: [ " + sb.toString() + " ]"); }
From source file:org.bedework.calcore.hibernate.DbStatistics.java
License:Apache License
/** Get the current statistics * * @param dbStats/*from w w w. j av a 2s . co m*/ * @return Collection */ public static Collection<StatsEntry> getStats(Statistics dbStats) { /* XXX this ought to be property driven to some extent. The cache stats in * particular. */ ArrayList<StatsEntry> al = new ArrayList<StatsEntry>(); if (dbStats == null) { return al; } al.add(new StatsEntry("Database statistics")); al.add(new StatsEntry("Number of connection requests", dbStats.getConnectCount())); al.add(new StatsEntry("Session flushes", dbStats.getFlushCount())); al.add(new StatsEntry("Transactions", dbStats.getTransactionCount())); al.add(new StatsEntry("Successful transactions", dbStats.getSuccessfulTransactionCount())); al.add(new StatsEntry("Sessions opened", dbStats.getSessionOpenCount())); al.add(new StatsEntry("Sessions closed", dbStats.getSessionCloseCount())); al.add(new StatsEntry("Queries executed", dbStats.getQueryExecutionCount())); al.add(new StatsEntry("Max query time", dbStats.getQueryExecutionMaxTime())); al.add(new StatsEntry("Max time query", dbStats.getQueryExecutionMaxTimeQueryString())); al.add(new StatsEntry("Collection statistics")); al.add(new StatsEntry("Collections fetched", dbStats.getCollectionFetchCount())); al.add(new StatsEntry("Collections loaded", dbStats.getCollectionLoadCount())); al.add(new StatsEntry("Collections rebuilt", dbStats.getCollectionRecreateCount())); al.add(new StatsEntry("Collections batch deleted", dbStats.getCollectionRemoveCount())); al.add(new StatsEntry("Collections batch updated", dbStats.getCollectionUpdateCount())); al.add(new StatsEntry("Object statistics")); al.add(new StatsEntry("Objects fetched", dbStats.getEntityFetchCount())); al.add(new StatsEntry("Objects loaded", dbStats.getEntityLoadCount())); al.add(new StatsEntry("Objects inserted", dbStats.getEntityInsertCount())); al.add(new StatsEntry("Objects deleted", dbStats.getEntityDeleteCount())); al.add(new StatsEntry("Objects updated", dbStats.getEntityUpdateCount())); al.add(new StatsEntry("Cache statistics")); double chit = dbStats.getQueryCacheHitCount(); double cmiss = dbStats.getQueryCacheMissCount(); al.add(new StatsEntry("Cache hit count", chit)); al.add(new StatsEntry("Cache miss count", cmiss)); al.add(new StatsEntry("Cache hit ratio", chit / (chit + cmiss))); entityStats(al, dbStats, BwCalendar.class); entityStats(al, dbStats, BwEventObj.class); entityStats(al, dbStats, BwEventAnnotation.class); entityStats(al, dbStats, BwCategory.class); entityStats(al, dbStats, BwLocation.class); entityStats(al, dbStats, BwContact.class); entityStats(al, dbStats, BwUser.class); collectionStats(al, dbStats, BwCalendar.class, "children"); collectionStats(al, dbStats, BwEventObj.class, "attendees"); collectionStats(al, dbStats, BwEventObj.class, "categories"); collectionStats(al, dbStats, BwEventObj.class, "descriptions"); collectionStats(al, dbStats, BwEventObj.class, "summaries"); collectionStats(al, dbStats, BwEventObj.class, "rrules"); collectionStats(al, dbStats, BwEventObj.class, "rdates"); collectionStats(al, dbStats, BwEventObj.class, "exdates"); collectionStats(al, dbStats, BwEventAnnotation.class, "attendees"); collectionStats(al, dbStats, BwEventAnnotation.class, "categories"); collectionStats(al, dbStats, BwEventAnnotation.class, "descriptions"); collectionStats(al, dbStats, BwEventAnnotation.class, "summaries"); collectionStats(al, dbStats, BwEventAnnotation.class, "rrules"); collectionStats(al, dbStats, BwEventAnnotation.class, "rdates"); collectionStats(al, dbStats, BwEventAnnotation.class, "exdates"); String[] qs = dbStats.getQueries(); for (String q : qs) { queryStats(al, dbStats, q); } String[] slcrn = dbStats.getSecondLevelCacheRegionNames(); for (String s : slcrn) { secondLevelStats(al, dbStats, s); } return al; }
From source file:org.cast.cwm.admin.DatabaseStatisticsPage.java
License:Open Source License
public DatabaseStatisticsPage(PageParameters params) { super(params); Statistics stats = Databinder.getHibernateSessionFactory().getStatistics(); if (stats.isStatisticsEnabled()) { add(new Label("count", String.valueOf(stats.getQueryExecutionCount()))); add(new Label("cloads", String.valueOf(stats.getCollectionLoadCount()))); add(new Label("worst", stats.getQueryExecutionMaxTimeQueryString())); // Worked in SNUDLE, why am I getting no output here? add(new Label("worsttime", String.valueOf(stats.getQueryExecutionMaxTime()))); add(new Label("qchit", String.valueOf(stats.getQueryCacheHitCount()))); add(new Label("qcmiss", String.valueOf(stats.getQueryCacheMissCount()))); } else {//from w w w .ja v a 2 s . co m stats.setStatisticsEnabled(true); add(new Label("count", "--")); add(new Label("cloads", "--")); add(new Label("worst", "--")); add(new Label("worsttime", "--")); add(new Label("qchit", "--")); add(new Label("qcmiss", "--")); } stats.clear(); add(new Link<Void>("off") { private static final long serialVersionUID = 1L; @Override public void onClick() { Databinder.getHibernateSessionFactory().getStatistics().setStatisticsEnabled(false); setResponsePage(getApplication().getHomePage()); } }); }
From source file:org.glite.security.voms.admin.core.tasks.LogHibernateStatsTask.java
License:Apache License
@Override public void run() { Statistics stats = HibernateFactory.getFactory().getStatistics(); if (stats != null) { LOG.info("Logging statistics...."); LOG.info("start time: {}", stats.getStartTime()); LOG.info("sessions opened: {}", stats.getSessionOpenCount()); LOG.info("sessions closed: {}", stats.getSessionCloseCount()); LOG.info("transactions: {}", stats.getTransactionCount()); LOG.info("successful transactions: {}", stats.getSuccessfulTransactionCount()); LOG.info("optimistic lock failures: {}", stats.getOptimisticFailureCount()); LOG.info("flushes: {}", stats.getFlushCount()); LOG.info("connections obtained: {}", stats.getConnectCount()); LOG.info("statements prepared: {}", stats.getPrepareStatementCount()); LOG.info("statements closed: {}", stats.getCloseStatementCount()); LOG.info("second level cache puts: {}", stats.getSecondLevelCachePutCount()); LOG.info("second level cache hits: {}", stats.getSecondLevelCacheHitCount()); LOG.info("second level cache misses: {}", stats.getSecondLevelCacheMissCount()); LOG.info("entities loaded: {}", stats.getEntityLoadCount()); LOG.info("entities updated: {}", stats.getEntityUpdateCount()); LOG.info("entities inserted: {}", stats.getEntityInsertCount()); LOG.info("entities deleted: {}", stats.getEntityDeleteCount()); LOG.info("entities fetched (minimize this): {}", stats.getEntityFetchCount()); LOG.info("collections loaded: {}", stats.getCollectionLoadCount()); LOG.info("collections updated: {}", stats.getCollectionUpdateCount()); LOG.info("collections removed: {}", stats.getCollectionRemoveCount()); LOG.info("collections recreated: {}", stats.getCollectionRecreateCount()); LOG.info("collections fetched (minimize this): {}", stats.getCollectionFetchCount()); LOG.info("queries executed to database: {}", stats.getQueryExecutionCount()); LOG.info("query cache puts: {}", stats.getQueryCachePutCount()); LOG.info("query cache hits: {}", stats.getQueryCacheMissCount()); LOG.info("query cache misses: {}", stats.getQueryCacheMissCount()); LOG.info("max query time: {} ms, for query {}", stats.getQueryExecutionMaxTime(), stats.getQueryExecutionMaxTimeQueryString()); }//ww w . j a v a 2 s . c o m }
From source file:org.jboss.as.jpa.hibernate4.management.HibernateManagementAdaptor.java
License:Open Source License
private void registerStatisticAttributes(ManagementResourceRegistration jpaHibernateRegistration) { /**/*from w w w . ja va 2 s. c om*/ * Get global number of entity deletes * @return entity deletion count */ jpaHibernateRegistration.registerMetric(OPERATION_ENTITY_DELETE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getEntityDeleteCount()); } }); /** * Get global number of entity inserts * @return entity insertion count */ jpaHibernateRegistration.registerMetric(OPERATION_ENTITY_INSERT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getEntityInsertCount()); } }); /** * Get global number of entity loads * @return entity load (from DB) */ jpaHibernateRegistration.registerMetric(OPERATION_ENTITY_LOAD_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getEntityLoadCount()); } }); /** * Get global number of entity fetchs * @return entity fetch (from DB) */ jpaHibernateRegistration.registerMetric(OPERATION_ENTITY_FETCH_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getEntityFetchCount()); } }); /** * Get global number of entity updates * @return entity update */ jpaHibernateRegistration.registerMetric(OPERATION_ENTITY_UPDATE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getEntityUpdateCount()); } }); /** * Get global number of executed queries * @return query execution count */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_EXECUTION_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getQueryExecutionCount()); } }); /** * Get the time in milliseconds of the slowest query. */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_EXECUTION_MAX_TIME, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getQueryExecutionMaxTime()); } }); /** * Get the query string for the slowest query. */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_EXECUTION_MAX_TIME_QUERY_STRING, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { String sql = stats.getQueryExecutionMaxTimeQueryString(); if (sql != null) { response.set(sql); } else { context.getResult(); // result will be undefined } } }); /** * Get the global number of cached queries successfully retrieved from cache */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_CACHE_HIT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getQueryCacheHitCount()); } }); /** * Get the global number of cached queries *not* found in cache */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_CACHE_MISS_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getQueryCacheMissCount()); } }); /** * Get the global number of cacheable queries put in cache */ jpaHibernateRegistration.registerMetric(OPERATION_QUERY_CACHE_PUT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getQueryCachePutCount()); } }); /** * Get the global number of flush executed by sessions (either implicit or explicit) */ jpaHibernateRegistration.registerMetric(OPERATION_FLUSH_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getFlushCount()); } }); /** * 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) */ jpaHibernateRegistration.registerMetric(OPERATION_CONNECT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getConnectCount()); } }); /** * Global number of cacheable entities/collections successfully retrieved from the cache */ jpaHibernateRegistration.registerMetric(OPERATION_SECOND_LEVEL_CACHE_HIT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSecondLevelCacheHitCount()); } }); /** * Global number of cacheable entities/collections not found in the cache and loaded from the database. */ jpaHibernateRegistration.registerMetric(OPERATION_SECOND_LEVEL_CACHE_MISS_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSecondLevelCacheMissCount()); } }); /** * Global number of cacheable entities/collections put in the cache */ jpaHibernateRegistration.registerMetric(OPERATION_SECOND_LEVEL_CACHE_PUT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSecondLevelCachePutCount()); } }); /** * Global number of sessions closed */ jpaHibernateRegistration.registerMetric(OPERATION_SESSION_CLOSE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSessionCloseCount()); } }); /** * Global number of sessions opened */ jpaHibernateRegistration.registerMetric(OPERATION_SESSION_OPEN_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSessionOpenCount()); } }); /** * Global number of collections loaded */ jpaHibernateRegistration.registerMetric(OPERATION_COLLECTION_LOAD_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCollectionLoadCount()); } }); /** * Global number of collections fetched */ jpaHibernateRegistration.registerMetric(OPERATION_COLLECTION_FETCH_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCollectionFetchCount()); } }); /** * Global number of collections updated */ jpaHibernateRegistration.registerMetric(OPERATION_COLLECTION_UPDATE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCollectionUpdateCount()); } }); /** * Global number of collections removed */ //even on inverse="true" jpaHibernateRegistration.registerMetric(OPERATION_COLLECTION_REMOVE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCollectionRemoveCount()); } }); /** * Global number of collections recreated */ jpaHibernateRegistration.registerMetric(OPERATION_COLLECTION_RECREATED_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCollectionRecreateCount()); } }); /** * The number of transactions we know to have been successful */ jpaHibernateRegistration.registerMetric(OPERATION_SUCCESSFUL_TRANSACTION_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getSuccessfulTransactionCount()); } }); /** * The number of transactions we know to have completed */ jpaHibernateRegistration.registerMetric(OPERATION_COMPLETED_TRANSACTION_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getTransactionCount()); } }); /** * The number of prepared statements that were acquired */ jpaHibernateRegistration.registerMetric(OPERATION_PREPARED_STATEMENT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getPrepareStatementCount()); } }); /** * The number of prepared statements that were released */ jpaHibernateRegistration.registerMetric(OPERATION_CLOSE_STATEMENT_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getCloseStatementCount()); } }); /** * The number of <tt>StaleObjectStateException</tt>s * that occurred */ jpaHibernateRegistration.registerMetric(OPERATION_OPTIMISTIC_FAILURE_COUNT, new AbstractMetricsHandler() { @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.getOptimisticFailureCount()); } }); /** * enable/disable statistics attribute */ // void registerReadWriteAttribute(String attributeName, OperationStepHandler readHandler, OperationStepHandler writeHandler, AttributeAccess.Storage storage); jpaHibernateRegistration.registerReadWriteAttribute(OPERATION_STATISTICS_ENABLED, new AbstractMetricsHandler() { // readHandler @Override void handle(final ModelNode response, final String name, Statistics stats, OperationContext context) { response.set(stats.isStatisticsEnabled()); } }, StatisticsEnabledWriteHandler.INSTANCE, AttributeAccess.Storage.RUNTIME); }
From source file:org.olat.restapi.system.DatabaseWebService.java
License:Apache License
private HibernateStatisticsVO getHibernateStatistics() { Statistics statistics = DBFactory.getInstance().getStatistics(); if (!statistics.isStatisticsEnabled()) { return null; }//w w w . ja va2 s .co m HibernateStatisticsVO stats = new HibernateStatisticsVO(); stats.setOpenSessionsCount(statistics.getSessionOpenCount()); stats.setTransactionsCount(statistics.getTransactionCount()); stats.setSuccessfulTransactionCount(statistics.getSuccessfulTransactionCount()); stats.setFailedTransactionsCount( statistics.getTransactionCount() - statistics.getSuccessfulTransactionCount()); stats.setOptimisticFailureCount(statistics.getOptimisticFailureCount()); stats.setQueryExecutionCount(statistics.getQueryExecutionCount()); stats.setQueryExecutionMaxTime(statistics.getQueryExecutionMaxTime()); stats.setQueryExecutionMaxTimeQueryString(statistics.getQueryExecutionMaxTimeQueryString()); return stats; }
From source file:org.yawlfoundation.yawl.util.HibernateStatistics.java
License:Open Source License
private XNode getQueries(Statistics stats) { XNode node = new XNode("Queries"); node.addChild("total_executions", stats.getQueryExecutionCount()); node.addChild("max_time", stats.getQueryExecutionMaxTime()); node.addChild("max_time_query", stats.getQueryExecutionMaxTimeQueryString()); node.addChild("total_cache_hits", stats.getQueryCacheHitCount()); node.addChild("total_cache_misses", stats.getQueryCacheMissCount()); node.addChild("total_cache_puts", stats.getQueryCachePutCount()); for (String query : stats.getQueries()) { QueryStatistics queryStats = stats.getQueryStatistics(query); XNode queryNode = node.addChild("query"); queryNode.addChild("hql", query); queryNode.addChild("executions", queryStats.getExecutionCount()); queryNode.addChild("max_time", queryStats.getExecutionMaxTime()); queryNode.addChild("min_time", queryStats.getExecutionMinTime()); queryNode.addChild("average_time", queryStats.getExecutionAvgTime()); queryNode.addChild("row_count", queryStats.getExecutionRowCount()); queryNode.addChild("cache_hits", queryStats.getCacheHitCount()); queryNode.addChild("cache_misses", queryStats.getCacheMissCount()); queryNode.addChild("cache_puts", queryStats.getCachePutCount()); }//from ww w. ja va 2 s .co m return node; }