()
| 70 | } |
| 71 | |
| 72 | async function run(): Promise<void> { |
| 73 | console.log('🚀 Starting PostgreSQL activity monitor'); |
| 74 | console.log(`📍 Log directory: ${LOG_DIR}`); |
| 75 | console.log(`⏱️ Interval: ${INTERVAL_MS / 1000} seconds`); |
| 76 | console.log(`🔔 Alert threshold: ${ALERT_THRESHOLD} connections`); |
| 77 | console.log(`🎵 Alert sound: ${SOUND_FILE}`); |
| 78 | console.log('Press Ctrl+C to stop\n'); |
| 79 | |
| 80 | await ensureLogDirectory(); |
| 81 | |
| 82 | // Run immediately |
| 83 | await monitorActivity(); |
| 84 | |
| 85 | // Then run every 30 seconds |
| 86 | const intervalId = setInterval(monitorActivity, INTERVAL_MS); |
| 87 | |
| 88 | // Handle graceful shutdown |
| 89 | process.on('SIGINT', async () => { |
| 90 | console.log('\n\n🛑 Received SIGINT, shutting down...'); |
| 91 | clearInterval(intervalId); |
| 92 | await pool.end(); |
| 93 | console.log('✅ Connection pool closed'); |
| 94 | process.exit(0); |
| 95 | }); |
| 96 | |
| 97 | process.on('SIGTERM', async () => { |
| 98 | console.log('\n\n🛑 Received SIGTERM, shutting down...'); |
| 99 | clearInterval(intervalId); |
| 100 | await pool.end(); |
| 101 | console.log('✅ Connection pool closed'); |
| 102 | process.exit(0); |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | run().catch(error => { |
| 107 | console.error('❌ Fatal error:', error); |
no test coverage detected