Splunk SPL 关键字 函数 示例 (施工中。。。)

语法符号说明

必要参数显⽰在尖括号 < > 中。
可选参数显⽰在⽅括号 [ ] 中。


table

在查询结果中只展示对应字段。

示例

| table 字段1,字段2,字段3

stats

将查询结果进行聚合统计,类似 SQL 中的 group 。

示例

| stats count by 字段1,字段2

将查询结果按 字段1 和 字段2 分组,统计记录数量。


timechart

将查询结果以时间为 X 轴进行聚合统计 。

语法

timechart [sep=<string>] [format=<string>] [partial=<bool>] [cont=<bool>] [limit=<int>]
[agg=<stats-agg-term>] [<bin-options>...] ( (<single-agg> [BY <split-by-clause>] ) | (<eval-
expression>) BY <split-by-clause> )

示例

| timechart span=1h count by 字段

将查询结果按 字段 分组,统计每小时记录数。


筛选出前10000条日志作为查询结果。

示例

| head 10000

eval if in

示例

| eval 新字段=if(字段 in ("甲","乙","丙"),"结果1","结果2")

如果 字段 的值为"甲","乙","丙"中的任意一个,则 新字段 的值为"结果1",否则 新字段 的值为"结果2"。


iplocation

生成IP对应的地区信息,会在结果中加入 City、Country、lat、lon 和 Region 字段,用来表示日志中IP的所在地信息。

语法

iplocation [prefix=<string>] [allfields=<bool>] [lang=<string>] <ip-address-fieldname>

示例

| iplocation lang=zh ip
| table Country,City,ip

tstats

对加速数据模型进行统计查询。

语法

| tstats [prestats=<bool>] [local=<bool>] [append=<bool>] [summariesonly=<bool>]
[allow_old_summaries=<bool>] [chunk_size=<unsigned int>] <stats-func>...
[FROM ( <namespace> | sid=<tscollect-job-id> | datamodel=<data_model-name> )]
[WHERE <search-query> | <field> IN (<value-list>)]
[BY <field-list> [span=<timespan>] ]

示例

| tstats summariesonly=t count from datamodel=数据模型名 where 1=1

rex

用正则表达式在某个字段中提取新字段。

语法

rex [field=<field>] ( <regex-expression> [max_match=<int>] [offset_field=<string>] ) |
(mode=sed <sed-expression>)

示例

| rex field=_raw "正则1(?\<新字段名\>正则2)正则3" 

replace

将字段中的值替换为新值。可以使用通配符 * 进行模糊匹配

语法

replace (<wc-string> WITH <wc-string>)...[IN <field-list>]

示例

| replace "原值" with "新值" in 字段名

earliest latest

将查询结果控制在某个时间范围。
一般用于子查询或动态查询。

  • 现在:now
  • 2小时前:-2h@h
  • 1天前:-1d@d

示例

index=* earliest=-2h@h latest=now

posted @ 2020-07-20 08:47  太晓  阅读(1944)  评论(0编辑  收藏  举报