How to Monitor Your Ktor (Kotlin) API with Vigilmon (Free Uptime + Health Checks)
Ktor is a lightweight Kotlin framework for building asynchronous servers and clients. If your API is running on Ktor, you need uptime monitoring to know when it goes down, when responses degrade, and when SSL certificates are close to expiring.
This guide shows you how to add a health endpoint to your Ktor app and hook it up to Vigilmon for free external monitoring.
Why External Monitoring Matters
Your internal health checks only run if your server is still running and responding. External monitoring from multiple regions catches:
- The entire server going offline (no process, no check)
- Network routing failures that prevent traffic from reaching you
- Crashes or deadlocks that stop the Kotlin coroutine dispatcher
Step 1: Add a Health Endpoint to Your Ktor App
Add a simple /health route:
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.routing.*
import io.ktor.server.response.*
import io.ktor.http.*
fun main() {
embeddedServer(Netty, port = 8080) {
routing {
get("/health") {
call.respond(HttpStatusCode.OK, mapOf("status" to "ok"))
}
}
}.start(wait = true)
}
Deploy this change and verify it responds with HTTP 200 at your domain.
Step 2: Create a Monitor in Vigilmon
- Sign in at vigilmon.online and go to Monitors > New Monitor
- Set URL to your health endpoint
- Set Check interval: 1 minute for production APIs
- Set Regions: 2-3 for multi-region consensus
- Set Expected status code: 200
- Save the monitor
Vigilmon starts checking your endpoint immediately.
Step 3: Configure Alerts
Go to Alert Channels and add:
- Email: instant notification when the check fails
- Slack: post to your ops or alerts channel
- Webhook: send to PagerDuty, Discord, or any HTTP endpoint
Set escalation to alert after 2 consecutive failures to avoid false positives from transient network blips.
Step 4: Monitor SSL Certificate Expiry
Add a separate SSL certificate monitor in Vigilmon:
- New Monitor > SSL Certificate
- Set the domain
- Alert at 30 days remaining and 7 days remaining
Advanced: Deep Health Check with Coroutines
get("/health/deep") {
val dbOk = runCatching {
withContext(Dispatchers.IO) { checkDatabaseConnection() }
}.isSuccess
call.respond(
if (dbOk) HttpStatusCode.OK else HttpStatusCode.ServiceUnavailable,
mapOf(
"status" to if (dbOk) "ok" else "degraded",
"database" to if (dbOk) "ok" else "error"
)
)
}
Summary
- Add /health endpoint to your Ktor app returning HTTP 200 when healthy
- Create an HTTP monitor in Vigilmon pointing at that endpoint
- Add a second SSL monitor for your domain
- Configure alert channels (email + Slack minimum)
Your Ktor API now has external uptime monitoring that will alert you before your users notice a problem.
Top comments (0)