A simple way of monitoring application health in Kotlin.
- Start
com.ximedes.HealthDemoKt.main()
- Visit http://localhost:8080/health to see health information
- Visit http://localhost:8080/pagehit to update the page hit counter
Updating a single health item:
HealthService.updateItem("pageHits", pageHits)
Registering a callback that gets called when health information is asked:
HealthService.registerCallback("myLiveStatusInformation") {
"Your callback code goes here"
}
Getting health information as a sorted map:
HealthService.getCurrentHealth()
Exposing health information as a REST endpoint in ktor.io:
routing {
get("/health") {
call.respond(HttpStatusCode.OK, HealthService.getCurrentHealth())
}
}
Have fun!