cribl_getSystemMetrics
Retrieve system metrics from Cribl deployment with optional filters for time range, metric names, and worker processes to narrow results and maintain performance.
Instructions
Retrieves system metrics from the Cribl deployment. IMPORTANT: To avoid excessively large responses, please use the optional parameters (filterExpr, metricNameFilter, earliest, latest, numBuckets, wp) to narrow down your query whenever possible. If no parameters are provided, the server will default to fetching only the most recent data bucket (numBuckets=1) to prevent performance issues.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filterExpr | No | Optional: A JS expression to filter metrics (e.g., "model.pipeline === 'test'" or "host == 'myhost'"). | |
| metricNameFilter | No | Optional: Regex or array of metric names (e.g.,limit to "pipe.*" , "total.in_bytes", or "os.cpu.perc,os.mem.*"). | |
| earliest | No | Optional: Start time for the query (e.g., '-15m', '2023-10-26T10:00:00Z'). | |
| latest | No | Optional: End time for the query (e.g., 'now', '2023-10-26T10:15:00Z'). | |
| numBuckets | No | Optional: The number of time buckets for aggregation. | |
| wp | No | Optional: Worker process filter. |
Implementation Reference
- src/server.ts:342-365 (registration)Registers the 'cribl_getSystemMetrics' MCP tool with the server, including description, schema, and handler callback.
server.tool( 'cribl_getSystemMetrics', 'Retrieves system metrics from the Cribl deployment. \nIMPORTANT: To avoid excessively large responses, please use the optional parameters (filterExpr, metricNameFilter, earliest, latest, numBuckets, wp) to narrow down your query whenever possible. \nIf no parameters are provided, the server will default to fetching only the most recent data bucket (numBuckets=1) to prevent performance issues.', GetSystemMetricsArgsShape, async (args: ValidatedArgs<typeof GetSystemMetricsArgsShape>) => { console.error(`[Tool Call] cribl_getSystemMetrics with args:`, args) // Pass the validated args to the API client function const result = await getSystemMetrics(args) if (!result.success || typeof result.data !== 'string') { console.error(`[Tool Error] cribl_getSystemMetrics for args ${JSON.stringify(args)}:`, result.error || 'Invalid data received') return { isError: true, content: [{ type: 'text', text: `Error fetching system metrics: ${result.error || 'Unknown error'}` }], } } console.error(`[Tool Success] cribl_getSystemMetrics: Fetched ${result.data.length} characters of metrics for args:`, args) return { content: [{ type: 'text', text: result.data }], } } ) - src/server.ts:333-340 (schema)Defines the Zod schema for input validation of the 'cribl_getSystemMetrics' tool arguments.
const GetSystemMetricsArgsShape = { filterExpr: z.string().optional().nullable().describe('Optional: A JS expression to filter metrics (e.g., "model.pipeline === \'test\'" or "host == \'myhost\'").'), metricNameFilter: z.string().optional().nullable().describe('Optional: Regex or array of metric names (e.g.,limit to "pipe.*" , "total.in_bytes", or "os.cpu.perc,os.mem.*").'), earliest: z.string().optional().nullable().describe('Optional: Start time for the query (e.g., \'-15m\', \'2023-10-26T10:00:00Z\').'), latest: z.string().optional().nullable().describe('Optional: End time for the query (e.g., \'now\', \'2023-10-26T10:15:00Z\').'), numBuckets: z.number().int().optional().nullable().describe('Optional: The number of time buckets for aggregation.'), wp: z.string().optional().nullable().describe('Optional: Worker process filter.'), } - src/server.ts:346-365 (handler)Handler function that validates args, calls getSystemMetrics API, and returns the result or error.
async (args: ValidatedArgs<typeof GetSystemMetricsArgsShape>) => { console.error(`[Tool Call] cribl_getSystemMetrics with args:`, args) // Pass the validated args to the API client function const result = await getSystemMetrics(args) if (!result.success || typeof result.data !== 'string') { console.error(`[Tool Error] cribl_getSystemMetrics for args ${JSON.stringify(args)}:`, result.error || 'Invalid data received') return { isError: true, content: [{ type: 'text', text: `Error fetching system metrics: ${result.error || 'Unknown error'}` }], } } console.error(`[Tool Success] cribl_getSystemMetrics: Fetched ${result.data.length} characters of metrics for args:`, args) return { content: [{ type: 'text', text: result.data }], } } ) - src/api/criblClient.ts:432-489 (handler)Actual API client implementation that calls GET /api/v1/system/metrics with optional query parameters, defaulting to numBuckets=1 when no params provided.
export async function getSystemMetrics( params?: { filterExpr?: string | null; metricNameFilter?: string | null; earliest?: string | null; latest?: string | null; numBuckets?: number | null; wp?: string | null; } ): Promise<ClientResult<string>> { const context = `getSystemMetrics`; const url = `/api/v1/system/metrics`; console.error(`[stderr] Attempting API call: GET ${url} with params: ${JSON.stringify(params)}`); // Prepare query parameters const queryParams: Record<string, any> = {}; if (params?.filterExpr != null) queryParams.filterExpr = params.filterExpr; if (params?.metricNameFilter != null) queryParams.metricNameFilter = params.metricNameFilter; if (params?.earliest != null) queryParams.earliest = params.earliest; if (params?.latest != null) queryParams.latest = params.latest; if (params?.wp != null) queryParams.wp = params.wp; // Default to 1 bucket if no parameters are provided to limit response size const providedParamKeys = Object.keys(params || {}).filter(k => params?.[k as keyof typeof params] !== undefined && params?.[k as keyof typeof params] !== null); if (providedParamKeys.length === 0) { queryParams.numBuckets = 1; console.error(`[stderr] No specific metrics parameters provided, defaulting to numBuckets=1`); } else if (params?.numBuckets != null) { queryParams.numBuckets = params.numBuckets; } try { const response = await apiClient.get<string>(url, { params: queryParams, headers: { ...apiClient.defaults.headers.common, 'Accept': 'text/plain' // Keep requesting plain text for now }, responseType: 'text', }); const responseDataString = typeof response.data === 'string' ? response.data : String(response.data); return { success: true, data: responseDataString }; } catch (error) { const errorMessage = handleApiError(error, context); if (axios.isAxiosError(error) && error.response?.headers?.['content-type']?.includes('text/html')) { try { const htmlError = error.response.data as string; const preMatch = htmlError.match(/<pre>([\s\S]*?)<\/pre>/i); if (preMatch && preMatch[1]) { console.error(`[stderr] Extracted HTML error detail for ${context}: ${preMatch[1]}`); } } catch (htmlParseError) { console.error(`[stderr] Failed to parse potential HTML error for ${context}: ${htmlParseError}`); } } return { success: false, error: errorMessage }; } } - src/server.ts:6-17 (helper)Import statement that brings the getSystemMetrics API client function into server.ts.
import { getPipelines, getSources, setPipelineConfig, getPipelineConfig, listWorkerGroups, restartWorkerGroup, getSystemMetrics, versionControl, commitPipeline, deployPipeline } from './api/criblClient.js';