Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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)}`;
    }
  • 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: {} },
    },
  • The mapping of 'prom_targets' to the scrapeTargets handler in handlePrometheusTool.
    case "prom_targets": return scrapeTargets();

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/batu-sonmez/infraclaude'

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