haproxy_stats
Retrieve HAProxy statistics for monitoring and optimizing load balancing performance on the OPNSense MCP Server. Supports efficient management of network traffic and firewall configurations.
Instructions
Get HAProxy statistics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Type definition (schema) for HAProxy statistics data structure.export interface HAProxyStats { frontends: { [name: string]: { status: string; sessions: number; bytesIn: number; bytesOut: number; requestRate: number; errorRate: number; }; }; backends: { [name: string]: { status: string; activeServers: number; backupServers: number; sessions: number; queuedRequests: number; health: { [serverName: string]: { status: 'up' | 'down' | 'maint'; lastCheck: string; weight: number; checksPassed: number; checksFailed: number; }; }; }; }; }
- Core handler function that fetches HAProxy statistics from the OPNsense API endpoint '/haproxy/stats/show' and parses the response.async getStats(): Promise<HAProxyStats> { try { const response = await this.client.get('/haproxy/stats/show'); return this.parseStats(response); } catch (error) { throw new Error(`Failed to get HAProxy stats: ${error}`); } }
- Helper function to parse raw HAProxy stats data into the structured HAProxyStats format.private parseStats(data: any): HAProxyStats { const stats: HAProxyStats = { frontends: {}, backends: {} }; // Parse the stats data from HAProxy // This would need to be implemented based on the actual response format // For now, returning a basic structure if (data.stats) { // Parse frontend stats if (data.stats.frontends) { for (const [name, frontendData] of Object.entries(data.stats.frontends)) { stats.frontends[name] = { status: (frontendData as any).status || 'unknown', sessions: (frontendData as any).scur || 0, bytesIn: (frontendData as any).bin || 0, bytesOut: (frontendData as any).bout || 0, requestRate: (frontendData as any).req_rate || 0, errorRate: (frontendData as any).ereq || 0 }; } } // Parse backend stats if (data.stats.backends) { for (const [name, backendData] of Object.entries(data.stats.backends)) { const backend = backendData as any; stats.backends[name] = { status: backend.status || 'unknown', activeServers: backend.act || 0, backupServers: backend.bck || 0, sessions: backend.scur || 0, queuedRequests: backend.qcur || 0, health: {} }; // Parse server health if (backend.servers) { for (const [serverName, serverData] of Object.entries(backend.servers)) { const server = serverData as any; stats.backends[name].health[serverName] = { status: server.status === 'UP' ? 'up' : server.status === 'DOWN' ? 'down' : 'maint', lastCheck: server.check_status || '', weight: server.weight || 0, checksPassed: server.chkpass || 0, checksFailed: server.chkfail || 0 }; } } } } } return stats; }