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

92 lines (91 loc) 3.34 kB
/** * grafana_list_metrics tool * * Discovers available metrics (or label values) from a Prometheus datasource. * Helps the agent understand what data exists before querying or building * dashboards — "what can I track?" gets answered here. */ import type { GrafanaClientRegistry } from "../grafana-client-registry.js"; import type { CustomMetricsStore } from "../services/custom-metrics-store.js"; import { type PrometheusMetricType } from "../metric-definitions.js"; export type { PrometheusMetricType } from "../metric-definitions.js"; /** * Known metrics map — derived from the shared metric-definitions registry. * Re-exported so existing consumers (tests, deduplicateAndEnrich) continue to work. */ export declare const KNOWN_LENS_METRICS: ReadonlyMap<string, { type: PrometheusMetricType; help: string; }>; /** * Deduplicate histogram sub-metrics and synthesize metadata entries from * metric names + the known-metrics registry. Histogram _bucket/_count/_sum * variants are coalesced into a single base-name entry with type "histogram". */ export declare function deduplicateAndEnrich(names: string[]): Array<{ name: string; type: PrometheusMetricType; help: string; category?: MetricCategory; source: string; }>; export type MetricCategory = "cost" | "usage" | "session" | "queue" | "messaging" | "webhook" | "tools" | "agent" | "custom"; export type MetricPurpose = "performance" | "cost" | "reliability" | "capacity"; /** * Maps a high-level purpose to the metric categories that serve it. * Agents say "show me performance metrics" → we filter to session + tools categories. */ export declare const PURPOSE_CATEGORIES: Record<MetricPurpose, ReadonlySet<MetricCategory>>; /** * Categorize a metric name by functional area. * Returns the category for `openclaw_*` metrics, or `undefined` for non-openclaw metrics. * `openclaw_ext_*` metrics are always categorized as `"custom"`. */ export declare function categorizeMetric(name: string): MetricCategory | undefined; export declare function createListMetricsToolFactory(registry: GrafanaClientRegistry, getCustomMetricsStore?: () => CustomMetricsStore | null): (_ctx: unknown) => { name: string; label: string; description: string; parameters: { type: "object"; properties: { datasourceUid: { type: string; description: string; }; prefix: { type: string; description: string; }; search: { type: string; description: string; }; label: { type: string; description: string; }; metadata: { type: string; description: string; }; purpose: { type: string; enum: string[]; description: string; }; compact: { type: string; description: string; }; }; required: string[]; }; execute(_toolCallId: string, params: Record<string, unknown>): Promise<{ content: Array<{ type: "text"; text: string; }>; details: unknown; }>; };