qf-studio/grom

GitHub: qf-studio/grom

grom 是一款将 Prometheus 和 Grafana 仪表盘以 btop 风格精美渲染到终端的实时监控可视化工具。

Stars: 14 | Forks: 0

# grom [![ci](https://static.pigsec.cn/wp-content/uploads/repos/cas/99/993938d8ce5e902ccfb9d6747725c320d855dea3235ed9a304cedf0d94c9321f.svg)](https://github.com/qf-studio/grom/actions/workflows/ci.yml) [![release](https://img.shields.io/github/v/release/qf-studio/grom)](https://github.com/qf-studio/grom/releases) [![license](https://img.shields.io/github/license/qf-studio/grom)](LICENSE) **btop 风格的 Prometheus & Grafana 终端仪表盘。** grom 将 Prometheus 指标渲染为精致的终端仪表盘 —— 盲文 图表,渐变仪表,阈值着色统计。将其指向你现有的 Grafana 仪表盘 JSON,即可在你的终端中获得相同的布局。 ![grom demo](https://static.pigsec.cn/wp-content/uploads/repos/cas/6a/6a742703205df5263302886cb387ca61e30a6a27ac94c8e969129bd57e0bfb18.gif) ## 为什么选择 grom - [grafterm](https://github.com/slok/grafterm) —— 唯一类似 Grafana 的 TUI —— 已停止维护(2019),并且仅限于 termdash 的固定组件。 - [btop](https://github.com/aristocratos/btop) 证明了终端仪表盘也可以非常 精美 —— 但它只显示系统指标。 - 没有任何工具能在终端中渲染*你的* Grafana 仪表盘。grom 做到了。 ## 安装 ``` brew install --cask qf-studio/tap/grom # macOS / Linux go install github.com/qf-studio/grom/cmd/grom@latest ``` darwin/linux (amd64 + arm64) 的预编译二进制文件位于 [发布页面](https://github.com/qf-studio/grom/releases)。 ## 快速开始 ``` # 使用假数据的 Widget 画廊 — 不需要 Prometheus grom demo --theme tokyo-night # 适用于任何 Prometheus(仅使用 `up` + scrape_* metrics) grom run --config examples/prometheus.yaml --prom http://localhost:9090 # 在终端中渲染你现有的 Grafana dashboard grom run --grafana-json my-dashboard.json --prom http://localhost:9090 # 什么是 maps?在不运行的情况下验证 import grom import my-dashboard.json # summary + warnings grom import --check my-dashboard.json # non-zero exit on any warning (CI) # 输出单个静态帧到 stdout(snapshots、docs、cron) grom run -c dashboard.yaml --prom http://localhost:9090 --once ``` ## 按键 | 按键 | 操作 | |---|---| | `hjkl` / 方向键 | 移动焦点 | | `enter` | 放大聚焦的面板 | | `esc` | 关闭放大(或帮助浮层) | | `+` / `-` | 扩大 / 缩小时间范围(5m → 24h 预设) | | `r` | 立即刷新 | | `t` | 切换主题 | | `?` | 帮助浮层 | | `q` / `ctrl-c` | 退出 | ## 仪表盘 原生配置是微小的 YAML 文件。每个组件都是一个 PromQL 查询(或 多个)加上展示效果: ``` title: my service theme: pilot # pilot | tokyo-night | catppuccin-mocha refresh: 10s range: 1h widgets: - type: stat # stat | gauge | bargauge | timeseries title: error rate unit: percentunit # percent | percentunit | currencyUSD | sparkline: true # s | ms | bytes | short | grid: { x: 0, y: 0, w: 6, h: 4 } # Grafana-style 24-column placement thresholds: # color by CURRENT value - color: green # base (no value) - value: 0.01 color: yellow - value: 0.05 color: red queries: - expr: sum(rate(errors_total[5m])) / sum(rate(requests_total[5m])) - type: timeseries title: requests / s stacked: true grid: { x: 6, y: 0, w: 18, h: 8 } queries: - expr: sum by (code) (rate(requests_total[5m])) legend: "{{code}}" # Grafana-style label templates ``` 注意事项: - `grid` 是可选的 —— 在所有地方省略它,grom 会自动将组件按 具有响应式断点的行排列(1 列 < 80 字符,2 列 < 140,4 列及以上)。 - **timeseries** 总是查询区间(步长自动适配图表宽度); **stat** 通过 `sparkline: true` 结合进来(数值 + 趋势带);仪表和 条形仪表保持即时。在查询上使用 `instant: true` 可退出区间模式。 - 阈值颜色是语义化的(`green`、`yellow`、`red`、`blue`、`text`、 `gray` —— 根据主题解析)或原始十六进制。 - 失败的查询只会标记其自身的面板 —— 网格的其余部分保持活动状态。 工作示例:[`examples/prometheus.yaml`](examples/prometheus.yaml) (针对任何 Prometheus 运行)以及 [`examples/pilot.yaml`](examples/pilot.yaml)。 ## Grafana 导入 `grom run --grafana-json` / `grom import` 接受仪表盘 JSON 导出 —— 裸露或由 API 封装(`{"dashboard": {...}}`)。 | Grafana | grom | |---|---| | `stat`, `gauge`, `bargauge`, `timeseries` 面板 | 1:1 组件 | | `gridPos` | 24 列布局,缩放以适应你的终端 | | `fieldConfig` 单位 / 小数位 / 最小值 / 最大值 / 阈值 | 支持 | | stat `graphMode` | `area` → sparkline,`none` → 仅数字 | | 自定义堆叠 | 堆叠图表 | | `targets[].expr` / `legendFormat` / `instant` | 查询 | | `time.from: now-`, `refresh` | 初始范围 & 轮询间隔 | | 行 | 丢弃;子节点提升至原位 | | 其他任何情况 | 其网格槽中的占位面板 + 警告 | ## 终端注意事项 - **颜色**:当你的终端支持时会使用 24 位色,否则降级为 ANSI-256/16。 默认情况下,通过管道输出是无色的(`CLICOLOR_FORCE=1` 会 强制使用 ANSI 回退 —— 如需忠实截取,请使用 PTY)。 - **盲文**:图表使用盲文点(每个单元格 2×4)。如果你的字体缺乏 覆盖范围,`--ascii` 会切换为实心块字符。 ## 开发 ``` make build # build ./bin/grom make demo # render the widget gallery make test # go test -race make lint # golangci-lint ``` 发布由标签驱动:`make release V=x.y.z` 会推送标签,CI (goreleaser)会发布二进制文件 + Homebrew cask。README 的 GIF 会通过 `vhs docs/demo.tape` 重新生成(将其指向任何活动的 Prometheus)。 ## 路线图 - Prometheus 身份验证(basic / bearer / TLS) - 每个断点重新堆叠导入的布局;用于 阶梯网格的 2D 画布 - 免配置的探索模式(指标浏览器,即席查询) ## 许可证 MIT © QF Studio
标签:EVTX分析, Go语言, Grafana, 可视化面板, 日志审计, 程序破解, 终端UI, 自定义请求头, 运维监控