prom_instant_query
Execute PromQL instant queries to retrieve current metric values from Prometheus monitoring systems for infrastructure analysis and troubleshooting.
Instructions
Execute a PromQL instant query and return current values
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | PromQL query expression |
Implementation Reference
- src/tools/prometheus/query.ts:4-27 (handler)The `instantQuery` function implements the core logic for the "prom_instant_query" tool, executing the PromQL query against the Prometheus API.
export async function instantQuery(args: Record<string, unknown>): Promise<string> { const query = args.query as string; if (!query) throw new Error("PromQL query is required"); const url = `${config.prometheusUrl}/api/v1/query?query=${encodeURIComponent(query)}`; const res = await fetch(url); if (!res.ok) throw new Error(`Prometheus query failed: ${res.status} ${res.statusText}`); const data = (await res.json()) as { status: string; error?: string; data: { result: Array<{ metric: Record<string, string>; value: [number, string] }> } }; if (data.status !== "success") throw new Error(`Query error: ${data.error || "unknown"}`); const results = data.data.result || []; if (results.length === 0) return `No results for query: ${query}`; const headers = ["METRIC", "VALUE"]; const rows = results.map((r) => { const labels = Object.entries(r.metric) .map(([k, v]) => `${k}="${v}"`) .join(", "); return [labels || "{}", r.value[1]]; }); return `Query: ${query}\n\n${formatTable(headers, rows)}`; } - src/tools/prometheus/index.ts:7-17 (registration)The tool definition (name, description, inputSchema) for "prom_instant_query" is registered here.
{ name: "prom_instant_query", description: "Execute a PromQL instant query and return current values", inputSchema: { type: "object" as const, properties: { query: { type: "string", description: "PromQL query expression" }, }, required: ["query"], }, }, - src/tools/prometheus/index.ts:55-56 (handler)The `handlePrometheusTool` function routes the "prom_instant_query" request to the `instantQuery` function.
switch (name) { case "prom_instant_query": return instantQuery(a);