How to Monitor Your Turso Database with Vigilmon
Turso is a distributed SQLite database platform built on libSQL, popular with edge-first and serverless applications. While Turso handles database replication and availability internally, your application layer can still fail when Turso is unreachable. Vigilmon helps you monitor your application's ability to reach and query Turso, alerting you when the connection breaks.
Why Monitor Turso?
- Edge replication delays can cause stale reads
- API endpoint changes in Turso can break your app
- Authentication token expiry cutting off database access
- Application-layer failures when Turso is fine but your app can't reach it
- Embedded replica sync failures in edge deployments
Step 1: Create a Health Check That Queries Turso
Create an endpoint in your application that performs a lightweight Turso query:
Node.js / Next.js
// app/api/health/route.js (Next.js App Router)
import { createClient } from '@libsql/client';
export async function GET() {
const client = createClient({
url: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
try {
const result = await client.execute('SELECT 1 as ok');
return Response.json({
status: 'ok',
timestamp: new Date().toISOString(),
database: 'ok',
rows: result.rows.length,
});
} catch (error) {
return Response.json({
status: 'error',
database: 'error',
message: error.message,
}, { status: 503 });
}
}
SvelteKit
// src/routes/health/+server.js
import { createClient } from '@libsql/client';
import { json } from '@sveltejs/kit';
import { TURSO_DATABASE_URL, TURSO_AUTH_TOKEN } from '$env/static/private';
export async function GET() {
const client = createClient({
url: TURSO_DATABASE_URL,
authToken: TURSO_AUTH_TOKEN,
});
try {
await client.execute('SELECT 1');
return json({ status: 'ok', database: 'turso' });
} catch (err) {
return json({ status: 'error', message: err.message }, { status: 503 });
}
}
Hono (Cloudflare Workers)
import { Hono } from 'hono';
import { createClient } from '@libsql/client/web';
const app = new Hono();
app.get('/health', async (c) => {
const client = createClient({
url: c.env.TURSO_DATABASE_URL,
authToken: c.env.TURSO_AUTH_TOKEN,
});
try {
await client.execute('SELECT 1');
return c.json({ status: 'ok', database: 'turso' });
} catch (err) {
return c.json({ status: 'error' }, 503);
}
});
export default app;
Step 2: Configure Vigilmon
- Sign in at vigilmon.online
- Click New Monitor
- Set:
-
URL:
https://your-app.com/health - Expected status: 200
- Interval: 1 minute
-
URL:
- Add Slack/email alerts
- Save
Step 3: Monitor the Turso API Directly
Turso exposes an HTTP API you can monitor directly:
GET https://[db-name]-[org-name].turso.io/v1/query
Authorization: Bearer [your-token]
However, this requires passing your auth token in the request — better to route through your application's health endpoint.
Step 4: Embedded Replicas (Edge Monitoring)
For apps using Turso embedded replicas:
const client = createClient({
url: 'file:local.db',
syncUrl: process.env.TURSO_DATABASE_URL,
authToken: process.env.TURSO_AUTH_TOKEN,
});
// In health check
try {
await client.sync(); // Force sync check
const result = await client.execute('SELECT 1');
return { status: 'ok', sync: 'ok' };
} catch (err) {
return { status: 'error', sync: 'failed' };
}
Conclusion
Turso's distributed SQLite architecture is resilient, but your application layer needs monitoring too. Vigilmon catches the moment your app can't reach its database and alerts you immediately. Free tier included.
Top comments (0)