vm_query_range
Query time series data over a specified time range using PromQL expressions to analyze historical metrics and performance trends.
Instructions
Query time series over a time range
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | PromQL expression | |
| start | No | Start timestamp in Unix seconds | |
| end | No | End timestamp in Unix seconds | |
| step | No | Query resolution step width |
Implementation Reference
- src/index.js:348-350 (handler)Switch case handler for vm_query_range tool call, extracts arguments and invokes the query range function.case "vm_query_range": { const {query, start, end, step} = request.params.arguments; return await vmDataRangeQuery(query, start, end, step);
- src/index.js:165-195 (helper)Core helper function that performs the HTTP range query to VictoriaMetrics API, handles response and formats output.async function vmDataRangeQuery(query, start, end, step) { let urlStr = VM_URL if (urlStr === "") { urlStr = VM_SELECT_URL } const url = new URL(urlStr + "/api/v1/query_range"); url.searchParams.append("query", query); url.searchParams.append("start", start ?? ""); url.searchParams.append("end", end ?? ""); url.searchParams.append("step", step ?? ""); const response = await fetch(url.toString()); const data = await response.json(); if (data.status === "success") { return { content: [{ type: "text", text: JSON.stringify(data.data), }], isError: false }; } else { return { content: [{ type: "text", text: "range query fail:" + await response.text(), }], isError: true }; } }
- src/index.js:55-80 (schema)Tool schema definition specifying name, description, and input schema for vm_query_range.const VM_QUERY_RANGE_TOOL = { name: "vm_query_range", description: "Query time series over a time range", inputSchema: { type: "object", properties: { query: { type: "string", description: "PromQL expression", }, start: { type: "number", description: "Start timestamp in Unix seconds", }, end: { type: "number", description: "End timestamp in Unix seconds", }, step: { type: "string", description: "Query resolution step width", } }, required: ["query"], } };
- src/index.js:127-134 (registration)Registration of vm_query_range tool (as VM_QUERY_RANGE_TOOL) in the list of available tools returned by ListToolsRequestHandler.const VM_TOOLS = [ VM_DATA_WRITE_TOOL, VM_QUERY_RANGE_TOOL, VM_QUERY_TOOL, VM_LABELS_TOOL, VM_LABEL_VALUES_TOOL, VM_PROMETHEUS_WRITE_TOOL ];