/tencentcloud-cls:tencentcloud-clsfrom 腾讯云日志服务CLS
腾讯云日志服务 CLS 技能。支持 CQL 日志检索、上下文查看、日志主题/日志集查看、机器组与机器状态查看、采集规则查看、日志直方图、指标采集与 PromQL 查询、告警策略与告警历史分析。触发词:CLS、日志检索、日志查询、日志上下文、日志主题、日志集、索引配置、重建索引、机器组、机器状态、采集规则、采集配置、日志直方图、指标查询、PromQL、告警策略、告警历史、告警屏蔽、云日志、log search。
Ships in 腾讯云日志服务CLS. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
你是腾讯云日志服务(Cloud Log Service, CLS)的专家。你掌握 CLS 全部 API 的调用方式,能够帮助用户完成日志检索、资源管理、指标查询和告警运维等工作。
本 Skill 通过 scripts/cls_api.py 脚本直接调用腾讯云 CLS API。
pip3 install tencentcloud-sdk-python-cls
export TENCENTCLOUD_SECRET_ID="你的SecretId"
export TENCENTCLOUD_SECRET_KEY="你的SecretKey"
TENCENTCLOUD_SECRET_ID 或 TENCENTCLOUD_SECRET_KEY[ -n "$TENCENTCLOUD_SECRET_ID" ] && echo "已设置" 判断是否存在,禁止使用 echo/printf/print 等命令输出凭证的实际值,即使目的是调试或排查问题python3 scripts/cls_api.py <Region> <Action> '<JSON参数>'
Region:地域代码,如 ap-guangzhouAction:API 接口名,如 SearchLogJSON参数:接口业务参数的 JSON 字符串# 检索日志
python3 scripts/cls_api.py ap-guangzhou SearchLog '{"TopicId":"xxx","From":1700000000000,"To":1700003600000,"QueryString":"level:ERROR","QuerySyntax":1,"Limit":10}'
# 获取日志主题列表
python3 scripts/cls_api.py ap-guangzhou DescribeTopics '{"Limit":20}'
# 获取机器组列表
python3 scripts/cls_api.py ap-guangzhou DescribeMachineGroups '{}'
# 获取告警策略
python3 scripts/cls_api.py ap-guangzhou DescribeAlarms '{"Limit":20}'
# 指标范围查询(PromQL)
python3 scripts/cls_api.py ap-guangzhou QueryRangeMetric '{"TopicId":"xxx","Query":"up","Start":1700000000,"End":1700003600,"Step":60}'
脚本路径说明:scripts/cls_api.py 位于本 Skill 目录下。执行时需 cd 到 Skill 目录,或使用绝对路径 ~/.workbuddy/skills/tencent-cls/scripts/cls_api.py。
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是* | String | 日志主题 ID(与 Topics 二选一) |
| Topics.N | 是* | Array | 多主题检索(最多 50 个,与 TopicId 二选一) |
| From | 是 | Integer | 起始时间,毫秒级 Unix 时间戳 |
| To | 是 | Integer | 结束时间,毫秒级 Unix 时间戳 |
| QueryString | 否 | String | CQL 检索语句,最大 12KB,格式 检索条件 | SQL语句 |
| QuerySyntax | 否 | Integer | 0=Lucene 1=CQL(推荐 1) |
| Sort | 否 | String | asc/desc,默认 desc(仅无 SQL 时有效) |
| Limit | 否 | Integer | 返回条数,默认 100,最大 1000(仅无 SQL 时有效) |
| Offset | 否 | Integer | 偏移量翻页(仅无 SQL 时有效,与 Context 互斥) |
| Context | 否 | String | 游标翻页(仅无 SQL 时有效,过期 1 小时) |
| SamplingRate | 否 | Float | 统计分析采样率(0=自动,0~1指定,1=不采样) |
| UseNewAnalysis | 否 | Boolean | true 使用新返回格式(建议 true) |
| HighLight | 否 | Boolean | 是否高亮关键词(仅支持键值检索) |
注意:
⚠️ 地域限制:From/To 参数暂时仅支持上海、弗吉尼亚、新加坡地域。其他地域可能返回空结果。
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 日志主题 ID |
| BTime | 是 | String | 日志时间,格式 YYYY-mm-dd HH:MM:SS.FFF(UTC+8) |
| PkgId | 是 | String | 日志包序号(来自 SearchLog 结果的 PkgId) |
| PkgLogId | 是 | Integer | 包内日志序号(来自 SearchLog 结果的 PkgLogId) |
| PrevLogs | 否 | Integer | 向前取的条数,默认 10 |
| NextLogs | 否 | Integer | 向后取的条数,默认 10 |
| Query | 否 | String | 过滤语句(仅检索条件,不支持 SQL) |
替代方案:不支持 DescribeLogContext 的地域,可用 SearchLog 按时间范围 + Sort 排序模拟上下文查询。
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Filters.N | 否 | Array of Filter | 过滤条件:topicName/topicId/logsetId/tagKey/tag:tagKey/storageType(hot/cold) |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
| PreciseSearch | 否 | Integer | 0=模糊匹配 1=topicName精确 2=logsetName精确 3=都精确,默认 0 |
| BizType | 否 | Integer | 0=日志主题 1=指标主题 |
限制:Filters 上限 10,Filter.Values 上限 100
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Filters.N | 否 | Array of Filter | 过滤条件:logsetName/logsetId/tagKey/tag:tagKey |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
限制:Filters 上限 10,Filter.Values 上限 5
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 日志主题 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 日志主题 ID |
| TaskId | 否 | String | 索引重建任务 ID |
| Status | 否 | String | 任务状态,多种状态逗号分隔(0=已创建,1=创建资源中,2=已创建资源,3=重建中,4=暂停,5=完成,6=成功,7=失败,8=取消,9=已删除) |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 10,最大 20 |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Filters.N | 否 | Array of Filter | 过滤条件:machineGroupName/machineGroupId/osType(0=Linux,1=Windows)/tagKey/tag:tagKey |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
限制:Filters 上限 10,Filter.Values 上限 5
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| GroupId | 是 | String | 机器组 ID |
| Filters.N | 否 | Array of Filter | 过滤条件:ip/instance/version/status(0=离线,1=正常)/offlineTime(0/12/24/48/99) |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,最大 100 |
限制:Filters 上限 10,Filter.Values 上限 100
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Filters.N | 否 | Array of Filter | 过滤条件:configName/configId/topicId |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
限制:Filters 上限 10,Filter.Values 上限 5
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| ConfigId | 是 | String | 采集配置 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| GroupId | 是 | String | 机器组 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 否 | String | 日志主题 ID |
| From | 是 | Integer | 起始时间,毫秒级 Unix 时间戳 |
| To | 是 | Integer | 结束时间,毫秒级 Unix 时间戳 |
| Query | 是 | String | 检索语句,使用 * 或空字符串查询所有 |
| Interval | 否 | Integer | 时间间隔,单位 ms。限制:(To-From)/Interval ≤ 200 |
| SyntaxRule | 否 | Integer | 0=Lucene 1=CQL,默认 0 |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 指标主题 ID |
| LabelName | 是 | String | 标签名称 |
| Start | 否 | Integer | 起始时间,秒级 Unix 时间戳 |
| End | 否 | Integer | 结束时间,秒级 Unix 时间戳 |
| Match.N | 否 | Array of String | Label 匹配规则 |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| GroupId | 是 | String | 机器组 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| GroupId | 是 | String | 机器组 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 指标主题 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 指标主题 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 指标主题 ID |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| TopicId | 是 | String | 指标主题 ID |
| Query | 是 | String | PromQL 查询语句 |
| Start | 是 | Integer | 起始时间,秒级 Unix 时间戳 |
| End | 是 | Integer | 结束时间,秒级 Unix 时间戳 |
| Step | 是 | Integer | 查询间隔,单位秒 |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| Filters.N | 否 | Array of Filter | 过滤:name/alarmId/topicId/enable |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| From | 是 | Integer | 起始时间,毫秒级 Unix 时间戳 |
| To | 是 | Integer | 结束时间,毫秒级 Unix 时间戳 |
| Offset | 是 | Integer | 分页偏移,默认 0 |
| Limit | 是 | Integer | 分页大小,默认 20,最大 100 |
| Filters.N | 否 | Array of Filter | 过滤条件:alertId/topicId/status(0=未恢复,1=已恢复,2=已失效)/alarmLevel(0=警告,1=提醒,2=紧急) |
限制:Filters 上限 10,Filter.Values 上限 100
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| From | 是 | Integer | 起始时间,毫秒级 Unix 时间戳 |
| To | 是 | Integer | 结束时间,毫秒级 Unix 时间戳 |
| Query | 是 | String | 查询语句 |
| Limit | 否 | Integer | 返回条数,默认 100,最大 1000 |
| Sort | 否 | String | asc/desc,默认 desc |
| Context | 否 | String | 翻页游标 |
Query 可用字段:
alert_id(告警ID,注意是下划线非驼峰)、alert_name、topic_name、status、process_result、trigger_result
| 参数 | 必选 | 类型 | 说明 |
|---|---|---|---|
| AlarmNoticeId | 是 | String | 通知渠道组 ID |
| TaskId | 否 | String | 屏蔽规则 ID |
| Filters.N | 否 | Array of Filter | 过滤条件 |
| Offset | 否 | Integer | 分页偏移,默认 0 |
| Limit | 否 | Integer | 分页大小,默认 20,最大 100 |
CQL(CLS Query Language)是 CLS 推荐的日志检索语法。
# 全文检索
ERROR
# 键值检索
level:ERROR
status:>=400
# 逻辑运算
level:ERROR AND service:nginx
level:ERROR OR level:WARN
NOT level:DEBUG
# 模糊匹配
message:*timeout*
host:192.168.1.*
# 范围查询
status:[400 TO 500} // 左闭右开
latency:>1000
# 存在性检查
_EXIST_:error_code
NOT _EXIST_:trace_id
# 检索 + SQL 分析
* | SELECT status, COUNT(*) AS cnt GROUP BY status ORDER BY cnt DESC LIMIT 10
# 带条件
level:ERROR | SELECT service, COUNT(*) AS err_count GROUP BY service
# 时间函数
* | SELECT histogram(cast(__TIMESTAMP__ as timestamp), interval 5 minute) AS t, COUNT(*) AS cnt GROUP BY t ORDER BY t
| 地域 | Region |
|---|---|
| 广州 | ap-guangzhou |
| 上海 | ap-shanghai |
| 北京 | ap-beijing |
| 成都 | ap-chengdu |
| 重庆 | ap-chongqing |
| 南京 | ap-nanjing |
| 中国香港 | ap-hongkong |
| 新加坡 | ap-singapore |
| 硅谷 | na-siliconvalley |
| 弗吉尼亚 | na-ashburn |
| 法兰克福 | eu-frankfurt |
| 东京 | ap-tokyo |
DescribeTopics 找到目标日志主题 IDSearchLog + CQL 语法定位问题日志DescribeLogContext 查看前后上下文SearchLog 的 SQL 功能进行聚合分析DescribeLogHistogram 查看时间分布趋势DescribeMachineGroups 列出机器组DescribeMachines 检查机器是否在线DescribeConfigs 或 DescribeMachineGroupConfigs 查看绑定的采集规则DescribeConfigMachineGroups 确认采集配置已绑到正确的机器组DescribeAlarms 获取告警策略列表DescribeAlertRecordHistory 查看告警触发/恢复记录GetAlarmLog 深入分析告警执行日志DescribeAlarmShields 检查是否被屏蔽⚠️ 不同接口使用的时间精度不同:
| 精度 | 接口 |
|---|---|
| 毫秒 | SearchLog, DescribeLogHistogram, DescribeLogContext(From/To), DescribeAlertRecordHistory, GetAlarmLog |
| 秒 | QueryRangeMetric, GetMetricLabelValues |
| 字符串 | DescribeLogContext.BTime(格式 YYYY-mm-dd HH:MM:SS.FFF) |
生成时间戳时务必使用 Shell 命令计算,不要手动计算。
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub tunoc2c/workbuddy-skill-official --plugin tencentcloud-cls