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

62 lines (61 loc) 2.64 kB
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js"; import { buildProcessBlock, extractProcessingParams, PROCESSING_OPTIONAL_PARAMS } from "./_process-builder.js"; const recipe = { name: "file-logs", category: "logs", signal: "logs", summary: "Tail and ship local log files to Loki, with optional JSON/label processing", dashboardTemplate: null, credentialParams: [], requiredParams: [ { name: "paths", type: "string[]", description: "Glob patterns for log files to tail", example: "/var/log/app/*.log" }, ], optionalParams: [ { name: "labels", type: "string", description: "Extra labels as key=value pairs" }, { name: "encoding", type: "string", description: "File encoding", default: "utf-8" }, ...PROCESSING_OPTIONAL_PARAMS, ], generateConfig(pipelineId, params, targets, _pipelineName) { const paths = params.paths; const matchLabel = componentLabel(pipelineId, "match"); const srcLabel = componentLabel(pipelineId, "file"); const writeLabel = componentLabel(pipelineId, "write"); const builder = new AlloyConfigBuilder(); builder.addBlock(`local.file_match "${matchLabel}" { path_targets = [${paths.map((p) => `{ __path__ = "${escapeString(p)}" }`).join(", ")}] }`); // Check for processing params — wire source → process → write or source → write const processing = buildProcessBlock(pipelineId, extractProcessingParams(params), `loki.write.${writeLabel}.receiver`); const forwardTo = processing ? processing.receiverRef : `loki.write.${writeLabel}.receiver`; builder.addBlock(`loki.source.file "${srcLabel}" { targets = local.file_match.${matchLabel}.targets forward_to = [${forwardTo}] }`); if (processing) { builder.addBlock(processing.block); } builder.addBlock(`loki.write "${writeLabel}" { endpoint { url = "${escapeString(targets.lokiWriteUrl)}" } }`); return builder.build(pipelineId, "file-logs", "file-logs"); }, sampleQueries(_params, _jobName) { return { recentLogs: '{source="file"}', errorLogs: '{source="file"} |= "error"', logVolume: 'rate({source="file"}[5m])', }; }, componentIds(pipelineId) { return [ `local.file_match.${componentLabel(pipelineId, "match")}`, `loki.source.file.${componentLabel(pipelineId, "file")}`, `loki.write.${componentLabel(pipelineId, "write")}`, ]; }, }; export default recipe;