feat: add SSH metrics collection with ssh2 library and auto-scheduler
Replace sshpass with ssh2 Node.js library for reliable SSH connections. Add all 6 servers (CWP, EasyPanel, MCP Hub, Meet, WhatsApp, WhatSMS). Add 5-minute auto-collection scheduler in production mode. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import diagnosticRouter from './routes/diagnostic.js'
|
||||
import hetznerRouter from './routes/hetzner.js'
|
||||
import wpMonitorRouter from './routes/wp-monitor.js'
|
||||
import serverMetricsRouter from './routes/server-metrics.js'
|
||||
import { collectAllServerMetrics } from './services/server-metrics.js'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
@@ -65,10 +66,29 @@ app.use((err: any, _req: express.Request, res: express.Response, _next: express.
|
||||
// Start server
|
||||
app.listen(PORT, () => {
|
||||
console.log('='.repeat(50))
|
||||
console.log(`🚀 API Server running on http://localhost:${PORT}`)
|
||||
console.log(`📊 Dashboard: http://localhost:${PORT}/api/dashboard`)
|
||||
console.log(`🔍 Monitor: http://localhost:${PORT}/api/monitor`)
|
||||
console.log(`🔧 Diagnostic: http://localhost:${PORT}/api/diagnostic`)
|
||||
console.log(`☁️ Hetzner: http://localhost:${PORT}/api/hetzner`)
|
||||
console.log(`API Server running on http://localhost:${PORT}`)
|
||||
console.log(`Dashboard: http://localhost:${PORT}/api/dashboard`)
|
||||
console.log(`Monitor: http://localhost:${PORT}/api/monitor`)
|
||||
console.log(`Hetzner: http://localhost:${PORT}/api/hetzner`)
|
||||
console.log('='.repeat(50))
|
||||
|
||||
// Auto-collect server metrics every 5 minutes
|
||||
if (isProduction) {
|
||||
const INTERVAL = 5 * 60 * 1000
|
||||
console.log('[SCHEDULER] Server metrics collection every 5min')
|
||||
|
||||
// Initial collection after 30s (let server stabilize)
|
||||
setTimeout(() => {
|
||||
collectAllServerMetrics().catch(err =>
|
||||
console.error('[SCHEDULER] Initial collection failed:', err)
|
||||
)
|
||||
}, 30000)
|
||||
|
||||
// Recurring collection
|
||||
setInterval(() => {
|
||||
collectAllServerMetrics().catch(err =>
|
||||
console.error('[SCHEDULER] Collection failed:', err)
|
||||
)
|
||||
}, INTERVAL)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user