Skip to main content

Ali SLS日志 SQL 查询

日志整体统计分析

########################### resource 分组统计 ###########################
* | SELECT count(resource) as count ,resource ,date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day,resource order by day,count desc LIMIT 1000000
########################### resource 分组统计 ###########################

########################### user operation 分组统计 ###########################
* and resource: user | SELECT count(resource) as count, operation, date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day,operation order by day, count desc LIMIT 1000000
########################### user operation 分组统计 ###########################

########################### 特定IP operation 分组统计 ###########################
* and (ip :23.22.35.162 or ip: 3.224.220.101) | SELECT count(resource) as count, resource, operation, date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day, resource, operation order by day, count desc LIMIT 1000000
########################### 特定IP operation 分组统计 ###########################

########################### user 账号风控 分组统计 ###########################
* and resource: user and (operation : login* OR operation register*) | SELECT count(resource) as count, operation, date_trunc('month', created) AS day WHERE relative_id IS NOT null group by day,operation order by day, count desc LIMIT 1000000
########################### user 账号风控 分组统计 ###########################

用户日志查询分析

########################### 登录成功日志 ###########################
# 清单
* and resource: user and operation: login-result and message: success* | SELECT created,operation,relative_id,ip,resource,message WHERE relative_id IS NOT null LIMIT 1000000
# app清单
* and resource: user and operation: login-result and message: success* | SELECT created,operation,relative_id,ip,resource,message WHERE message like '%app%' LIMIT 1000000
# web清单
* and resource: user and operation: login-result and message: success* | SELECT created,operation,relative_id,ip,resource,message WHERE message like '%web%' LIMIT 1000000
# 数量统计(按天分组统计)
* and resource: user and operation: login-result and message: success* | SELECT count(resource) ,message,date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day,message order by day LIMIT 1000000
########################### 登录成功日志 ###########################

########################### 登录失败日志 ###########################
# 清单
* and resource: user and operation: login-result and message: Wrong* | SELECT created,operation,relative_id,ip,resource,message WHERE relative_id IS NOT null LIMIT 1000000
# 数量统计(按天分组统计)
* and resource: user and operation: login-result and message: Wrong* | SELECT count(resource) as count ,date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day order by day LIMIT 1000000
########################### 登录失败日志 ###########################


########################### 无效邮箱日志 ###########################
# 清单
* and resource: user and operation: login-result and message: Email* | SELECT created,operation,relative_id,ip,resource,message WHERE relative_id IS NOT null LIMIT 1000000
# 数量统计(按天分组统计)
* and resource: user and operation: login-result and message: Email* | SELECT count(resource) as count ,date_trunc('day', created) AS day WHERE relative_id IS NOT null group by day order by day LIMIT 1000000
########################### 无效邮箱日志 ###########################

全文查询

########################### 全文查询语法 ###########################
keyword1 [ [ and | or | not ] keywords2 ] ...

# 全文查询不针对具体的字段进行查询,其查询语法为:
# - keywords1 是需要查询的关键词,可以使用 *、?进行模糊匹配,也可以结合运算符如 and、or 等联合其他查询条件一起查询。
# - 案例1:希望查询关键词为 Nginx 相关的日志。则查询语句:Nginx。
# - 案例2:查询关键词为 Nginx 或 Tomcat 相关的日志。则查询语句:Nginx or Tomcat。
# - 案例3:期望查询域名为 aliyun.com 相关的日志。则查询语句为:*.aliyun.com。
########################### 全文查询语法 ###########################

字段查询

########################### 字段查询语法 ###########################
indexname1 [ : | > | >= | < | <= | = | in ] keyword1 [ [ and | or | not ] indexname2 ... ]

# 字段查询对应的字段类型包含text、long、double、JSON,且针对具体的字段进行查询,其查询语法为:
# - indexname1 是需要查询的字段名,当字段名、表名等专有名词中存在特殊字符(空格、中文等)、语法关键词(and、or等)等内容时,则需要使用""(双引号)包裹。在查询中使用引号,请参见如何在查询和分析语句中使用引号。
# - 字段索引涉及long、double类型,可以使用比较运算符>、>=、<、<=、=、in。
# - 案例1:希望查询 requestMethod 为 GET 相关的日志。则查询语法为:requestMethod: GET。
# - 案例2:希望查询 requestTimeSpend 大于 500ms 相关的日志。则查询语法为requestTimeSpend > 500(该字段索引类型为long)。
# - 案例3:希望查询 requestMethod 为 GET 且 requestTimeSpend 大于 500ms 相关的日志。则查询语法为:requestMethod: GET and requestTimeSpend > 500
########################### 字段查询语法 ###########################

阿里SLS 文档

group by

SELECT 
key,
...
aggregate function
GROUP BY
key,...

时间转换: