DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor Your Ktor (Kotlin) API with Vigilmon (Free Uptime + Health Checks)

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)
}
Enter fullscreen mode Exit fullscreen mode

Deploy this change and verify it responds with HTTP 200 at your domain.

Step 2: Create a Monitor in Vigilmon

  1. Sign in at vigilmon.online and go to Monitors > New Monitor
  2. Set URL to your health endpoint
  3. Set Check interval: 1 minute for production APIs
  4. Set Regions: 2-3 for multi-region consensus
  5. Set Expected status code: 200
  6. 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:

  1. New Monitor > SSL Certificate
  2. Set the domain
  3. 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"
        )
    )
}
Enter fullscreen mode Exit fullscreen mode

Summary

  1. Add /health endpoint to your Ktor app returning HTTP 200 when healthy
  2. Create an HTTP monitor in Vigilmon pointing at that endpoint
  3. Add a second SSL monitor for your domain
  4. Configure alert channels (email + Slack minimum)

Your Ktor API now has external uptime monitoring that will alert you before your users notice a problem.

Start monitoring your Ktor API with Vigilmon - free

Top comments (0)