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
61 lines (60 loc) • 2.39 kB
JavaScript
import { AlloyConfigBuilder, componentLabel, escapeString } from "../../config-builder.js";
import { buildProcessBlock, extractProcessingParams, PROCESSING_OPTIONAL_PARAMS } from "./_process-builder.js";
const recipe = {
name: "loki-push-api",
category: "logs",
signal: "logs",
summary: "Accept logs via Loki-compatible HTTP push API — centralized log gateway with optional JSON/label processing",
dashboardTemplate: null,
credentialParams: [],
requiredParams: [],
optionalParams: [
{ name: "listenPort", type: "number", description: "HTTP listen port", default: 3500 },
{ name: "listenAddress", type: "string", description: "Bind address", default: "0.0.0.0" },
...PROCESSING_OPTIONAL_PARAMS,
],
generateConfig(pipelineId, params, targets, _pipelineName) {
const listenPort = params.listenPort ?? 3500;
const listenAddress = params.listenAddress || "0.0.0.0";
const srcLabel = componentLabel(pipelineId, "push_api");
const writeLabel = componentLabel(pipelineId, "write");
const builder = new AlloyConfigBuilder();
const processing = buildProcessBlock(pipelineId, extractProcessingParams(params), `loki.write.${writeLabel}.receiver`);
const forwardTo = processing
? processing.receiverRef
: `loki.write.${writeLabel}.receiver`;
builder.addBlock(`loki.source.api "${srcLabel}" {
http {
listen_address = "${escapeString(listenAddress)}"
listen_port = ${listenPort}
}
forward_to = [${forwardTo}]
}`);
if (processing) {
builder.addBlock(processing.block);
}
builder.addBlock(`loki.write "${writeLabel}" {
endpoint {
url = "${escapeString(targets.lokiWriteUrl)}"
}
}`);
return builder.build(pipelineId, "loki-push-api", "loki-push-api");
},
sampleQueries() {
return {
recentLogs: '{source="push-api"}',
errorLogs: '{source="push-api"} |= "error"',
logVolume: 'rate({source="push-api"}[5m])',
};
},
componentIds(pipelineId) {
return [
`loki.source.api.${componentLabel(pipelineId, "push_api")}`,
`loki.write.${componentLabel(pipelineId, "write")}`,
];
},
boundPorts(params) {
return [Number(params.listenPort)];
},
};
export default recipe;