feat: automated backup and production monitoring
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
d7d04eb2d7
commit
69601cce3a
@@ -2,6 +2,7 @@ import { Hono } from 'hono'
|
||||
import { db, schema, sqlite } from '../db/index.js'
|
||||
import { eq, desc, sql, count } from 'drizzle-orm'
|
||||
import { getActiveSSECount } from './fights.js'
|
||||
import { createBackup } from '../engine/backup.js'
|
||||
|
||||
const CREATOR_PUBKEY = 'da5e0c1b646bdb13c2300f805b0ca3e5afe5b052c594ce78bac8978d21c3fa39'
|
||||
const startTime = Date.now()
|
||||
@@ -30,6 +31,8 @@ adminRouter.get('/stats', async (c) => {
|
||||
const totalFights = await db.select({ count: count() }).from(schema.fights)
|
||||
const totalSats = await db.select({ total: sql<number>`coalesce(sum(${schema.fights.potSats}), 0)` }).from(schema.fights)
|
||||
|
||||
const rssMB = Math.round(mem.rss / 1024 / 1024)
|
||||
|
||||
return c.json({
|
||||
uptime: Math.round((Date.now() - startTime) / 1000),
|
||||
rssBytes: mem.rss,
|
||||
@@ -41,6 +44,10 @@ adminRouter.get('/stats', async (c) => {
|
||||
totalBots: totalBots[0]?.count || 0,
|
||||
totalFights: totalFights[0]?.count || 0,
|
||||
totalSatsMoved: totalSats[0]?.total || 0,
|
||||
alerts: {
|
||||
memoryWarning: rssMB > 200,
|
||||
memoryCritical: rssMB > 300,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
@@ -105,3 +112,14 @@ adminRouter.get('/fights', async (c) => {
|
||||
|
||||
return c.json({ fights })
|
||||
})
|
||||
|
||||
// GET /backup — trigger manual backup
|
||||
adminRouter.get('/backup', (c) => {
|
||||
try {
|
||||
const path = createBackup()
|
||||
return c.json({ ok: true, path })
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : 'Backup failed'
|
||||
return c.json({ error: msg }, 500)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user