get_metric_data_for_host
Retrieve metric timeslice data for a specific host in New Relic applications using REST v2 queries to monitor performance and analyze system behavior.
Instructions
Get metric timeslices for metrics on a host (REST v2).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| application_id | Yes | ||
| host_id | Yes | ||
| names | Yes | ||
| values | No | ||
| from | No | ||
| to | No | ||
| period | No | ||
| summarize | No | ||
| page | No | ||
| auto_paginate | No | ||
| region | No |
Implementation Reference
- src/tools/rest/metrics.ts:110-137 (handler)The handler function that implements the core logic for fetching metric timeslices data for a host via New Relic REST API v2, supporting pagination and query parameters.async getMetricData(args: GetMetricDataArgs): Promise<unknown> { const client = this.restFor(args.region); const path = `/applications/${args.application_id}/hosts/${args.host_id}/metrics/data`; const query: Record<string, unknown> = { names: args.names, values: args.values }; if (args.from) query.from = args.from; if (args.to) query.to = args.to; if (args.period) query.period = args.period; if (args.summarize !== undefined) query.summarize = args.summarize; if (args.page) query.page = args.page; const results: unknown[] = []; let nextUrl: string | undefined; let page = args.page; do { const res = await client.get<unknown>(path, page ? { ...query, page } : query); results.push(res.data); const next = res.links?.next; if (args.auto_paginate && next) { const u = new URL(next); const p = u.searchParams.get('page'); page = p ? Number(p) : undefined; nextUrl = next; } else { nextUrl = undefined; } } while (args.auto_paginate && nextUrl); return { items: args.auto_paginate ? results : results[0], page }; }
- src/tools/rest/metrics.ts:86-108 (schema)Defines the tool's metadata, description, and input schema for validation.getMetricDataTool(): Tool { return { name: 'get_metric_data_for_host', description: 'Get metric timeslices for metrics on a host (REST v2).', inputSchema: { type: 'object', properties: { application_id: { type: 'number' }, host_id: { type: 'number' }, names: { type: 'array', items: { type: 'string' } }, values: { type: 'array', items: { type: 'string' } }, from: { type: 'string' }, to: { type: 'string' }, period: { type: 'number' }, summarize: { type: 'boolean' }, page: { type: 'number' }, auto_paginate: { type: 'boolean' }, region: { type: 'string', enum: ['US', 'EU'] }, }, required: ['application_id', 'host_id', 'names'], }, }; }
- src/server.ts:85-87 (registration)Registers the tool by including its definition in the server's list of available tools.restMetrics.getListMetricNamesTool(), restMetrics.getMetricDataTool(), restMetrics.getListApplicationHostsTool(),
- src/server.ts:195-198 (registration)Registers the execution handler in the server's tool dispatcher switch statement.case 'get_metric_data_for_host': return await new RestMetricsTool().getMetricData( args as Parameters<RestMetricsTool['getMetricData']>[0] );
- src/tools/rest/metrics.ts:13-25 (schema)TypeScript type definition for the tool's input arguments, aligning with the inputSchema.type GetMetricDataArgs = { application_id: number; host_id: number; names: string[]; values?: string[]; from?: string; to?: string; period?: number; summarize?: boolean; page?: number; auto_paginate?: boolean; region?: Region; };