CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Grafana CLI

$ gcx 官方出品 中风险
Grafana Labs · 办公协作与 SaaS · Apache-2.0 · macos / linux / windows

Grafana CLI(gcx)是 Grafana Labs 官方推出的统一命令行工具,面向 Grafana、Grafana Enterprise 与 Grafana Cloud,用于管理仪表盘、SLO、IRM、上下文配置与 Grafana Assistant。支持 -o json、--agent(自动启用 JSON 并关闭彩色输出)、--jq 过滤、--limit 与系统钥匙串凭据存储。

FCRS-1.0 综合评分
91 /100
极佳 (Excellent)
中置信度 (源码/文档)
零摩擦安装命令
brew install gcx
CLI vs MCP 选型建议 CLI + MCP 搭配

gcx 擅长本地 GitOps 仪表盘拉取(resources pull)、--agent/--jq 脚本化以及 CI 令牌调用;Grafana MCP 更适合聊天宿主中的交互式自然语言检索。

Agent 友好度体检单

✓ 原生 JSON 输出
✓ 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
✓ 官方 SKILL.md

当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。

FCRS-1.0 六维评分拆解

Agent 友好度 23 / 25

支持 -o json、专属 --agent 模式(JSON + 无颜色)、内置 --jq、--limit 与官方 Agent Skill。

  • --agent forces JSON output and disables terminal ANSI colors
  • Built-in --jq and --limit bound and filter large payloads
安全与权限边界 22 / 25

默认使用系统钥匙串隔离存储,同时支持 GCX_KEYCHAIN=off 与 GRAFANA_TOKEN 适配 CI 环境。

  • Keychain-backed token storage prevents plaintext leakage by default
  • --context isolates staging vs production Grafana instances
安装与运行摩擦 14 / 15

单一 Go 二进制,可通过 brew install gcx、go install 与 GitHub Releases 覆盖主流平台。

  • Available via brew install gcx and native releases
能力覆盖与边际价值 13 / 15

单工具打通开源、企业版与 Grafana Cloud 的仪表盘、SLO、IRM 与 Assistant 管理。

  • Covers resources, slo, irm, assistant, and context
维护与来源背书 10 / 10

Grafana Labs 官方开源 CLI(grafana/gcx),采用 Apache-2.0 协议。

  • First-party Grafana Labs open-source project
文档与可验证性 9 / 10

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 等云能力会产生用量费用)。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# 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 高频安全命令配方

只读查询(安全推荐)

在 Agent 模式下以 JSON 拉取仪表盘
gcx resources pull dashboards -o json --agent

以无彩色转义的机器可读 JSON 导出仪表盘定义。

带条数限制与 jq 过滤列出 Grafana 上下文
gcx context list -o json --limit 20 --jq '.[].name'

列出已配置的 Grafana CLI 上下文,并通过内置 --jq 提取名称。

受控写入与预演

在 CI 中校验当前上下文连通性
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 等能力会触发云端用量计费。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI