Skip to content

Instantly share code, notes, and snippets.

@bodiam
Created May 25, 2015 20:16
Show Gist options
  • Save bodiam/fe3f8448e8296bc2e07d to your computer and use it in GitHub Desktop.
Save bodiam/fe3f8448e8296bc2e07d to your computer and use it in GitHub Desktop.
A small script to check the health status of your Grails 3 and Spring Boot applications
#!/usr/bin/env groovy
import groovy.json.JsonSlurper
/**
* Displays the status of registered Spring Boot URL's.
* To register URL's, create a file called healthcheck.txt in the following format
*
* <name>,<url>
*
* Eg: healthcheck.txt:
* Grails Backend, http://localhost:9090/health
* Spring Boot Backend, http://localhost:8080/health
**/
def configuration = args ? new File(args[0]) : new File("healthcheck.txt")
def RED='\u001B[31m'
def GREEN='\u001B[32m'
def YELLOW='\u001B[33m'
def NC='\u001B[0m' // No Color
configuration.eachLine { line ->
def (name, url) = line.split(",")
print "${YELLOW}${name.trim()}${NC}".padRight(30)
print "- ${url.trim()} ".padRight(35)
try {
def text = new URL(url).text
def json = new JsonSlurper().parseText(text)
if(json.status == 'UP') {
println "${GREEN}OK${NC}"
} else {
println "${RED}ERROR${NC}"
}
} catch(e) {
println "${RED}ERROR${NC}"
}
}
Grails Backend - http://localhost:9090/health ERROR
Spring Boot Backend - http://localhost:8080/health OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment