MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / run

Function run

apps/web/src/scripts/monitor-pg-activity.ts:72–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70}
71
72async 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
106run().catch(error => {
107 console.error('❌ Fatal error:', error);

Callers 1

Calls 5

ensureLogDirectoryFunction · 0.85
monitorActivityFunction · 0.85
logMethod · 0.65
endMethod · 0.65
onMethod · 0.45

Tested by

no test coverage detected