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
43 lines (42 loc) • 1.59 kB
JavaScript
/**
* OTLP Metrics Provider
*
* Central MeterProvider lifecycle module. Creates an OpenTelemetry
* MeterProvider that pushes metrics via OTLP HTTP/JSON to the
* configured collector (LGTM stack, Grafana Cloud, Mimir, etc.).
*
* Replaces the previous prom-client pull model (/metrics endpoint).
* Data flow:
* OpenClaw diagnostic events → OTel instruments → OTLP exporter → Collector → Mimir → Grafana
*/
import { MeterProvider, PeriodicExportingMetricReader, AggregationTemporality, } from "@opentelemetry/sdk-metrics";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
import { createOtelResource } from "./otel-resource.js";
const DEFAULT_ENDPOINT = "http://localhost:4318/v1/metrics";
const DEFAULT_EXPORT_INTERVAL_MS = 15_000;
export function createOtelMetrics(config) {
const exporter = new OTLPMetricExporter({
url: config.endpoint || DEFAULT_ENDPOINT,
headers: config.headers,
temporalityPreference: AggregationTemporality.CUMULATIVE,
});
const reader = new PeriodicExportingMetricReader({
exporter,
exportIntervalMillis: config.exportIntervalMs ?? DEFAULT_EXPORT_INTERVAL_MS,
});
const resource = createOtelResource(config);
const provider = new MeterProvider({
resource,
readers: [reader],
});
const meter = provider.getMeter("grafana-lens");
return {
meter,
async forceFlush() {
await provider.forceFlush();
},
async shutdown() {
await provider.shutdown();
},
};
}