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

117 lines (116 loc) 3.67 kB
/** * Grafana Lens plugin configuration types. * * These mirror the JSON Schema in openclaw.plugin.json but provide * TypeScript types for use within the extension code. * * Config precedence: explicit plugin config > environment variables > defaults. * Env vars follow Grafana community conventions (GRAFANA_URL, GRAFANA_SERVICE_ACCOUNT_TOKEN) * and OpenTelemetry conventions (OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS). * * Supports two grafana config formats: * 1. Legacy single instance: { url, apiKey, orgId } * 2. Named instances: { instances: [{ name, url, apiKey, orgId }], default? } * Both normalize to the same internal shape: { instances: Record<name, config>, defaultInstance }. */ /** A single Grafana instance (parsed — fields may still be missing). */ export type GrafanaInstanceConfig = { url?: string; apiKey?: string; orgId?: number; }; /** A validated instance — url and apiKey confirmed present. */ export type ValidatedGrafanaInstanceConfig = { url: string; apiKey: string; orgId?: number; }; export type GrafanaLensConfig = { grafana: { instances: Record<string, GrafanaInstanceConfig>; defaultInstance: string; }; metrics?: { enabled?: boolean; }; otlp?: { endpoint?: string; headers?: Record<string, string>; exportIntervalMs?: number; instanceId?: string; logs?: boolean; traces?: boolean; captureContent?: boolean; contentMaxLength?: number; forwardAppLogs?: boolean; appLogMinSeverity?: string; redactSecrets?: boolean; }; proactive?: { enabled?: boolean; webhookPath?: string; costAlertThreshold?: number; }; customMetrics?: { enabled?: boolean; maxMetrics?: number; maxLabelsPerMetric?: number; maxLabelValues?: number; defaultTtlDays?: number; }; alloy?: { enabled?: boolean; url?: string; configDir?: string; filePrefix?: string; maxPipelines?: number; lgtm?: { prometheusRemoteWriteUrl?: string; lokiUrl?: string; otlpEndpoint?: string; pyroscopeUrl?: string; }; }; }; /** * Validated config — at least the default instance has url + apiKey. * Only instances with valid credentials are included. */ export type ValidatedGrafanaLensConfig = Omit<GrafanaLensConfig, "grafana"> & { grafana: { instances: Record<string, ValidatedGrafanaInstanceConfig>; defaultInstance: string; }; }; /** * Validate that the default instance has credentials and filter out incomplete instances. */ export declare function validateConfig(config: GrafanaLensConfig): { valid: true; config: ValidatedGrafanaLensConfig; } | { valid: false; errors: string[]; }; /** * Derive per-signal OTLP endpoints from a base URL or metrics endpoint. * * Accepts either a base URL (http://localhost:4318) or a full metrics * endpoint (http://localhost:4318/v1/metrics) and returns all three signal paths. */ export declare function deriveOtlpEndpoints(endpoint?: string): { metrics: string; logs: string; traces: string; }; /** * Parse OTEL_EXPORTER_OTLP_HEADERS env var format: "key=value,key2=value2" * Returns parsed headers and count of skipped (malformed) pairs. */ export declare function parseOtlpHeadersEnv(raw: string): { headers: Record<string, string>; skipped: number; }; export declare function parseConfig(raw?: Record<string, unknown>): GrafanaLensConfig & { _warnings?: string[]; };