Skip to main content
Glama

prom_alert_rules

View and monitor all Prometheus alert rules with their current status to manage infrastructure alerts effectively.

Instructions

List all Prometheus alert rules and their current state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The implementation of the `alertRules` function, which fetches and formats Prometheus alert rules.
    export async function alertRules(): Promise<string> {
      const url = `${config.prometheusUrl}/api/v1/rules`;
      const res = await fetch(url);
      if (!res.ok) throw new Error(`Failed to fetch rules: ${res.status}`);
    
      const data = (await res.json()) as { data: { groups: Array<{ name: string; interval: string; rules: Array<{ type: string; name: string; state: string; labels: Record<string, string>; alerts: unknown[] }> }> } };
      const groups = data.data?.groups || [];
    
      const lines: string[] = ["Alert rules:"];
    
      for (const group of groups) {
        lines.push(`\nGroup: ${group.name} (interval: ${group.interval})`);
        const rules = (group.rules || []).filter((r: { type: string }) => r.type === "alerting");
    
        if (rules.length === 0) continue;
    
        const headers = ["RULE", "STATE", "SEVERITY", "ACTIVE"];
        const rows = rules.map((r: { name: string; state: string; labels: Record<string, string>; alerts: unknown[] }) => [
          r.name,
          r.state,
          r.labels?.severity || "N/A",
          String(r.alerts?.length || 0),
        ]);
        lines.push(formatTable(headers, rows));
      }
    
      return lines.join("\n");
    }
  • The registration definition for the "prom_alert_rules" tool.
      name: "prom_alert_rules",
      description: "List all Prometheus alert rules and their current state",
      inputSchema: { type: "object" as const, properties: {} },
    },
  • The switch case in handlePrometheusTool that calls the alertRules implementation.
    case "prom_alert_rules": return alertRules();

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