Loading...
Loading...
Compare original and translation side by side
aliyun version3.3.8aliyun version3.3.8aliyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-sls-query"
aliyun plugin updatealiyun configure ai-mode enable
aliyun configure ai-mode set-user-agent --user-agent "AlibabaCloud-Agent-Skills/alibabacloud-sls-query"
aliyun plugin updatealiyun configure listaliyun configurealiyun configure listaliyun configure listaliyun configurealiyun configure list| API | CLI | Action | Purpose |
|---|---|---|---|
| GetLogsV2 | | | Run query / SQL / SPL and read results |
| GetIndex | | | Read index config to verify prerequisites |
Permission failure handling: If a call returnspermission error, stop and surface references/ram-policies.md to the user. Do not retry with a different account without explicit user confirmation.Unauthorized
| API | CLI命令 | 操作权限 | 用途 |
|---|---|---|---|
| GetLogsV2 | | | 运行查询/SQL/SPL并读取结果 |
| GetIndex | | | 读取索引配置以验证前置条件 |
**权限失败处理:**若调用返回权限错误,请停止操作并向用户提供references/ram-policies.md链接。未经用户明确确认,请勿使用其他账号重试。Unauthorized
get-indexaliyun sls get-index \
--project <project> --logstore <logstore>| Section | Meaning |
|---|---|
| Full-text index — absence means full-text search is disabled |
| Field indexes — map of field → |
IndexConfigNotExistlinekeyslogstoreget-indexget-indexaliyun sls get-index \
--project <project> --logstore <logstore>| 部分 | 含义 |
|---|---|
| 全文索引——不存在则表示全文搜索已禁用 |
| 字段索引——字段到 |
IndexConfigNotExistlinekeyslogstoreget-index| Priority | Mode | Statement Form | Use when | Requires |
|---|---|---|---|---|
| 1 | Index search | | Filtering raw logs; return time-ordered and paginated logs | Full-text ( |
| 2 | SQL | | Aggregation, | Target field has |
| 3 | SQL scan | | User requested | None |
| 4 | SPL | | User requested | None |
GROUP BY| 优先级 | 模式 | 语句格式 | 使用场景 | 要求 |
|---|---|---|---|---|
| 1 | 索引搜索 | | 过滤原始日志;返回按时间排序的分页日志 | 全文索引( |
| 2 | SQL | | 聚合、 | 目标字段的 |
| 3 | SQL扫描 | | 用户明确要求 | 无 |
| 4 | SPL | | 用户明确要求 | 无 |
GROUP BY|||** and "payment failed" and status: "500" and not path: "/healthz"*"..."key: "value"andornotkey: *>>=[a, b]longdouble|** and "payment failed" and status: "500" and not path: "/healthz"*"..."key: "value"andornotkey: *>>=[a, b]longdoublestatus: 500 | SELECT date_trunc('minute', __time__) AS minute,
count(*) AS errors
FROM log
GROUP BY minute
ORDER BY minutelogget-indexlongdoublestatus >= 500texttry_caststatus: 500 | SELECT date_trunc('minute', __time__) AS minute,
count(*) AS errors
FROM log
GROUP BY minute
ORDER BY minutelogget-indexlongdoublestatus >= 500texttry_caststatus: 500 and service: payment
| where try_cast(latency as BIGINT) > 1000
| extend latency_ms = try_cast(latency as BIGINT)
| project service, latency_ms, messagestatus: 500 and service: payment
| where try_cast(latency as BIGINT) > 1000
| extend latency_ms = try_cast(latency as BIGINT)
| project service, latency_ms, messagevarcharcast()try_cast()* | set session mode=scan; SELECT api, count(1) AS pv FROM log GROUP BY apivarcharcast()try_cast()* | set session mode=scan; SELECT api, count(1) AS pv FROM log GROUP BY api--from--to--from--toYYYY-MM-DD HH:MM:SSundefined--from--to--from--toYYYY-MM-DD HH:MM:SSundefined
**2. Natural-language absolute time without timezone**
If the user gives a date/time but no timezone, use the machine's local timezone. First normalize natural language such as `2026年3月13日12点` to `2026-03-13 12:00:00`, then parse it as local time.
```bash
**2. 无时区的自然语言绝对时间**
若用户提供日期/时间但未指定时区,使用机器本地时区。先将自然语言(如`2026年3月13日12点`)标准化为`2026-03-13 12:00:00`,再按本地时间解析。
```bash
For a time range such as "2026年3月13日12点到13点", compute both endpoints the same way. For a single point-in-time request, infer a practical window from the user's intent; if unclear, ask for the range before executing.
**3. Absolute time with explicit timezone**
To convert a local date/time to a Unix timestamp: parse the input as UTC with `date -u`, then **subtract** the timezone's UTC offset in seconds.
Formula: `unix_ts = date_utc_parse(input) − (UTC_offset_hours × 3600)`
```bash
对于时间范围(如"2026年3月13日12点到13点"),按相同方式计算两个端点。若用户仅指定单个时间点,根据用户意图推断合理时间窗口;若不明确,执行前需询问用户时间范围。
**3. 带明确时区的绝对时间**
将本地日期/时间转换为Unix时间戳:使用`date -u`将输入解析为UTC时间,然后**减去**时区的UTC偏移秒数。
公式:`unix_ts = date_utc_parse(input) − (UTC_offset_hours × 3600)`
```bash
```bash
```bash
Common UTC offsets (value to subtract):
| Timezone | UTC offset hours | Seconds to subtract |
|------------------|------------------|---------------------|
| Beijing (UTC+8) | +8 | `28800` |
| Tokyo (UTC+9) | +9 | `32400` |
| London (UTC) | 0 | `0` |
| New York (UTC-5) | -5 | `-18000` |
---
常见UTC偏移量(需减去的值):
| 时区 | UTC偏移小时数 | 需减去的秒数 |
|------------------|------------------|---------------------|
| 北京(UTC+8) | +8 | `28800` |
| 东京(UTC+9) | +9 | `32400` |
| 伦敦(UTC) | 0 | `0` |
| 纽约(UTC-5) | -5 | `-18000` |
---get-logs-v2get-logs-v2aliyun sls get-logs-v2aliyun help sls get-logs-v2--project--logstore--from--to--query|aliyun sls get-logs-v2aliyun help sls get-logs-v2--project--logstore--from--to--query|--offset--line--offset--linealiyun sls get-logs-v2 \
--project my-project --logstore my-logstore \
--from 1740000000 --to 1740003600 \
--query '* and "payment failed" and status: "500"' \
--line 100 --offset 0 --reverse true--line1–100--offset0--reverse truefalsealiyun sls get-logs-v2 \
--project my-project --logstore my-logstore \
--from 1740000000 --to 1740003600 \
--query '* and "payment failed" and status: "500"' \
--line 100 --offset 0 --reverse true--line1–100--offset0--reverse truefalseLIMITLIMITaliyun sls get-logs-v2 \
--project my-project --logstore my-logstore \
--from 1740000000 --to 1740003600 \
--query 'status: "500" | SELECT request_uri, count(*) AS cnt FROM log GROUP BY request_uri ORDER BY cnt DESC LIMIT 20'LIMIT countLIMIT 500LIMIT offset, countLIMIT 20, 20LIMIT 40, 20LIMIT count OFFSET offsetLIMIT offset, countORDER BY <field> DESC/ASCmeta.progressIncompleteCompletealiyun sls get-logs-v2 \
--project my-project --logstore my-logstore \
--from 1740000000 --to 1740003600 \
--query 'status: "500" | SELECT request_uri, count(*) AS cnt FROM log GROUP BY request_uri ORDER BY cnt DESC LIMIT 20'LIMIT countLIMIT 500LIMIT offset, countLIMIT 20, 20LIMIT 40, 20LIMIT count OFFSET offsetLIMIT offset, countORDER BY <field> DESC/ASCmeta.progressIncompleteCompleteget-logs-v2{
"meta": { "progress": "Complete", "count": 10, ... },
"data": [ { "field1": "value1", ... }, ... ]
}| Field | Meaning |
|---|---|
| |
| Number of rows returned |
| Array of log entries or aggregation rows; may contain |
jq--cli-query| Extract | | |
|---|---|---|
| Data rows | | |
| Progress | | |
| Row count | | |
| Specific fields | | |
get-logs-v2{
"meta": { "progress": "Complete", "count": 10, ... },
"data": [ { "field1": "value1", ... }, ... ]
}| 字段 | 含义 |
|---|---|
| |
| 返回的行数 |
| 日志条目或聚合行数组;可能包含 |
jq--cli-query| 提取内容 | | |
|---|---|---|
| 数据行 | | |
| 进度 | | |
| 行数 | | |
| 指定字段 | | |
aliyun sls get-logs-v2 ...dataaliyun sls get-logs-v2 ...dataaliyun configure ai-mode disablealiyun configure ai-mode disableSELECTdoc_value: true__time__--from--toget-logsget-logs-v2SELECTdoc_value: true__time__--from--toget-logsget-logs-v2--from--tokeystextdoc_value*meta.progress = IncompleteCommon Errors--from--tokeystextdoc_value*meta.progress = Incomplete| Document | Description |
|---|---|
| references/query-analysis.md | Mode decision, index-search / SQL rules, scan semantics |
| references/spl-guide.md | SPL pipeline syntax, common commands, field handling |
| references/functions-guide.md | Function categories, SQL/SPL differences, templates |
| references/troubleshooting.md | "No data / wrong result / error" playbook |
| references/related-apis.md | |
| references/ram-policies.md | Minimum and complete RAM policies |
| references/cli-installation-guide.md | Aliyun CLI install, auth modes, profiles |
| references/regions.md | Region / endpoint configuration, internal endpoint, ProjectNotExist troubleshooting |
| references/acceptance-criteria.md | CLI invocation acceptance tests |
| Source-of-truth YAMLs bundled with this skill |
| 文档 | 描述 |
|---|---|
| references/query-analysis.md | 模式决策、索引搜索/SQL规则、扫描语义 |
| references/spl-guide.md | SPL管道语法、常用命令、字段处理 |
| references/functions-guide.md | 函数分类、SQL/SPL差异、模板 |
| references/troubleshooting.md | "无数据/结果错误/报错"排查手册 |
| references/related-apis.md | |
| references/ram-policies.md | 最小权限与完整RAM策略 |
| references/cli-installation-guide.md | Aliyun CLI安装、认证模式、配置文件 |
| references/regions.md | 区域/端点配置、内部端点、ProjectNotExist故障排查 |
| references/acceptance-criteria.md | CLI调用验收测试 |
| 本技能附带的权威YAML配置文件 |