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
35 lines (34 loc) • 2.31 kB
JavaScript
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js";
const recipe = {
name: "docker-metrics",
category: "infrastructure",
signal: "metrics",
summary: "Docker container resource metrics via cAdvisor — CPU, memory, network, disk per container",
dashboardTemplate: "metric-explorer",
credentialParams: [],
requiredParams: [],
optionalParams: [
{ name: "scrapeInterval", type: "string", description: "Scrape interval", default: "15s" },
],
generateConfig(pipelineId, params, targets, _pipelineName) {
const scrapeInterval = params.scrapeInterval || "15s";
const jobName = params.jobName || "docker-metrics";
const exp = componentLabel(pipelineId, "cadvisor");
const scr = componentLabel(pipelineId, "scrape");
const rel = componentLabel(pipelineId, "relabel");
const wr = componentLabel(pipelineId, "write");
return new AlloyConfigBuilder()
.addBlock(`prometheus.exporter.cadvisor "${exp}" { }`)
.addBlock(`prometheus.scrape "${scr}" {\n targets = prometheus.exporter.cadvisor.${exp}.targets\n forward_to = [prometheus.relabel.${rel}.receiver]\n job_name = "${escapeString(jobName)}"\n scrape_interval = "${escapeString(scrapeInterval)}"\n}`)
.addBlock(`prometheus.relabel "${rel}" {\n forward_to = [prometheus.remote_write.${wr}.receiver]\n rule {\n target_label = "job"\n replacement = "${escapeString(jobName)}"\n }\n}`)
.addBlock(`prometheus.remote_write "${wr}" {\n endpoint {\n url = "${escapeString(targets.prometheusRemoteWriteUrl)}"\n }\n}`)
.build(pipelineId, "docker-metrics", "docker-metrics");
},
sampleQueries(_params, jobName) {
return { cpuByContainer: `rate(container_cpu_usage_seconds_total{job="${jobName}"}[5m])`, memoryByContainer: `container_memory_usage_bytes{job="${jobName}"}` };
},
componentIds(pipelineId) {
return [`prometheus.exporter.cadvisor.${componentLabel(pipelineId, "cadvisor")}`, `prometheus.scrape.${componentLabel(pipelineId, "scrape")}`, `prometheus.relabel.${componentLabel(pipelineId, "relabel")}`, `prometheus.remote_write.${componentLabel(pipelineId, "write")}`];
},
};
export default recipe;