prometheus_query_range
Execute a Prometheus range query to retrieve metrics within a specified time range, with defined start, end timestamps, and step resolution for monitoring and analysis.
Instructions
Execute a Prometheus range query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | Yes | end timestamp (RFC3339 or unix timestamp) | |
| query | Yes | prometheus query expression | |
| start | Yes | start timestamp (RFC3339 or unix timestamp) | |
| step | Yes | query resolution step width |
Implementation Reference
- src/server/tools.ts:186-187 (handler)Handler function that executes the prometheus_query_range tool logic by calling client.queryRange with the provided query, start, end, and step parameters.handle: async (client: PrometheusClient, args) => client.queryRange(args.query, args.start, args.end, args.step),
- src/server/tools.ts:57-62 (schema)Zod schema defining the input parameters for the prometheus_query_range tool: query (PromQL expression), start, end (timestamps), step (resolution).const PrometheusQueryRangeSchema = z.object({ query: z.string().describe("prometheus query expression"), start: z.string().describe("start timestamp (RFC3339 or unix timestamp)"), end: z.string().describe("end timestamp (RFC3339 or unix timestamp)"), step: z.string().describe("query resolution step width"), });
- src/server/tools.ts:179-188 (registration)Registration of the prometheus_query_range tool in the tools array, specifying its capability, name, schema, and handler.defineTool<typeof PrometheusQueryRangeSchema, QueryResult>({ capability: "query", name: "prometheus_query_range", title: "Prometheus Query Range", description: "Execute a Prometheus range query", inputSchema: PrometheusQueryRangeSchema, type: "readonly", handle: async (client: PrometheusClient, args) => client.queryRange(args.query, args.start, args.end, args.step), }),
- src/prometheus/client.ts:141-150 (helper)Supporting method in PrometheusClient that performs the actual HTTP request to Prometheus /api/v1/query_range endpoint, called by the tool handler.async queryRange( query: string, start: string, end: string, step: string, ): Promise<QueryResult> { const endpoint = "/api/v1/query_range"; const params: Record<string, string> = { query, start, end, step }; return this.request<QueryResult>(endpoint, params); }