Tuesday, August 12, 2008

Poor man web app monitoring

This is actually something I need to make sure my web apps are still up and running.

1. Put the start time in global session.
In Bootstrap:

servletContext.setAttribute("startTime", new Date())

2. Then create a controller, or resuse an existing controller and define "uptime" action there:
def uptime = {
def starTime = servletContext.getAttribute("starTime")
long uptime = new Date().time - startTime.time

3. Now come the easy part -- a simple groovy script to periodically check the server to make sure it's up.

try {
def p = new URL("http://host:8080/app/foo/uptime").text
println p // up and running
} catch (e) {
println "Server seems to be down"

1 comment:

Anonymous said...

nice tip dude ;)