prometheus_list_targets
Retrieve and display all configured monitoring targets in Prometheus to verify active endpoints and their status.
Instructions
List all Prometheus targets
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server/tools.ts:132-140 (registration)Registration of the prometheus_list_targets tool including name, schema (EmptySchema), description, and handle function that calls PrometheusClient.listTargets()defineTool<typeof EmptySchema, TargetsResult>({ capability: "discovery", name: "prometheus_list_targets", title: "List Prometheus Targets", description: "List all Prometheus targets", inputSchema: EmptySchema, type: "readonly", handle: async (client: PrometheusClient) => client.listTargets(), }),
- src/prometheus/client.ts:239-246 (handler)Implementation of listTargets method in PrometheusClient, which makes an HTTP GET request to /api/v1/targets endpoint to retrieve all Prometheus targets.async listTargets(scrapePool?: string): Promise<TargetsResult> { const endpoint = "/api/v1/targets"; const params: Record<string, string> = {}; if (scrapePool) { params.scrapePool = scrapePool; } return this.request<TargetsResult>(endpoint, params); }
- src/prometheus/client.ts:52-92 (helper)Private request helper method that performs HTTP requests to Prometheus API endpoints, handles errors, and extracts data from responses.private async request<T>( endpoint: string, params?: Record<string, string>, ): Promise<T> { const url = new URL(endpoint, this.baseUrl); const queryParams = new URLSearchParams(params); if (queryParams) { url.search = queryParams.toString(); } logger.debug("making prometheus request", { endpoint, url }); try { const response = await fetch(url.toString(), { method: "GET", headers: this.headers, }); if (!response.ok) { const error = `http ${response.status}: ${response.statusText}`; logger.error(error, { endpoint, status: response.status }); throw new Error(error); } const result: Response<T> = await response.json(); if (result.status !== "success") { const errorMsg = result.error || "unknown error"; const error = `prometheus api error: ${errorMsg}`; logger.error(error, { endpoint, status: result.status }); throw new Error(error); } logger.debug("prometheus request successful", { endpoint }); return result.data; } catch (error) { logger.error("prometheus request failed", { endpoint, error: error instanceof Error ? error.message : String(error), }); throw error; }