Grafana CLI (grafanactl)
$ grafanactl 官方出品 中风险grafanactl 是 Grafana Labs 官方开源的 Apache-2.0 Go 命令行工具,采用类似 kubectl 的资源模型管理仪表盘、文件夹与告警等 Grafana 资源;支持 -o json 与 YAML 输出、grafanactl config view -o json 上下文查看、resources get/pull/push,并随附官方 SKILL.md。
brew install grafana/tap/grafanactl 仪表盘与资源即代码(resources pull/push)场景适合使用支持 -o json 的 grafanactl;即席查询 PromQL/LogQL 指标可搭配 Grafana MCP(mcp-grafana)使用。
核心事实概览
- 命令名
- $ grafanactl
- FCRS-1.0 总分
- 87/100 (良好 (Good))
- 证据置信度
- 高置信度 (实测)
- CLI vs MCP 建议
- CLI + MCP 搭配
- 评测日期
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
采用熟悉的 resources get/pull/push 动词,全面支持 -o json / --output json,并内置 SKILL.md(official_skill)。
- Native
-o jsonacrossconfig viewandresourcescommands - Ships
SKILL.mdingrafana/grafanactl(official_skill)
多上下文隔离与 GitOps pull/diff 流程有效降低了误覆盖仪表盘的风险,但全局 --dry-run 仍在演进中。
- Context-isolated
~/.config/grafanactl/config.yamland GitOpspullworkflow
单文件 Go 二进制,可通过 Homebrew tap(grafana/tap/grafanactl)、go install 或全平台 Releases 安装。
- Available via
brew,go install, and cross-platform binaries
将仪表盘与文件夹等资源统一抽象为可观测性即代码(pull/push/edit/get)工作流。
- Unified
resourcesabstraction for Grafana observability-as-code
由 Grafana Labs 在 grafana/grafanactl 仓库以 Apache-2.0 协议官方活跃开发。
- Official
grafana/grafanactlrepo (Apache-2.0)
在 grafana.github.io/grafanactl/ 拥有清晰的官方文档页面、内置 SKILL.md 与 --help。
- Official docs site and
SKILL.md
安全边界、鉴权与放权指南
将 Grafana 服务器上下文与服务账号令牌保存在 ~/.config/grafanactl/config.yaml 中(可通过 grafanactl config view 检查)。
CLI 本身开源免费(Apache-2.0);需连接自建 Grafana 或 Grafana Cloud 实例。
# grafanactl Agent Rules - Always run `grafanactl config view -o json` first to confirm the active Grafana context. - Prefer `grafanactl resources pull` and git diff review before running `grafanactl resources push`. - Require user confirmation before deleting or overwriting production dashboards.
Agent 高频安全命令配方
只读查询(安全推荐)
grafanactl config view -o json
以 JSON 格式打印已配置的 Grafana 上下文与当前激活端点。
grafanactl resources get dashboards -o json
从当前上下文拉取仪表盘资源并输出结构化 JSON。
受控写入与预演
grafanactl resources pull dashboards -p ./resources -o json
将仪表盘导出至 ./resources 本地 JSON 文件,不改动远端 Grafana 状态。
核心优势
- + 统一的
-o json输出与类似kubectl的get/pull/push资源命令体系。 - + 随附官方
SKILL.md,适配 AI Agent 自动化可观测性配置管理。 - + 轻量 Go 二进制,支持 Homebrew tap、
go install与 Releases 多途径安装。
注意事项与踩坑点
- ! 专注于 Grafana 资源对象管理,不直接用于执行 Prometheus/Loki 实时指标查询。
- ! 项目处于快速迭代期,部分子命令参数仍在持续演进。
已验证兼容的 Agent 宿主
Follow 家族生态联动
同分类相关 CLI: 办公协作与 SaaS
进入分类页 →DatoCMS 官方 CLI,用于 Schema 检查、环境分支与迁移执行,支持 `--environment`、`--profile` 与 `--json`。
Windmill 官方工作流 CLI(`wmill`),支持 `--json`、`sync push --dry-run` 与 `job logs` 排查。
Datadog Labs 官方伴侣 CLI,覆盖 33+ Datadog 产品,支持 `--output json`、`--no-envelope` 与自动 AI Agent 识别。
专为人类与 AI Agent 打造的官方飞书 / Lark CLI,提供 200+ 命令、`--json` 结构化信封与 20+ 内置 Agent Skills。