query-metrics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCRITICAL: ALL script paths are relative to this skill's folder. Run them with full path (e.g.,).scripts/metrics-query
重要提示: 所有脚本路径均相对于此skill的文件夹。请使用完整路径运行它们(例如:)。scripts/metrics-query
Querying Axiom Metrics
查询Axiom指标
Query OpenTelemetry metrics stored in Axiom's MetricsDB.
查询存储在Axiom MetricsDB中的OpenTelemetry指标。
Setup
配置步骤
Run to check requirements (curl, jq, ~/.axiom.toml).
scripts/setupConfig in (shared with axiom-sre):
~/.axiom.tomltoml
[deployments.prod]
url = "https://api.axiom.co"
token = "xaat-your-token"
org_id = "your-org-id"The target dataset must be of kind .
otel-metrics-v1运行以检查依赖项(curl、jq、~/.axiom.toml)。
scripts/setup配置文件位于(与axiom-sre共享):
~/.axiom.tomltoml
[deployments.prod]
url = "https://api.axiom.co"
token = "xaat-your-token"
org_id = "your-org-id"目标数据集的类型必须为。
otel-metrics-v1Learning the Metrics Query Syntax
学习指标查询语法
The query endpoint is self-describing. Before writing any query, fetch the full specification:
bash
scripts/metrics-spec <deployment>This returns the complete metrics query specification with syntax, operators, and examples. Read it to understand query structure before composing queries.
查询端点是自描述的。在编写任何查询之前,请获取完整的规范:
bash
scripts/metrics-spec <deployment>该命令会返回包含语法、运算符和示例的完整指标查询规范。在编写查询前请先阅读该规范以理解查询结构。
Workflow
工作流程
- Learn the language: Run to read the metrics query spec
scripts/metrics-spec <deployment> - Discover metrics: If possible use the find-metrics command, otherwise list available metrics via the info scripts
- Explore tags: List tags and tag values to understand filtering options
- Write and execute query: Compose a metrics query and run it via
scripts/metrics-query - Iterate: Refine filters, aggregations, and groupings based on results
If you are unsure what to query, start by searching for metrics that match a relevant tag value:
bash
scripts/metrics-info <deployment> <dataset> find-metrics "frontend"This finds metrics associated with a known value (e.g., a service name or host), giving you a starting point for building queries.
- 学习查询语法:运行以阅读指标查询规范
scripts/metrics-spec <deployment> - 发现指标:如果可以,使用find-metrics命令,否则通过info脚本列出可用指标
- 探索标签:列出标签和标签值以了解过滤选项
- 编写并执行查询:编写指标查询并通过运行
scripts/metrics-query - 迭代优化:根据结果调整过滤器、聚合和分组方式
如果不确定要查询什么,可以先搜索与相关标签值匹配的指标:
bash
scripts/metrics-info <deployment> <dataset> find-metrics "frontend"该命令会找到与已知值(例如服务名称或主机)关联的指标,为你构建查询提供起点。
Query Metrics
查询指标
Execute a metrics query against a dataset:
bash
scripts/metrics-query <deployment> '<apl>' '<startTime>' '<endTime>'Example:
bash
scripts/metrics-query prod \
'my-dataset:http.server.duration | align to 5m using avg' \
'2025-06-01T00:00:00Z' \
'2025-06-02T00:00:00Z'| Parameter | Required | Description |
|---|---|---|
| Yes | Name from |
| Yes | Metrics query string. Dataset is extracted from the query itself. |
| Yes | RFC3339 timestamp only (e.g., |
| Yes | RFC3339 timestamp only (e.g., |
对数据集执行指标查询:
bash
scripts/metrics-query <deployment> '<apl>' '<startTime>' '<endTime>'示例:
bash
scripts/metrics-query prod \
'my-dataset:http.server.duration | align to 5m using avg' \
'2025-06-01T00:00:00Z' \
'2025-06-02T00:00:00Z'| 参数 | 是否必填 | 描述 |
|---|---|---|
| 是 | |
| 是 | 指标查询字符串。数据集会从查询本身中提取。 |
| 是 | 仅支持RFC3339格式的时间戳(例如: |
| 是 | 仅支持RFC3339格式的时间戳(例如: |
Discovery (Info Endpoints)
发现功能(信息端点)
Use to explore what metrics, tags, and values exist in a dataset before writing queries. Time range defaults to the last 24 hours; override with and .
scripts/metrics-info--start--end在编写查询前,使用探索数据集中存在的指标、标签和值。时间范围默认为过去24小时;可通过和参数覆盖默认值。
scripts/metrics-info--start--endList metrics in a dataset
列出数据集中的指标
bash
scripts/metrics-info <deployment> <dataset> metricsbash
scripts/metrics-info <deployment> <dataset> metricsList tags in a dataset
列出数据集中的标签
bash
scripts/metrics-info <deployment> <dataset> tagsbash
scripts/metrics-info <deployment> <dataset> tagsList values for a specific tag
列出特定标签的取值
bash
scripts/metrics-info <deployment> <dataset> tags <tag> valuesbash
scripts/metrics-info <deployment> <dataset> tags <tag> valuesList tags for a specific metric
列出特定指标的标签
bash
scripts/metrics-info <deployment> <dataset> metrics <metric> tagsbash
scripts/metrics-info <deployment> <dataset> metrics <metric> tagsList tag values for a specific metric and tag
列出特定指标和标签的取值
bash
scripts/metrics-info <deployment> <dataset> metrics <metric> tags <tag> valuesbash
scripts/metrics-info <deployment> <dataset> metrics <metric> tags <tag> valuesFind metrics matching a tag value
查找匹配标签值的指标
bash
scripts/metrics-info <deployment> <dataset> find-metrics "<search-value>"bash
scripts/metrics-info <deployment> <dataset> find-metrics "<search-value>"Custom time range
自定义时间范围
All info commands accept and for custom time ranges:
--start--endbash
scripts/metrics-info prod my-dataset metrics \
--start 2025-06-01T00:00:00Z \
--end 2025-06-02T00:00:00Z所有info命令都支持通过和参数设置自定义时间范围:
--start--endbash
scripts/metrics-info prod my-dataset metrics \
--start 2025-06-01T00:00:00Z \
--end 2025-06-02T00:00:00ZError Handling
错误处理
HTTP errors return JSON with and fields:
messageerrorjson
{"message": "description", "error": "detail"}Common status codes:
- 400 — Invalid query syntax or bad dataset name
- 401 — Missing or invalid authentication
- 403 — No permission to query/ingest this dataset
- 404 — Dataset not found
- 429 — Rate limited
- 500 — Internal server error
On a 500 error, re-run the failing script call with flags to capture response headers, then report the or header value to the user. This trace ID is essential for debugging the failure with the backend team.
curl -vtraceparentx-axiom-trace-idHTTP错误会返回包含和字段的JSON:
messageerrorjson
{"message": "description", "error": "detail"}常见状态码:
- 400 — 查询语法无效或数据集名称错误
- 401 — 缺少身份验证或身份验证无效
- 403 — 无权限查询/摄入该数据集
- 404 — 未找到数据集
- 429 — 触发速率限制
- 500 — 服务器内部错误
当出现500错误时,添加标志重新运行失败的脚本调用以捕获响应头,然后将或头的值告知用户。此跟踪ID对于与后端团队一起调试问题至关重要。
curl -vtraceparentx-axiom-trace-idScripts
脚本列表
| Script | Usage |
|---|---|
| Check requirements and config |
| Fetch metrics query specification |
| Execute a metrics query |
| Discover metrics, tags, and values |
| Low-level API calls |
Run any script without arguments to see full usage.
| 脚本 | 用途 |
|---|---|
| 检查依赖项和配置 |
| 获取指标查询规范 |
| 执行指标查询 |
| 发现指标、标签和值 |
| 底层API调用 |
运行任何不带参数的脚本即可查看完整使用说明。