Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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(), }),
  • 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); }
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/idanfishman/prometheus-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server