prom_targets
Monitor Prometheus scrape target health status to identify infrastructure monitoring issues and ensure reliable metrics collection.
Instructions
Show Prometheus scrape target health status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/prometheus/targets.ts:4-34 (handler)The scrapeTargets function fetches target health information from the Prometheus API and formats it into a table.
export async function scrapeTargets(): Promise<string> { const url = `${config.prometheusUrl}/api/v1/targets`; const res = await fetch(url); if (!res.ok) throw new Error(`Failed to fetch targets: ${res.status}`); interface Target { labels: Record<string, string>; scrapeUrl: string; health: string; lastScrape: string; lastError: string; } const data = (await res.json()) as { data: { activeTargets: Target[] } }; const activeTargets = data.data?.activeTargets || []; if (activeTargets.length === 0) return "No active scrape targets found."; const headers = ["JOB", "ENDPOINT", "STATE", "LAST SCRAPE", "ERROR"]; const rows = activeTargets.map((t: { labels: Record<string, string>; scrapeUrl: string; health: string; lastScrape: string; lastError: string; }) => [ t.labels.job || "unknown", t.scrapeUrl, t.health, t.lastScrape ? new Date(t.lastScrape).toLocaleTimeString() : "N/A", (t.lastError || "").substring(0, 40), ]); const healthy = activeTargets.filter((t: { health: string }) => t.health === "up").length; const total = activeTargets.length; return `Scrape targets (${healthy}/${total} healthy):\n\n${formatTable(headers, rows)}`; } - src/tools/prometheus/index.ts:43-46 (registration)The definition of the 'prom_targets' tool in the registerPrometheusTools function.
name: "prom_targets", description: "Show Prometheus scrape target health status", inputSchema: { type: "object" as const, properties: {} }, }, - src/tools/prometheus/index.ts:60-60 (handler)The mapping of 'prom_targets' to the scrapeTargets handler in handlePrometheusTool.
case "prom_targets": return scrapeTargets();