DEV Community

Vigilmon
Vigilmon

Posted on

How to Monitor SQLite Databases with Vigilmon

How to Monitor SQLite Databases with Vigilmon

SQLite is the world's most widely deployed database — embedded in mobile apps, IoT devices, edge servers, and many web applications. Unlike PostgreSQL or MySQL, SQLite doesn't have a network interface, so traditional database monitors don't apply. But that doesn't mean you can't monitor it effectively.

This guide shows how to monitor SQLite-backed applications using Vigilmon.


Monitoring SQLite: A Different Approach

Since SQLite is a file-based embedded database with no network port, you monitor:

  1. The application that uses SQLite (HTTP health endpoints)
  2. Application-level database checks (can the app query its own DB?)
  3. Background job liveness (for write-intensive cron jobs)
  4. Disk space (SQLite databases can grow unexpectedly)

Step 1: Add a Database Health Check to Your App

Node.js (with better-sqlite3)

// healthcheck.js
const Database = require('better-sqlite3');
const express = require('express');

const app = express();
const db = new Database('./app.db');

app.get('/health', (req, res) => {
  try {
    // Quick query to verify DB is accessible
    const result = db.prepare('SELECT 1 AS ok').get();
    res.json({ status: 'ok', db: 'ok', timestamp: Date.now() });
  } catch (err) {
    res.status(503).json({ status: 'error', db: 'error', error: err.message });
  }
});

app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

Python (with sqlite3)

# healthcheck.py (Flask example)
import sqlite3
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/health')
def health():
    try:
        conn = sqlite3.connect('./app.db')
        conn.execute('SELECT 1')
        conn.close()
        return jsonify({'status': 'ok', 'db': 'ok'})
    except Exception as e:
        return jsonify({'status': 'error', 'db': str(e)}), 503
Enter fullscreen mode Exit fullscreen mode

Go (with modernc.org/sqlite)

// healthcheck.go
func healthHandler(db *sql.DB) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        if err := db.Ping(); err != nil {
            w.WriteHeader(http.StatusServiceUnavailable)
            json.NewEncoder(w).Encode(map[string]string{"status": "error"})
            return
        }
        json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 2: Monitor Disk Space

SQLite databases are just files. A full disk = database write failures. Use a lightweight script as a heartbeat:

#!/bin/bash
# check-sqlite-disk.sh — run every 5 minutes via cron

DB_FILE="/var/app/app.db"
VIGILMON_HB="https://hb.vigilmon.online/your-heartbeat-id"

# Check if file exists
if [ ! -f "$DB_FILE" ]; then
    echo "ERROR: SQLite database file missing!"
    exit 1
fi

# Check disk usage (alert if > 80%)
DISK_USED=$(df "$DB_FILE" | tail -1 | awk '{print $5}' | tr -d '%')
if [ "$DISK_USED" -lt 80 ]; then
    curl -s "$VIGILMON_HB" > /dev/null
fi

# Log DB file size
DB_SIZE=$(du -h "$DB_FILE" | cut -f1)
echo "DB size: $DB_SIZE, Disk used: ${DISK_USED}%"
Enter fullscreen mode Exit fullscreen mode
# crontab -e
*/5 * * * * /var/app/check-sqlite-disk.sh
Enter fullscreen mode Exit fullscreen mode

Step 3: Register in Vigilmon

  1. Sign up at vigilmon.online
  2. Add an HTTP monitor for your app's /health endpoint
  3. Set the keyword check to look for "status":"ok" and "db":"ok"
  4. Add a heartbeat monitor for your disk-check script

SQLite-Specific Failure Modes to Monitor

Failure Symptom Monitor
Database file locked 503 from app HTTP health check
Disk full Writes fail silently Disk heartbeat
Corrupted DB Queries return errors HTTP health check
WAL file too large Slow queries Response time monitor
App crash No response HTTP availability

Turso (Distributed SQLite)

If you're using Turso (distributed SQLite), Vigilmon can monitor your Turso HTTP API endpoint:

https://your-db.turso.io/v2/pipeline
Enter fullscreen mode Exit fullscreen mode

Add this as an HTTP monitor with a POST body containing a simple SQL query.


Conclusion

SQLite monitoring is about monitoring what SQLite does: serving your application and writing to disk. With Vigilmon's HTTP and heartbeat monitors, you get full visibility into your SQLite-backed application's health.

Start monitoring your SQLite app for free at vigilmon.online

Top comments (0)