- Fix 24-bar history rendering to always show 24 uniform segments with gray fill for missing hours - Add lifetime uptime % and avg latency to status API - Add clickable detail modal with expanded stats, large history bar, and service removal - Add monitored_services DB table with CRUD API (GET/POST/DELETE) - Monitor reads services from DB each interval, seeds defaults on first run - Add inline form to add custom services to track - Extend log retention from 7 days to 90 days for lifetime stats Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import sqlite3 from 'sqlite3';
|
|
import { open, Database } from 'sqlite';
|
|
|
|
let db: Database | null = null;
|
|
|
|
export async function getDb() {
|
|
if (db) return db;
|
|
|
|
// Enable verbose mode for debugging
|
|
sqlite3.verbose();
|
|
|
|
const dbPath = process.env.DB_PATH || './dashboard.db';
|
|
|
|
db = await open({
|
|
filename: dbPath,
|
|
driver: sqlite3.Database
|
|
});
|
|
|
|
await db.exec(`
|
|
CREATE TABLE IF NOT EXISTS uptime_logs (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
service_name TEXT NOT NULL,
|
|
url TEXT NOT NULL,
|
|
status TEXT NOT NULL,
|
|
latency INTEGER,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS visitors (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
ip_hash TEXT,
|
|
city TEXT,
|
|
country TEXT,
|
|
lat REAL,
|
|
lon REAL,
|
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS monitored_services (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL UNIQUE,
|
|
url TEXT NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
`);
|
|
|
|
return db;
|
|
}
|