How to Monitor Your Fiber (Go) Application with Vigilmon
Fiber is the fastest Go web framework, inspired by Express.js and built on top of Fasthttp. It's a popular choice for building high-performance APIs and microservices. Vigilmon pairs seamlessly with Fiber to give your Go applications uptime monitoring, SSL alerts, and public status pages.
Why Monitor Your Fiber App?
Fiber apps are often used for production APIs and backend services. Without monitoring:
- Crashes go undetected until users complain
- You don't know response time is degrading
- SSL certificates expire silently
Adding a Health Endpoint to Fiber
Basic Health Check
package main
import (
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
// Health check endpoint for Vigilmon
app.Get("/health", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"status": "ok",
"service": "fiber-api",
})
})
app.Listen(":3000")
}
Health Check with Dependency Verification
package main
import (
"context"
"time"
"github.com/gofiber/fiber/v2"
"github.com/jackc/pgx/v5/pgxpool"
)
var db *pgxpool.Pool
func healthCheck(c *fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
// Check database connectivity
if err := db.Ping(ctx); err != nil {
return c.Status(503).JSON(fiber.Map{
"status": "error",
"detail": "database unreachable",
})
}
return c.JSON(fiber.Map{
"status": "ok",
"database": "connected",
"ts": time.Now().Unix(),
})
}
func main() {
// Initialize DB pool
var err error
db, err = pgxpool.New(context.Background(), "postgres://...")
if err != nil {
panic(err)
}
defer db.Close()
app := fiber.New()
app.Get("/health", healthCheck)
app.Listen(":3000")
}
Using Fiber's Built-in Monitor Middleware
Fiber has a built-in monitor middleware that provides process metrics:
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/monitor"
)
func main() {
app := fiber.New()
// Fiber's built-in monitor (not for external monitoring)
app.Get("/metrics", monitor.New(monitor.Config{
Title: "Fiber Metrics",
}))
// Simple health endpoint for Vigilmon
app.Get("/health", func(c *fiber.Ctx) error {
return c.SendString("ok")
})
app.Listen(":3000")
}
Health Check Middleware Pattern
For larger Fiber apps, extract health logic into a middleware:
package middleware
import (
"github.com/gofiber/fiber/v2"
"time"
)
type HealthStatus struct {
Status string `json:"status"`
Timestamp int64 `json:"timestamp"`
Checks map[string]string `json:"checks"`
}
func HealthMiddleware(checks map[string]func() error) fiber.Handler {
return func(c *fiber.Ctx) error {
results := make(map[string]string)
allOk := true
for name, checkFn := range checks {
if err := checkFn(); err != nil {
results[name] = "error: " + err.Error()
allOk = false
} else {
results[name] = "ok"
}
}
status := HealthStatus{
Timestamp: time.Now().Unix(),
Checks: results,
}
if allOk {
status.Status = "ok"
return c.JSON(status)
}
status.Status = "degraded"
return c.Status(503).JSON(status)
}
}
// Usage in main.go
app.Get("/health", middleware.HealthMiddleware(map[string]func() error{
"database": func() error { return db.Ping(ctx) },
"cache": func() error { return redisClient.Ping(ctx).Err() },
}))
Setting Up Vigilmon
- Sign up at vigilmon.online
- Click Add Monitor
-
URL:
https://your-fiber-app.com/health - Type: HTTP/HTTPS
- Expected Status: 200
- Interval: 1 minute
- Alerts: Email + Slack
Deploy Fiber to Production
Docker
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main .
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
EXPOSE 3000
CMD ["./main"]
docker build -t fiber-app .
docker run -p 3000:3000 fiber-app
Railway / Fly.io
Deploy to Railway or Fly.io and add your deployed URL to Vigilmon.
SSL Monitoring
For production Fiber apps on HTTPS, Vigilmon monitors your SSL certificate and alerts you 14, 7, and 3 days before expiry.
Public Status Page
Go to Status Pages in Vigilmon → Create → add your Fiber app monitor. Share the status URL with your API consumers.
Conclusion
Fiber's speed and simplicity make it ideal for high-performance Go APIs. Vigilmon keeps you informed when those APIs are down. Together you get:
- 1-minute uptime checks
- SSL certificate alerts
- Dependency health verification
- Public status page
Start free at vigilmon.online.
Top comments (0)