Git Product home page Git Product logo

log-hibernate-stats's Introduction

logHibernateStats

Summary

A simple Grails 3 plugin to log Hibernate statistics on controller actions.

For the Grails 2 plugin code and documentation, see: https://github.com/ishults/log-hibernate-stats/tree/grails_2.x

Configuration and Usage

To add this plugin, in your build.gradle add:

repositories {
  ...
  maven { url "http://dl.bintray.com/ishults/plugins" }
}
dependencies {
  ...
  compile "org.grails.plugins:log-hibernate-stats:1.0.20"
}

Then just update your config (such as application.yml) to add

logHibernateStats:
    enabled: 'ALWAYS'// From ALWAYS, ALLOWED, NEVER

for the environments you want to track statistics for.

Then in your logback.groovy set:

logger 'grails.app.controllers.org.grails.plugins.LogHibernateStatsInterceptor',
    DEBUG, ['STDOUT'], false // Or INFO

You should now be seeing output like:

INFO  controller.ControllerFilters  -
############## Hibernate Stats ##############
Action:                     /controller/actionName

Transaction Count:          2
Flush Count:                1
Prepared Statement Count:   2

Total time:                 500 ms
#############################################

after each request. If you set the logging to 'debug', you will also see:

DEBUG  controller.ControllerFilters  -
### Start logging for action: controller/actionName ###

at the start of each action (useful if logSql is enabled too).

If instead you'd like to target only specific actions, you can set

logHibernateStats.enabled = 'ALLOWED'

and instead append the parameter '_logHibernateStats=true' to your request. This will isolate the logging to just that request.

It is recommended to keep the plugin enabled value at 'NEVER' by default, and setting it to 'ALLOWED' or 'ALWAYS' when debugging in development.

Caveats

  • This plugin heavily assumes that no other place in the code is clearing/using Hibernate statistics.
  • If there are background services interacting with Hibernate, or if multiple requests are sent in succession, the statistics may not be accurate.

Credits

Plugin created by Igor Shults.

Official Grails 3.x plugin page here: https://bintray.com/ishults/plugins/org.grails.plugins%3Alog-hibernate-stats/view

Official Grails 2.x plugin page here: http://grails.org/plugin/log-hibernate-stats

If you're not interested in running this as a plugin, I wrote a blog post on some standalone code here: http://www.objectpartners.com/2014/04/22/tracking-hibernate-statistics-across-grails-actions/

Inspired by a post on Hibernate logging by Himanshu Seth: http://www.intelligrape.com/blog/2011/11/07/grails-find-number-of-queries-executed-for-a-particular-request/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.