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
47 lines (46 loc) • 2.92 kB
JavaScript
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js";
import { credentialEnvVar } from "../types.js";
const recipe = {
name: "redis-exporter",
category: "metrics",
signal: "metrics",
summary: "Redis metrics — memory, connections, commands, keyspace",
dashboardTemplate: "metric-explorer",
credentialParams: ["password"],
requiredParams: [
{ name: "redisUrl", type: "string", description: "Redis connection URL", example: "redis://localhost:6379" },
],
optionalParams: [
{ name: "password", type: "string", description: "Redis password", sensitive: true },
{ name: "scrapeInterval", type: "string", description: "Scrape interval", default: "15s" },
],
generateConfig(pipelineId, params, targets, pipelineName) {
const redisUrl = params.redisUrl;
const scrapeInterval = params.scrapeInterval || "15s";
const jobName = params.jobName || "redis";
const password = params.password;
const exp = componentLabel(pipelineId, "redis");
const scr = componentLabel(pipelineId, "scrape");
const rel = componentLabel(pipelineId, "relabel");
const wr = componentLabel(pipelineId, "write");
let exporterBlock = `prometheus.exporter.redis "${exp}" {\n redis_addr = "${escapeString(redisUrl)}"`;
if (password) {
const envVar = credentialEnvVar("redis-exporter", pipelineName, "password");
exporterBlock += `\n redis_password = sys.env("${envVar}")`;
}
exporterBlock += "\n}";
return new AlloyConfigBuilder()
.addBlock(exporterBlock)
.addBlock(`prometheus.scrape "${scr}" {\n targets = prometheus.exporter.redis.${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, "redis-exporter", "redis");
},
sampleQueries(_params, jobName) {
return { upCheck: `redis_up{job="${jobName}"}`, memoryUsed: `redis_memory_used_bytes{job="${jobName}"}`, connectedClients: `redis_connected_clients{job="${jobName}"}` };
},
componentIds(pipelineId) {
return [`prometheus.exporter.redis.${componentLabel(pipelineId, "redis")}`, `prometheus.scrape.${componentLabel(pipelineId, "scrape")}`, `prometheus.relabel.${componentLabel(pipelineId, "relabel")}`, `prometheus.remote_write.${componentLabel(pipelineId, "write")}`];
},
};
export default recipe;