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
39 lines (38 loc) • 2.07 kB
TypeScript
/**
* Metrics Collector Service
*
* Subscribes to OpenClaw diagnostic events and converts them to OpenTelemetry
* signals pushed via OTLP to the configured collector (LGTM stack, Grafana Cloud, etc.).
*
* Three pillars, one handler:
* - Metrics: operational gauges (sessions, cost, context, queues) → Mimir → Grafana dashboards
* - Logs: verbose structured log records for ALL events → Loki → Grafana Explore
* - Traces: agent lifecycle spans (model calls, messages, webhooks) → Tempo → Grafana Explore
*
* Log-to-trace correlation: span-producing events include trace_id in the log record,
* enabling Grafana's "Logs to Traces" feature (click Loki log → jump to Tempo trace).
*/
import type { OpenClawPluginService } from "openclaw/plugin-sdk/core";
import { type OtelLogs } from "./otel-logs.js";
import { type OtelTraces } from "./otel-traces.js";
import { type LifecycleTelemetry } from "./lifecycle-telemetry.js";
import { type ValidatedGrafanaLensConfig } from "../config.js";
import type { AlertStore } from "./alert-webhook.js";
import { CustomMetricsStore } from "./custom-metrics-store.js";
/**
* Test-only: drain the in-flight OTel pipeline (so batch exporter timers don't
* leak across vitest runs — `BatchLogRecordProcessor` / `BatchSpanProcessor`
* intervals are not unref'd by the SDK) and drop the process-wide singleton so
* the next createMetricsCollectorService() call rebuilds from scratch.
*
* Do NOT call this from production code — it bypasses the openclaw 2026.4.24+
* re-register protection that this singleton exists to provide.
*/
export declare function __resetMetricsCollectorSingletonForTests(): Promise<void>;
export declare function createMetricsCollectorService(config: ValidatedGrafanaLensConfig, alertStore?: AlertStore, pluginVersion?: string): {
service: OpenClawPluginService;
getCustomMetricsStore: () => CustomMetricsStore | null;
getOtelTraces: () => OtelTraces | null;
getOtelLogs: () => OtelLogs | null;
getLifecycleTelemetry: () => LifecycleTelemetry | null;
};