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

39 lines (38 loc) 2.56 kB
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js"; import { credentialEnvVar } from "../types.js"; const recipe = { name: "mysql-exporter", category: "metrics", signal: "metrics", summary: "MySQL database metrics — connections, queries, replication, InnoDB", dashboardTemplate: "metric-explorer", credentialParams: ["connectionString"], requiredParams: [ { name: "connectionString", type: "string", description: "MySQL DSN", sensitive: true, example: "user:password@tcp(host:3306)/dbname" }, ], optionalParams: [ { name: "scrapeInterval", type: "string", description: "Scrape interval", default: "15s" }, ], generateConfig(pipelineId, params, targets, pipelineName) { const scrapeInterval = params.scrapeInterval || "15s"; const jobName = params.jobName || "mysql"; const exp = componentLabel(pipelineId, "mysql"); const scr = componentLabel(pipelineId, "scrape"); const rel = componentLabel(pipelineId, "relabel"); const wr = componentLabel(pipelineId, "write"); const envVar = credentialEnvVar("mysql-exporter", pipelineName, "connectionString"); return new AlloyConfigBuilder() .addBlock(`prometheus.exporter.mysql "${exp}" {\n data_source_names = [sys.env("${envVar}")]\n}`) .addBlock(`prometheus.scrape "${scr}" {\n targets = prometheus.exporter.mysql.${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, "mysql-exporter", "mysql"); }, sampleQueries(_params, jobName) { return { upCheck: `mysql_up{job="${jobName}"}`, queries: `rate(mysql_global_status_queries{job="${jobName}"}[5m])` }; }, componentIds(pipelineId) { return [`prometheus.exporter.mysql.${componentLabel(pipelineId, "mysql")}`, `prometheus.scrape.${componentLabel(pipelineId, "scrape")}`, `prometheus.relabel.${componentLabel(pipelineId, "relabel")}`, `prometheus.remote_write.${componentLabel(pipelineId, "write")}`]; }, }; export default recipe;