鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

promql

提供面向 Prometheus 生态的 PromQL 全流程支持,涵盖查询编写、语法校验、性能调优与可观测性工程实践,包括速率计算选型、聚合逻辑设计、分位数计算、错误率防护、时序偏移、SLO 数学建模及高基数问题诊断,适用于从基础指标分析到生产级告警与记录规则落地的各类场景。

访问 GitHub
文档Skills.MD
name
promql
license
Apache-2.0
description
Write, validate, and optimize PromQL for Prometheus / Grafana Mimir / Grafana Cloud Metrics. Covers `rate` vs `irate` vs `increase`, label matchers and regex, `sum / avg / topk / by / without` aggregation, classic + native `histogram_quantile`, ratios with divide-by-zero guards, `absent` / `changes` for staleness, time offsets and `predict_linear`, recording-rule naming, SLO + burn-rate math, and a cardinality-hunting playbook. Use when writing a metric query, fixing wrong p95s, building an error-budget alert, debugging "query is slow", finding the noisy label that blew up cardinality, or migrating a dashboard query to a recording rule — even when the user says "calculate the error rate", "p99 latency", "sum by service", "why is this query slow", or "what's filling Mimir" without naming PromQL.

PromQL Query Patterns

Docs: https://prometheus.io/docs/prometheus/latest/querying/basics/

PromQL returns either an instant vector, a range vector, or a scalar.

Golden rule: rate() / increase() require a range vector ≥ 4× the scrape interval. 60s scrape → use [5m] minimum.

Prerequisites

  • A Prometheus / Mimir / Grafana Cloud endpoint to query (/api/v1/query or via Grafana Explore)
  • The PromQL pattern library in references/patterns.md

Common Workflows

1. Write + validate a query

▼
bash
复制代码
# 0. Point at your Prometheus/Mimir. For Grafana Cloud, use the metrics endpoint # and add basic auth (-u "<metrics_user>:<token>") to each curl below. PROM=http://localhost:9090 # or https://prometheus-prod-XX.grafana.net/api/prom # 1. Sketch the query — for "5xx error rate per service": EXPR='sum(rate(http_requests_total{status_code=~"5.."}[5m])) by (service)' # 2. Validate syntax + that the metric/labels exist curl -sG --data-urlencode "query=${EXPR}" \ "$PROM/api/v1/query" | jq '.status, (.data.result|length)' # Expect: "success" and result count > 0. If 0 — check label spelling and scrape activity: curl -sG --data-urlencode "match[]=http_requests_total" "$PROM/api/v1/series" | jq '.data | length' # 3. Sanity-check the magnitude — open Grafana Explore, paste the expr, # confirm the values look right against a known ground truth (k6 run, log count, etc.)

2. Common patterns to copy

Per-status request rate (aggregate AFTER rate):

▼
promql
复制代码
sum(rate(http_requests_total{job="api"}[5m])) by (status_code)

p95 latency (must keep le in the inner aggregation):

▼
promql
复制代码
histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service))

Error rate with divide-by-zero guard:

▼
promql
复制代码
sum(rate(http_requests_total{status_code=~"5.."}[5m])) / (sum(rate(http_requests_total[5m])) > 0)

Full library (recording rules, SLO burn-rate, offsets, cardinality hunt, native histograms): references/patterns.md.

3. Convert a slow dashboard query into a recording rule

▼
yaml
复制代码
# 1. Pick the slow expression, give it a recording-rule name groups: - name: http_request_rates interval: 1m rules: - record: job:http_request_duration_p95:rate5m expr: | histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le, job))
▼
bash
复制代码
# 2. After rules load, verify the new metric exists curl -sG --data-urlencode "query=job:http_request_duration_p95:rate5m" \ "$PROM/api/v1/query" | jq '.data.result | length' # → > 0 # 3. Verify it matches the original expression for at least one sample window # (Both queries should produce the same value at the same timestamp.) # 4. Replace the dashboard panel expression with the recording-rule metric.

Common bugs

  • histogram_quantile returns NaN → forgot by (le) in the inner aggregation
  • "No data" → check the metric exists (/api/v1/series) and the window ≥ 4× scrape interval
  • Wrong rate magnitude → counter was aggregated before rate() (always rate() first)
  • Query timeout → series count too high; use topk(...) + a recording rule + drop high-cardinality labels (see references/patterns.md)

Resources

  • PromQL basics
  • Operators
  • Functions
  • Grafana Mimir

快捷安装

复制到终端去安装 Skill

npxskillsaddhttps://github.com/grafana/skills--skillpromql
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
debug
debug 是一个系统化定位软件缺陷根因的技能,适用于用户报告 'fix'、'broken'、'error' 等问题或测试意外失败时。它通过可验证的假设、最小复现、因果链分析和回归测试,确保在修复前准确定位根本原因。
retrieving-developer-knowledge
retrieving-developer-knowledge 用于搜索、获取和整合 Google 官方开发者文档,覆盖 Google Cloud、AI/Gemini、Android、Chrome、Web、Flutter、Go、Firebase 等平台,适用于查询 gcloud CLI 命令、API 语法、IAM 权限或架构对比等场景。
diff-intake
diff-intake 读取 PR 或分支差异,生成结构化 YAML 变更摘要,用于下游 analytics instrumentation 技能。适用于用户提交 PR 链接、分支对比或原始 diff 后需理解变更内容、评估分析覆盖或启动埋点流程的场景。
lean-build
以极简方式构建高风险功能,强调架构一致性、范围严格控制与明确终止条件,通过复用现有接口、消除冗余逻辑、剔除非必要抽象与配置,实现端到端可验证的窄口径交付。
ast-grep
提供基于抽象语法树的结构化代码搜索能力,支持跨语言精准匹配代码模式、定位特定语法结构、识别复杂代码特征,适用于需理解代码语义而非简单文本匹配的深度代码分析场景。