← 返回
数据分析 Key 中文

Tencent Cloud Log Service

Query and analyze Tencent Cloud CLS logs
查询并分析腾讯云 CLS 日志
dbwang0130
数据分析 clawhub v0.1.0 1 版本 99851.9 Key: 需要
★ 1
Stars
📥 2,002
下载
💾 0
安装
1
版本
#latest

概述

CLS Skill

Query and analyze Tencent Cloud CLS logs.

Setup

  1. Install clscli (Homebrew):

```bash

brew tap dbwang0130/clscli

brew install dbwang0130/clscli/clscli

```

  1. Get credentials and region list: https://cloud.tencent.com/document/api/614/56474
  2. Set environment variables (same as Tencent Cloud API common parameters):

```bash

export TENCENTCLOUD_SECRET_ID="your-secret-id"

export TENCENTCLOUD_SECRET_KEY="your-secret-key"

```

  1. Specify region via --region (e.g. ap-guangzhou).

Usage

!IMPORTANT: If you do not know the log topic, list topics first.

List log topics

List topics in a region to determine which --region and topic ID to use for query/context.

clscli topics --region <region> [--topic-name name] [--logset-name name] [--logset-id id] [--limit 20] [--offset 0]

Examples: --output=json, --output=csv, -o topics.csv

OptionRequiredDescription
-------------------------------
--regionyesCLS region, e.g. ap-guangzhou
--topic-namenoFilter by topic name (fuzzy match)
--logset-namenoFilter by logset name (fuzzy match)
--logset-idnoFilter by logset ID
--limitnoPage size, default 20, max 100
--offsetnoPagination offset, default 0
--output, -onoOutput: json, csv, or file path

Output columns: Region, TopicId, TopicName, LogsetId, CreateTime, StorageType.

Get log by query

clscli query -q "[query condition] | [SQL statement]" --region <region> -t <TopicId> --last 1h

Examples:

  • Time: --last 1h, --last 30m; or --from/--to (Unix ms)
  • Multiple topics: --topics , or multiple -t
  • Auto pagination and cap: --max 5000 (paginate until 5000 logs or ListOver)
  • Output: --output=json, --output=csv, -o result.json (write to file)
OptionRequiredDescription
-------------------------------
--regionyesCLS region, e.g. ap-guangzhou
-q, --queryyesQuery condition or SQL, e.g. level:ERROR or `* \select count(*) as cnt`
-t, --topicone of -t/--topicsSingle log topic ID
--topicsone of -t/--topicsComma-separated topic IDs, max 50
--lastone of --last/--from/--toTime range, e.g. 1h, 30m, 24h
--from, --toone of --last/--from/--toStart/end time (Unix ms)
--limitnoLogs per request, default 100, max 1000
--maxnoMax total logs; when non-zero, auto-paginate until reached or ListOver
--output, -onoOutput: json, csv, or file path
--sortnoSort: asc or desc, default desc

Query condition syntax

Two syntaxes are supported:

  • CQL (CLS Query Language): CLS-specific query syntax for logs, easy to use, recommended.
  • Lucene: Open-source Lucene syntax; not designed for log search, has more restrictions on special chars, case, wildcards; not recommended.
CQL syntax
SyntaxDescription
---------------------
key:valueKey-value search; logs where field (key) contains value, e.g. level:ERROR
valueFull-text search; logs containing value, e.g. ERROR
ANDLogical AND, case-insensitive, e.g. level:ERROR AND pid:1234
ORLogical OR, case-insensitive, e.g. level:ERROR OR level:WARNING, level:(ERROR OR WARNING)
NOTLogical NOT, case-insensitive, e.g. level:ERROR NOT pid:1234, level:ERROR AND NOT pid:1234
()Grouping for precedence, e.g. level:(ERROR OR WARNING) AND pid:1234. Note: AND has higher precedence than OR when no parentheses.
" "Phrase search; double-quoted string, words and order must match, e.g. name:"john Smith". No logical operators inside phrase.
' 'Phrase search; single quotes, same as ""; use when phrase contains double quotes, e.g. body:'user_name:"bob"'
*Wildcard; zero or more chars, e.g. host:www.test*.com. No prefix wildcard.
>, >=, <, <=, =Range operators for numeric values, e.g. status>400, status:>=400
\Escape; escaped char is literal. Escape space, :, (), >, =, <, ", ', * in values.
key:*text: field exists (any value). long/double: field exists and is numeric, e.g. response_time:*
key:""text: field exists and is empty. long/double: value is not numeric or field missing, e.g. response_time:""

SQL statement syntax

SyntaxDescription
---------------------
SELECTSelect from table; data from current log topic matching query condition
ASAlias for column (KEY)
GROUP BYWith aggregate functions, group by one or more columns (KEY)
ORDER BYSort result set by KEY
LIMITLimit rows, default 100, max 1M
WHEREFilter raw data
HAVINGFilter after GROUP BY, before ORDER BY; WHERE filters raw data
Nested subqueryOne SELECT inside another for multi-step analysis
SQL functionsRicher analysis: IP geo, time format, string split/join, JSON extract, math, distinct count, etc.

Describe log context

Retrieve log context around a given log.

clscli context <PkgId> <PkgLogId> --region <region> -t <TopicId>

Examples: --output=json, --output=csv, -o context.json (write to file)

OptionRequiredTypeDescriptionExample
----------------------------------------------
--regionyesStringCLS regionap-guangzhou
-t, --topicyesStringLog topic ID-
PkgIdyesStringLog package ID, i.e. SearchLog Results[].PkgId528C1318606EFEB8-1A7
PkgLogIdyesIntegerIndex within package, i.e. SearchLog Results[].PkgLogId65536
--output, -ono-Output: json, csv, or file path-

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-28 18:39 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 368 📥 140,510
data-analysis

Stock Analysis

udiedrichsen
{"answer":"基于雅虎财经数据,分析股票与加密货币。支持投资组合管理、自选股预警、股息分析、8维评分、热门趋势扫描及传闻/早期信号探测。适用于股票分析、持仓追踪、财报异动、加密监控、热门股追踪或提前发掘非主流传闻。"}
★ 270 📥 56,983
data-analysis

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 165 📥 60,044