monitoring
Retrieve PostgreSQL database performance metrics, statistics, and health checks including connections, locks, replication status, and query performance.
Instructions
Database monitoring: performance metrics, statistics, health checks
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metric | Yes | Metric type to retrieve | |
| timeRange | No | Time range for metrics | 1h |
| limit | No | Maximum number of results |
Implementation Reference
- src/index.ts:1311-1372 (handler)The main execution handler for the 'monitoring' tool. Handles different metrics (connections, performance, cache, security) by delegating to various managers and returning JSON-formatted monitoring data.private async handleMonitoring(args: any) { const { metric } = args; switch (metric) { case 'connections': return { content: [{ type: 'text', text: JSON.stringify(this.dbManager.getPoolStats(), null, 2) }] }; case 'performance': const operationalStats = this.dbManager.getOperationalStats(); const performanceMetrics = this.performanceMonitor.getMetrics(); const slowOperations = this.performanceMonitor.getSlowOperations(); return { content: [{ type: 'text', text: JSON.stringify({ operational: operationalStats, performance: performanceMetrics, slowOperations, cache: this.cache.getStats() }, null, 2) }] }; case 'cache': return { content: [{ type: 'text', text: JSON.stringify({ stats: this.cache.getStats(), recent: this.cache.getRecentEntries(5), popular: this.cache.getPopularEntries(5) }, null, 2) }] }; case 'security': const rateLimitEntries = Array.from(this.rateLimiter.getAllEntries().entries()).slice(0, 10); return { content: [{ type: 'text', text: JSON.stringify({ rateLimits: rateLimitEntries, securityEvents: 'Security event logging would be implemented here' }, null, 2) }] }; default: return { content: [{ type: 'text', text: JSON.stringify({ message: `Monitoring metric '${metric}' not yet implemented` }, null, 2) }] }; } }
- src/index.ts:363-388 (schema)Input schema for the 'monitoring' tool, defining parameters such as metric (required), timeRange, and limit.{ name: 'monitoring', description: 'Database monitoring: performance metrics, statistics, health checks', inputSchema: { type: 'object', properties: { metric: { type: 'string', enum: ['connections', 'performance', 'locks', 'replication', 'disk_usage', 'query_stats', 'index_usage'], description: 'Metric type to retrieve' }, timeRange: { type: 'string', enum: ['1h', '24h', '7d', '30d'], description: 'Time range for metrics', default: '1h' }, limit: { type: 'integer', description: 'Maximum number of results', default: 50 } }, required: ['metric'] } },
- src/index.ts:633-637 (registration)Registration of all tool definitions (including 'monitoring') via ListToolsRequestSchema handler, exposing schemas to clients.// Register tool definitions this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: toolDefinitions, }));
- src/index.ts:664-666 (registration)Dispatch/registration in the CallToolRequestSchema switch statement, routing 'monitoring' tool calls to the handleMonitoring function.case 'monitoring': return await this.handleMonitoring(args);
- src/validation.ts:298-299 (helper)Tool name mappings in validation module, associating 'monitor' and 'stats' aliases with the 'monitoring' category for error suggestions.'monitor': 'monitoring', 'stats': 'monitoring',