Grafana CLI
$ gcx 官方出品 中风险Grafana CLI(gcx)是 Grafana Labs 官方推出的统一命令行工具,面向 Grafana、Grafana Enterprise 与 Grafana Cloud,用于管理仪表盘、SLO、IRM、上下文配置与 Grafana Assistant。支持 -o json、--agent(自动启用 JSON 并关闭彩色输出)、--jq 过滤、--limit 与系统钥匙串凭据存储。
brew install gcx gcx 擅长本地 GitOps 仪表盘拉取(resources pull)、--agent/--jq 脚本化以及 CI 令牌调用;Grafana MCP 更适合聊天宿主中的交互式自然语言检索。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 -o json、专属 --agent 模式(JSON + 无颜色)、内置 --jq、--limit 与官方 Agent Skill。
--agentforces JSON output and disables terminal ANSI colors- Built-in
--jqand--limitbound and filter large payloads
默认使用系统钥匙串隔离存储,同时支持 GCX_KEYCHAIN=off 与 GRAFANA_TOKEN 适配 CI 环境。
- Keychain-backed token storage prevents plaintext leakage by default
--contextisolates staging vs production Grafana instances
单一 Go 二进制,可通过 brew install gcx、go install 与 GitHub Releases 覆盖主流平台。
- Available via
brew install gcxand native releases
单工具打通开源、企业版与 Grafana Cloud 的仪表盘、SLO、IRM 与 Assistant 管理。
- Covers
resources,slo,irm,assistant, andcontext
Grafana Labs 官方开源 CLI(grafana/gcx),采用 Apache-2.0 协议。
- First-party Grafana Labs open-source project
Grafana Cloud 官方文档对钥匙串策略、标志位、计费说明与 Agent 集成描述详尽。
- Official docs at
grafana.com/docs/grafana-cloud/send-data/gcx/
安全边界、鉴权与放权指南
默认将令牌存储在系统钥匙串(macOS Keychain、Linux Secret Service、Windows Credential Manager),~/.config/gcx/config.yaml 仅保存绑定引用的路径(无头 CI 可设 GCX_KEYCHAIN=off),也支持 GRAFANA_SERVER 与 GRAFANA_TOKEN 环境变量。
Apache-2.0 开源 CLI 免费;可连接开源 Grafana 或付费 Grafana Cloud(调用 Assistant、k6、Synthetic 等云能力会产生用量费用)。
# Grafana CLI (gcx) Agent Rules - Always pass `-o json` (or `--agent`) and explicit `--context <name>` to prevent cross-environment mistakes. - In containers or headless CI, set `GCX_KEYCHAIN=off` and supply `GRAFANA_SERVER` + `GRAFANA_TOKEN`. - Require explicit approval before pushing dashboards, deleting SLOs, or invoking billable Assistant/Synthetic actions.
Agent 高频安全命令配方
只读查询(安全推荐)
gcx resources pull dashboards -o json --agent
以无彩色转义的机器可读 JSON 导出仪表盘定义。
gcx context list -o json --limit 20 --jq '.[].name'
列出已配置的 Grafana CLI 上下文,并通过内置 --jq 提取名称。
受控写入与预演
GCX_KEYCHAIN=off gcx context current -o json
绕过桌面系统钥匙串检查当前激活的 Grafana 服务上下文。
核心优势
- +
--agent、-o json、--jq与--limit组合让gcx既高效又节省上下文。 - + 默认系统钥匙串存储与无头
GCX_KEYCHAIN=off降级机制兼顾安全与 CI 自动化。
注意事项与踩坑点
- ! 直接复制
~/.config/gcx/config.yaml到其他机器不会迁移系统钥匙串中的令牌。 - ! 调用 Grafana Cloud 的 Assistant、Synthetic Monitoring 或 k6 等能力会触发云端用量计费。