stop_monitor
Terminate a persistent monitoring process for Valkey or Redis instances to stop ongoing observability data collection.
Instructions
Stop a persistent BetterDB monitor process that was previously started with start_monitor or --autostart --persist.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- packages/mcp/src/autostart.ts:157-189 (handler)The implementation of the stopMonitor function, which checks for the monitor PID file, kills the process if it's running, and cleans up the PID file.
export async function stopMonitor(): Promise<{ stopped: boolean; message: string }> { if (!fs.existsSync(PID_FILE)) { return { stopped: false, message: 'No persisted monitor found.' }; } const pid = readValidPid(PID_FILE); if (pid === null) { try { fs.unlinkSync(PID_FILE); } catch { /* ignore */ } return { stopped: true, message: 'Removed corrupted PID file.' }; } let wasRunning = false; try { process.kill(pid, 0); wasRunning = true; process.kill(pid, 'SIGTERM'); } catch { // Process not running — stale PID file } if (wasRunning) { // Wait for process to actually exit (up to 5s) const deadline = Date.now() + 5_000; while (Date.now() < deadline) { try { process.kill(pid, 0); } catch { break; } await new Promise(resolve => setTimeout(resolve, 250)); } } try { fs.unlinkSync(PID_FILE); } catch { /* already removed */ } return wasRunning ? { stopped: true, message: `Stopped monitor (PID ${pid}).` } : { stopped: true, message: `Removed stale PID file (process ${pid} was not running).` }; }