vm_data_write
Insert metric data into the VictoriaMetrics database by specifying metrics, values, and timestamps. Optimized for efficient data storage and retrieval.
Instructions
Write data to the VM database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metric | Yes | tag of metric | |
| timestamps | Yes | Array of metric timestamps | |
| values | Yes | Array of metric values |
Implementation Reference
- src/index.js:197-235 (handler)The core handler function that sends a POST request with metric data to the VictoriaMetrics /api/v1/import endpoint, handling success (204) or error responses.async function vmMetricsDataWrite(metric, values, timestamps) { let urlStr = VM_URL if (urlStr === "") { urlStr = VM_INSERT_URL } const url = new URL(urlStr + "/api/v1/import"); const data = { "metric": metric, "values": values, "timestamps": timestamps }; const response = await fetch(url.toString(), { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); const status = response.status; if (status === 204) { return { content: [{ type: "text", text: response.text(), }], isError: false }; } else { return { content: [{ type: "text", text: response.text(), }], isError: true }; } }
- src/index.js:11-38 (schema)Defines the tool object including name, description, and inputSchema specifying required properties: metric (object), values (array of numbers), timestamps (array of numbers).const VM_DATA_WRITE_TOOL = { name: "vm_data_write", description: "Write data to the VM database", inputSchema: { type: "object", properties: { metric: { type: "object", description: "tag of metric", }, values: { type: "array", description: "Array of metric values", items: { "type": "number" }, }, timestamps: { type: "array", description: "Array of metric timestamps", items: { "type": "number" }, } }, required: ["metric", "values", "timestamps"], } };
- src/index.js:344-347 (registration)Switch case in CallToolRequestSchema handler that extracts arguments and invokes the vmMetricsDataWrite handler for the vm_data_write tool.case "vm_data_write": { const {metric, values, timestamps} = request.params.arguments; return await vmMetricsDataWrite(metric, values, timestamps); }
- src/index.js:127-134 (registration)Registers the VM_DATA_WRITE_TOOL in the VM_TOOLS array returned by ListToolsRequestSchema handler.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 ];