mcpField
D
dpm-finder

dpm-finder

github.com/grafana云与 DevOps2954.2k 次安装1 天前更新
代码仓库

关于 dpm-finder

dpm-finder 是面向 Grafana Cloud 用户的 Python 命令行工具,用于分析 Prometheus 指标的数据点速率。它按每分钟数据点数排序,并提供逐序列明细以定位高流量标签。

主要功能

  1. 01按 DPM 排序指标
  2. 02显示活跃时间序列数
  3. 03按标签组合拆分 DPM
  4. 04按估算支出确定优先级

适用场景

  1. 01查找数据点最多的指标
  2. 02定位高 DPM 对应的标签组合
  3. 03为成本审查确定指标优先级

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/grafana/skills --skill dpm-finder

安装后在 Claude Code 中输入/dpm-finder确认已加载。

附带文件references/cli.md

详细介绍

dpm-finder

Grafana PS 工具,可按 DPM 对 Prometheus 指标进行排名,并提供逐序列细分。来源:https://github.com/grafana-ps/dpm-finder

前置条件

  • Python 3.9+
  • Grafana Cloud Prometheus 端点 URL + 数字型堆栈 ID + API 密钥(glc_…,需有 metrics:read 范围)

常见工作流

单次分析(最常见)
# 1. Clone + venv + install
git clone https://github.com/grafana-ps/dpm-finder.git
cd dpm-finder
python3 -m venv venv && source venv/bin/activate
pip install -r requirements.txt

# 2. Configure creds — copy .env_example → .env and fill in:
#    PROMETHEUS_ENDPOINT  https://prometheus-<cluster_slug>.grafana.net  (NOTHING after .net)
#    PROMETHEUS_USERNAME  <numeric stack id>
#    PROMETHEUS_API_KEY   glc_…

# 3. Verify creds before scanning — should return >0 series count
curl -s -u "$PROMETHEUS_USERNAME:$PROMETHEUS_API_KEY" \
  "$PROMETHEUS_ENDPOINT/api/v1/label/__name__/values" | jq '.data | length'

# 4. Run the scan (10-min lookback, 2.0 DPM minimum, top output)
./dpm-finder.py -f json -m 2.0 -t 8 --timeout 120 -l 10

# 5. Read the result — top 10 metrics by DPM
jq -r '.metrics | sort_by(-.dpm) | .[:10][] | "\(.dpm)\t\(.series_count)\t\(.metric_name)"' metric_rates.json

如果步骤 5 没有结果,请降低 -m,或确认端点 URL 在 .net 后没有多余路径。

使用 gcx 查找堆栈详情

如果已安装 gcx,它可以推导出端点和用户名:

gcx config check          # active stack context
gcx config list-contexts  # all configured stacks
gcx config view           # full config with endpoints

Prometheus 端点的格式为 https://prometheus-{cluster_slug}.grafana.net。用户名是数字型堆栈 ID。

如果没有 gcx:请在 Grafana Cloud 门户中查找,或在用量数据源上查询 grafanacloud_instance_info{name=~"STACK_NAME.*"}。

多堆栈运行

为避免触发 GCloud 速率限制,并发运行最多 3 个任务。请分批处理堆栈,并等待每批完成后再处理下一批。

解读结果

  • DPM = 该指标的所有序列中的每分钟最大数据点数
  • series_count = 该指标的活跃时间序列数
  • series_detail[](仅 JSON / 文本格式)= 按标签组合细分的 DPM,可用于找出造成问题的标签
  • 按 DPM 降序排列 → 找出最嘈杂的指标;结合 --cost-per-1000-series,按支出优先级排序

故障排查

  • 401 / 403 — API 密钥无效或缺少 metrics:read;请确认 PROMETHEUS_USERNAME 是数字型堆栈 ID
  • 超时 — 对于包含数千个指标的堆栈,请将 --timeout 提高到 120 以上
  • HTTP 422 — 指标存在聚合规则;工具会发出警告并自动跳过
  • 结果为空 — 降低 -m;确认端点后没有多余路径
  • 连接错误 — 采用指数退避重试,最多重试 10 次;持续失败通常表示网络或防火墙问题

参考资料

  • references/cli.md — 完整的标志参考、输出格式详情、导出器模式、Docker 调用、自动排除规则和重试行为

资源

评论

支持 Markdown