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

79 lines (78 loc) 3.2 kB
/** * Pipeline Store * * Manages the lifecycle of Alloy pipeline definitions: * - CRUD operations on pipeline records * - Persistence to ${stateDir}/alloy-pipelines.json * - Drift detection (file vs. state vs. Alloy components) * - Limit enforcement (max pipelines) * * Follows the same persistence pattern as CustomMetricsStore: * - Versioned JSON file in stateDir * - Load on start, save after each mutation * - Survives process restarts * * State is the source of truth for what Grafana Lens has created. * Drift detection reconciles state with the filesystem and Alloy runtime. */ import type { PipelineDefinition, PipelineStatus, AlloyPipelineLimits, DriftReport } from "./types.js"; export declare class PipelineStore { private state; private readonly stateFilePath; private readonly limits; private readonly configDir; private readonly filePrefix; constructor(opts: { stateDir: string; configDir: string; filePrefix?: string; limits?: Partial<AlloyPipelineLimits>; }); /** Load state from disk. Creates empty state if file doesn't exist. */ load(): Promise<void>; /** Save current state to disk (atomic: write tmp then rename). */ save(): Promise<void>; /** Generate a short unique pipeline ID (8 hex chars). */ generateId(): string; /** * Add a new pipeline definition. * Throws if the name already exists or limits are exceeded. */ add(pipeline: PipelineDefinition): void; /** Get a pipeline by name. Returns undefined if not found. */ get(name: string): PipelineDefinition | undefined; /** List all pipelines, optionally filtered by status. */ list(statusFilter?: PipelineStatus): PipelineDefinition[]; /** Update a pipeline's fields. Returns false if not found. */ update(name: string, updates: Partial<Pick<PipelineDefinition, "params" | "filePath" | "status" | "componentIds" | "configHash" | "lastError" | "signal" | "boundPorts" | "sampleQueries">>): boolean; /** Remove a pipeline by name. Returns false if not found. */ remove(name: string): boolean; /** Get pipeline count and limits. */ usage(): { count: number; max: number; }; /** Generate the .alloy file path for a pipeline. */ configFilePath(pipelineId: string, name: string): string; /** Compute SHA-256 hash of config content (for drift detection). */ static configHash(content: string): string; /** * Check if any of the given ports conflict with active pipelines. * Returns the first conflict found, or null if no conflicts. */ checkPortConflict(ports: number[], excludePipeline?: string): { port: number; pipelineName: string; } | null; /** * Detect drift between stored state and filesystem. * Checks file existence and hash for all active pipelines, * plus scans for orphan files in the config directory. */ detectFileDrift(): Promise<DriftReport>; /** * Mark pipelines as drifted based on drift report. * Call this after detectFileDrift() to update state. */ applyDriftReport(report: DriftReport): number; }