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.63 kB
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js"; const recipe = { name: "elasticsearch-exporter", category: "infrastructure", signal: "metrics", summary: "Elasticsearch cluster metrics — health, indices, shards, JVM", dashboardTemplate: "metric-explorer", credentialParams: ["basicAuth"], requiredParams: [ { name: "elasticsearchUrl", type: "string", description: "Elasticsearch HTTP URL", example: "http://elasticsearch:9200" }, ], optionalParams: [ { name: "basicAuth", type: "string", description: "Basic auth (user:password)", sensitive: true }, { name: "scrapeInterval", type: "string", description: "Scrape interval", default: "15s" }, ], generateConfig(pipelineId, params, targets, _pipelineName) { const esUrl = params.elasticsearchUrl; const scrapeInterval = params.scrapeInterval || "15s"; const jobName = params.jobName || "elasticsearch"; const exp = componentLabel(pipelineId, "es"); const scr = componentLabel(pipelineId, "scrape"); const rel = componentLabel(pipelineId, "relabel"); const wr = componentLabel(pipelineId, "write"); return new AlloyConfigBuilder() .addBlock(`prometheus.exporter.elasticsearch "${exp}" {\n address = "${escapeString(esUrl)}"\n}`) .addBlock(`prometheus.scrape "${scr}" {\n targets = prometheus.exporter.elasticsearch.${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, "elasticsearch-exporter", "elasticsearch"); }, sampleQueries(_params, jobName) { return { clusterHealth: `elasticsearch_cluster_health_status{job="${jobName}"}`, indexCount: `elasticsearch_indices_docs_total{job="${jobName}"}` }; }, componentIds(pipelineId) { return [`prometheus.exporter.elasticsearch.${componentLabel(pipelineId, "es")}`, `prometheus.scrape.${componentLabel(pipelineId, "scrape")}`, `prometheus.relabel.${componentLabel(pipelineId, "relabel")}`, `prometheus.remote_write.${componentLabel(pipelineId, "write")}`]; }, }; export default recipe;