UNPKG

openclaw-grafana-lens

Version:

OpenClaw plugin that gives AI agents full Grafana access — 18 composable tools for PromQL/LogQL/TraceQL queries, dashboard creation, alerting, SRE investigation, security monitoring, data collection pipeline management via Grafana Alloy (29 recipes), and

56 lines (55 loc) 2.3 kB
/** * Health context for well-known OpenClaw metrics. * * When grafana_query returns a value for a known metric, this module * provides SRE-grade interpretive context: status, thresholds, and * a human-readable description. This lets the agent act as a virtual * SRE without memorizing operational thresholds. * * Thresholds are defined in the shared metric-definitions registry * (src/metric-definitions.ts) — single source of truth. */ import { type HealthDirection } from "../metric-definitions.js"; export type HealthStatus = "healthy" | "warning" | "critical"; export type { HealthDirection } from "../metric-definitions.js"; export interface HealthContext { status: HealthStatus; thresholds: { warning: number; critical: number; }; description: string; direction: HealthDirection; } interface HealthRule { warning: number; critical: number; description: string; direction: HealthDirection; } /** * Extract a plain metric name from a PromQL expression. * Returns the name only for simple expressions (bare metric name, * optionally with label selectors). Complex expressions (rate, sum, * binary operators) return undefined — health context doesn't apply. */ export declare function extractMetricName(expr: string): string | undefined; /** * Resolve the health rule for a PromQL expression, if the metric is well-known. * Extracts the plain metric name and looks up the rule once. Use this to avoid * re-parsing the same expression in a loop (e.g., per instant query result). */ export declare function getHealthRule(expr: string): HealthRule | undefined; /** * Evaluate a value against a resolved health rule. * Use with `getHealthRule()` for per-result evaluation without re-parsing expr. */ export declare function evaluateHealthContext(rule: HealthRule, value: string): HealthContext | undefined; /** * Get health context for a metric value, if the metric is well-known. * Returns undefined for unknown metrics or complex PromQL expressions. * Convenience wrapper over getHealthRule() + evaluateHealthContext(). */ export declare function getHealthContext(expr: string, value: string): HealthContext | undefined; /** Exported for testing. */ export declare const _HEALTH_RULES: Record<string, HealthRule>;