Skip to content
Back to skills

Alicloud Observability Sls Log Query

ASecurity

Query and troubleshoot logs in Alibaba Cloud Log Service (SLS) using query|analysis syntax and the Python SDK. Use for time-bounded log search, error investigation, and root-cause analysis workflows.

  • 21 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 7, 2026
toolspythongobash

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 8 files and shows the line behind each finding

Scanned September 7, 2026

npx -y skills add modbender/skill-library-mcp --skill alicloud-observability-sls-log-query --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Alicloud Observability Sls Log Query?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Alicloud Observability Sls Log Query
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/modbender-alicloud-observability-sls-log-query/badge)](https://www.skillsdirectory.com/skills/modbender-alicloud-observability-sls-log-query)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: alicloud-observability-sls-log-query
description: Query and troubleshoot logs in Alibaba Cloud Log Service (SLS) using query|analysis syntax and the Python SDK. Use for time-bounded log search, error investigation, and root-cause analysis workflows.
---

Category: service

# SLS 日志查询与排障

使用 SLS 的 query|analysis 语法与 Python SDK 做日志检索、过滤与统计分析。

## Prerequisites

- 安装 SDK(建议在虚拟环境中,避免 PEP 668 限制):

```bash
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -U aliyun-log-python-sdk
```
- 配置环境变量:
  - `ALIBABA_CLOUD_ACCESS_KEY_ID`
  - `ALIBABA_CLOUD_ACCESS_KEY_SECRET`
  - `SLS_ENDPOINT` (如 `cn-hangzhou.log.aliyuncs.com`)
  - `SLS_PROJECT`
  - `SLS_LOGSTORE`

## Query 组成

- 查询语句:用于过滤日志(如 `status:500`)。
- 分析语句:用于统计聚合,格式为 `查询语句|分析语句`。
- 示例:`* | SELECT status, count(*) AS pv GROUP BY status`

详细语法见 `references/query-syntax.md`。

## Quickstart (Python SDK)

```python
import os
import time
from aliyun.log import LogClient, GetLogsRequest

client = LogClient(
    os.environ["SLS_ENDPOINT"],
    os.environ["ALIBABA_CLOUD_ACCESS_KEY_ID"],
    os.environ["ALIBABA_CLOUD_ACCESS_KEY_SECRET"],
)

project = os.environ["SLS_PROJECT"]
logstore = os.environ["SLS_LOGSTORE"]

query = "status:500"
start_time = int(time.time()) - 15 * 60
end_time = int(time.time())

request = GetLogsRequest(project, logstore, start_time, end_time, query=query)
response = client.get_logs(request)
for log in response.get_logs():
    print(log.contents)
```

## Script quickstart

```bash
python skills/observability/sls/alicloud-observability-sls-log-query/scripts/query_logs.py \
  --query "status:500" \
  --last-minutes 15
```

Optional args: `--project`, `--logstore`, `--endpoint`, `--start`, `--end`, `--last-minutes`, `--limit`.

## Troubleshooting script

```bash
python skills/observability/sls/alicloud-observability-sls-log-query/scripts/troubleshoot.py \
  --group-field status \
  --last-minutes 30 \
  --limit 20
```

Optional args: `--error-query`, `--group-field`, `--limit`, plus the time range args above.

## Workflow

1) 确认 Logstore 已开启索引(未开启会导致查询/分析失败)。
2) 编写查询语句,必要时追加分析语句。
3) 通过 SDK 或脚本执行查询并查看结果。
4) 用 `limit` 控制返回行数,必要时缩小时间范围。

## References

- 语法与示例:`references/query-syntax.md`
- Python SDK 初始化与查询:`references/python-sdk.md`
- 排障模板:`references/templates.md`

- Source list: `references/sources.md`

Files in this skill

  • SKILL.md2.7 KB
  • agents/openai.yaml258 B
  • references/python-sdk.md451 B
  • references/query-syntax.md436 B
  • references/sources.md110 B
  • references/templates.md774 B
  • scripts/query_logs.py1.9 KB
  • scripts/troubleshoot.py2.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.