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
66 lines (65 loc) • 3.5 kB
TypeScript
/**
* Shared metric definitions — single source of truth for all openclaw_lens_* metrics.
*
* This module is consumed by:
* - metrics-collector.ts → OTel instrument name + description for meter.create*()
* - list-metrics.ts → Prometheus name + type + help for OTLP metadata fallback
* - explain-metric.ts → labels for drill-down breakdown suggestions
* - health-context.ts → thresholds for SRE health evaluation
*
* Adding a new metric? Add it here and all four consumers pick it up automatically.
*
* Naming conventions:
* - OTel name: `openclaw_lens_<name>` (no _total suffix for counters)
* - Prometheus name: derived automatically — counters get `_total`, histograms expose _bucket/_count/_sum
* - Gauges: as-is
*/
/** Direction for health threshold evaluation. Canonical definition — re-exported by health-context.ts. */
export type HealthDirection = "higher_is_worse" | "lower_is_worse";
/** Prometheus metric type (matches OTel instrument type mapped to Prometheus conventions). */
export type PrometheusMetricType = "counter" | "gauge" | "histogram" | "unknown";
/** OTel instrument kind — determines how the instrument is created in metrics-collector. */
export type OtelInstrumentKind = "counter" | "histogram" | "updown_counter" | "observable_gauge";
export interface MetricDefinition {
/** OTel instrument name (no _total suffix — OTel SDK appends it for counters in Prometheus export). */
readonly otelName: string;
/** Human-readable description (used as both OTel description and Prometheus HELP). */
readonly help: string;
/** OTel instrument kind. */
readonly instrument: OtelInstrumentKind;
/** Known label keys for drill-down suggestions (ordered by analytical importance). */
readonly labels?: readonly string[];
/** SRE health thresholds (only for gauge-type metrics). */
readonly health?: {
readonly warning: number;
readonly critical: number;
readonly direction: HealthDirection;
/** Optional SRE-oriented description (richer than `help`). Falls back to `help` if omitted. */
readonly description?: string;
};
}
/** Derive the Prometheus metric type from the OTel instrument kind. */
export declare function prometheusType(kind: OtelInstrumentKind): PrometheusMetricType;
/**
* Derive the Prometheus metric name from the OTel instrument name and kind.
* Counters get `_total` appended (OTel→Prometheus convention).
* Histograms and gauges keep their name as-is.
*/
export declare function prometheusName(def: MetricDefinition): string;
export declare const METRIC_DEFINITIONS: readonly MetricDefinition[];
/** Prometheus name → { type, help } — used by list-metrics.ts OTLP fallback. */
export declare const KNOWN_METRICS_MAP: ReadonlyMap<string, {
type: PrometheusMetricType;
help: string;
}>;
/** Prometheus name → string[] — used by explain-metric.ts for drill-down labels. */
export declare const KNOWN_BREAKDOWNS_MAP: Readonly<Record<string, string[]>>;
/** Prometheus name → health rule — used by health-context.ts for SRE thresholds. */
export declare const HEALTH_RULES_MAP: Readonly<Record<string, {
warning: number;
critical: number;
description: string;
direction: HealthDirection;
}>>;
/** OTel name → MetricDefinition — used by metrics-collector.ts for instrument creation. */
export declare const DEFINITIONS_BY_OTEL_NAME: ReadonlyMap<string, MetricDefinition>;