vm_data_write
Write time-series data to VictoriaMetrics database by specifying metrics, values, and timestamps for storage and analysis.
Instructions
Write data to the VM database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metric | Yes | tag of metric | |
| values | Yes | Array of metric values | |
| timestamps | Yes | Array of metric timestamps |
Implementation Reference
- src/index.js:197-235 (handler)Core handler function that performs the HTTP POST request to VictoriaMetrics /api/v1/import endpoint with the provided metric, values, and timestamps, returning success or error content.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 schema including name, description, and input schema with 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:127-134 (registration)Registers the vm_data_write tool (as VM_DATA_WRITE_TOOL) in the VM_TOOLS array, which is returned by the 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 ];
- src/index.js:344-347 (handler)Switch case in CallToolRequestSchema handler that destructures arguments and invokes the vmMetricsDataWrite handler function.case "vm_data_write": { const {metric, values, timestamps} = request.params.arguments; return await vmMetricsDataWrite(metric, values, timestamps); }