Update July 5, 2012: See this blog post for an updated test app and support for Grails 2.0+.
I released a new Grails plugin today, app-info. This plugin exposes a lot of internal information for a Grails application. Most of the code for this plugin dates back a long time and was originally mostly JSPs that I would copy into whatever application I was working on to give myself a view into what’s going on. Over time as I started using Spring and Hibernate I added more pages to display that information, and it now also shows information about Grails too.
Click any of the images to see the full-size version in a new window.
This plugin uses the Dynamic Controller plugin to modularize the controller actions as mixins. There are several of them and if there are some you don’t want or need, you can exclude them. None are configured by default – that has to be done in your application’s
grails-app/conf/Config.groovy file. Here’s the configuration from the sample application (download link at the end):
grails.plugins.dynamicController.mixins = [ 'com.burtbeckwith.grails.plugins.appinfo.IndexControllerMixin': 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.HibernateControllerMixin': 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.Log4jControllerMixin' : 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.SpringControllerMixin' : 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.MemoryControllerMixin' : 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.PropertiesControllerMixin' : 'com.burtbeckwith.appinfo_test.AdminManageController', 'com.burtbeckwith.grails.plugins.appinfo.ScopesControllerMixin' : 'com.burtbeckwith.appinfo_test.AdminManageController' ]
With this configuration all of the URLs will start with http://localhost:8080/appname/adminManage. My preference is to re-map these in
grails-app/conf/UrlMappings.groovy to http://localhost:8080/appname/admin/manage since I want the administration parts of the application under /admin/**. This is optional but if you want to do this see the configuration in the sample app.
Note: This plugin exposes a lot of information about your application so you’re strongly recommended to use a security plugin and guard these URLs. The sample application uses the Spring Security Core plugin but you’re free to restrict access however you like, and optionally not even include this in your production war.
The Attributes menu has three entries:
Displays all application-scope attributes from the ServletContext
Displays all request-scope attributes from the current HttpServletRequest. Since this is for the current request, it’s mostly useful to see what’s available in a typical request.
Displays all session-scope attributes from the current HttpSession. Since this is for the current request, it’s mostly useful to see what’s available in a typical session.
The Properties menu has three entries:
A read/write view of the DataSource bean. Depending on the DataSource implementation, changing an attribute will take effect immediately and reset the connection pool
Read-only view of the Grails Configuration.
Read/write view of system properties. You can alter current properties or add new ones.
The Info menu has five entries:
All controllers, plus links to all actions
Has comboboxes for all loggers to change the log level at runtime. Also has a text field to register a new Logger and its level.
Also includes a reverse-engineered log4j.xml based on the in-memory Log4j configuration. This is an estimate, so it may not be 100% accurate. But if you’re having logging configuration issues and are familiar with the log4j.xml format, this can be convenient for diagnosing how things are misconfigured.
Graphs describing memory usage. Also has an action to trigger explicit garbage collection.
Displays all current sessions and session-scope variables with a link to invalidate the session. This is enabled by default; to disable set
grails.plugins.appinfo.useContextListener = false in
Spring bean information for all beans in the “main” context and the parent context
The Hibernate menu has five entries and several sub-actions
- Mappings Info
- Auxiliary Database Objects
- Named Queries
- Named SQL Queries
- Filter Definitions
ER-style graphs of all Hibernate classes with relationships.
ER-style graphs of all tables with relationships.
2nd-level cache information for StandardQueryCache, UpdateTimestampsCache, and all domain class caches.
Also has links to clear the cache and display usage graphs
- General Hibernate statistics
- Links for statistics for each domain class
- Links for statistics for each collection
- Links for statistics for cached queries
On each page there are three combo boxes. The Tables combo box lists all database tables and selecting one displays detailed information for that table
The Entities combo box lists all entities (domain classes, JPA-annotated Java classes, and hbm.xml-mapped classes) and selecting one displays detailed information for each one
The hbm.xml combo box lists all entities and selecting one displays the reverse-engineered hbm.xml that would have created the equivalent entity. This is useful if you’re having GORM mapping issues and want to see what the Hibernate configuration is
You can download a preconfigured sample application here
The /admin/** URLs in the sample app are restricted to users with ROLE_ADMIN. There’s one user configured in BootStrap.groovy with username ‘admin’ and password ‘password’ with ROLE_ADMIN, so you can use that to authenticate.