Home > grails, monitoring, plugin > Introducing the Grails Monitor Plugin

Introducing the Grails Monitor Plugin

February 14th, 2008

Grails is a fantastic web framework based on Groovy, which brings the convention-over-configuration paradigm pioneered by Ruby on Rails to the Java world. There is currently a lot of buzz around Grails and so far I had a lot of fun working with the framework.

One aspect of Grails is easy extensibility using plugins. There are already some plugins, which cover a lot of functionality. I have been working on a plugin of my own, a generic monitoring plugin, which will be released shortly under a Apache License.

The monitoring plugin provides pre-defined monitors for many aspects of a web application. Additionally it is really easy to define your own monitors to track usage of application-specific metrics.

The plugin is based around rr4j, which is a Java port of the well-known RRDTool and uses its data storage and graphing engine. It requires the Quartz Plugin (with my patches for GRAILSPLUGINS-190 and GRAILSPLUGINS-213) and Java 1.5 or greater.

So, what does it look like? Some Screenshots (click for bigger image):

The monitor view showing the System group:

The Web group with the Requests graphs:

The Web group with the UserAgent graphs:

So, how do I define a monitor of my own? Following the Grails philosophy of convention over configuration, the monitor plugin defines its own artefact type: Monitor.

Creating an application-specific monitor involves defining a class ending in ‘Monitor’ in the ./grails-app/monitor/ directory and adding some simple elements:


class SessionMonitor implements HttpSessionListener {
def activeSessions = 0L

static monitorName = 'Sessions'
static monitorGroup = 'Web'
static monitorDescription = """The ${monitorName} monitor contains
information regarding active sessions."""

static monitorDefs = {
'activeSessions'( type:'gauge', aggregation:'avg', min:0) {
description = "Number of active sessions"
}
}

static monitorGraphDefs = {
'activeSessions'() {
title = '''Active sessions'''
description = title

// graph sources
source(id:'activeSessions', metric:'activeSessions', aggregation:'average')

// what to draw
area(id:'activeSessions', legend:true)
}
}

void sessionCreated(HttpSessionEvent se) {
activeSessions++
}

void sessionDestroyed(HttpSessionEvent se) {
if (activeSessions > 0) {
activeSessions--
}
}
}

The monitor class specifies a name (monitorName), a group it belongs to (monitorGroup, e.g. ‘Web’, ‘System’, or ‘Application’) and optionally a description (monitorDescription). Two DSLs, one for metrics (monitorDefs), one for graphs (monitorGraphDefs), allow to specify the monitored values and what the graphs should look like. Values are collected periodically (currently every minute) using a Quartz-controlled job.

Details will follow once the plugin is released. It still needs some work for the UI and behind the scenes, but a first version will be available soon.

Roadmap

I have plenty of ideas for additional features and monitors.

Features:

JMX export
XML/JSON/CSV export
Support for non-numeric data (e.g. Java version, OS name, hostname, …)
Possibly storage backends other than RRD4J (e.g. a database)
Notification via EMail when certain thresholds are exceeded
Integration of other graphing solutions, like JFreeChart

Monitors:

Count per Domain object
Requests by controller/action
Database/GORM query stats (using Hibernate statistics)
Special monitors for some databases (MySQL “SHOW STATS”, …)
Security monitor for JSecurity/ACEGI/CAS plugins
Monitor for Quartz jobs (job runs, min/max/avg duration)

Basically, the idea is, that every plugin would provide its own set of monitors for the contributed functionality.

I you have any other idea, advice, or feature requests please feel free to post a comment below.

Categories: grails, monitoring, plugin Tags:
  1. Glenn Saqui
    February 14th, 2008 at 11:10 | #1

    Hi,

    When do you think this plugin will be released?

  2. Marc Palmer
    February 14th, 2008 at 12:40 | #2

    Gimme gimme gimme!

    We’d love this for our sites.

    One thing – how will you build in some hooks so that we can easily restrict access to authenticated users only? We can probably do this with Grails 1.0 filters… but it needs to be worked out.

  3. Wolfgang Schell
    February 14th, 2008 at 13:48 | #3

    @Marc:

    I deliberately left out hooks for securing the monitoring UI, as this would depend on the security mechanism chosen by the application developer.

    Filters or at least customized UrlMappings will do the trick for now.

    For plugins to actively use security features, we really need some kind of “standard” security functionality, at least a basic common API/framework, which might still be implemented by different libraries (JSecurity, Acegi, CAS, …)

  4. Wolfgang Schell
    February 14th, 2008 at 13:57 | #4

    @Glenn:

    It will still take one or two weeks for me to release a first version, as I’m doing this in my spare time.

    I won’t promise that it will be “production ready” as until now I’m just running it myself in its own environment, but it is going along nicely.

    I just got access to the grails-plugin repository, so I will be importing it over the weekend for others to play around a little bit.

    Of course, documentation needs to be written, etc.

  5. ismael
    February 14th, 2008 at 14:30 | #5

    Great plugin idea, that looks so obvious and natural after you know about it !

    Do you intend to give metrics about permgen space use ?

  6. Jim Shingler
    February 14th, 2008 at 15:10 | #6

    Very Nice! I look forward to the the plugin becoming available

  7. Anonymous
    February 14th, 2008 at 15:59 | #7

    Holy cow, this looks AMAZING!

  8. Dmitriy Kopylenko
    February 14th, 2008 at 16:03 | #8

    +1 for the ‘standard’ security API/conventions in Grails

  9. Matt Raible
    February 14th, 2008 at 18:09 | #9

    This looks like a very cool plugin Wolfgang. Well done!

  10. Wolfgang’s Sweetheart
    February 14th, 2008 at 23:44 | #10

    He’s my boyfriend! And obviously one of the biggest developers in town. 🙂

  11. mike stephen
    February 21st, 2008 at 11:52 | #11

    This looks amazing Wolfgang, looking forward to using it. Keep up the good work!

  12. Anonymous
    October 24th, 2008 at 23:45 | #12

    Is this plugin available? It looks really cool but I can’t find it on the Grails website or when I enter ‘grails list-plugins’ from the command line.

  13. Wolfgang Schell
    October 27th, 2008 at 15:24 | #13

    The plugin is currently on hold and will be as long as I’m working for my current employer, sorry….

Comments are closed.
Fork me on GitHub