首页 > 解决方案 > If 语句和提取值

问题描述

我有一个看起来像的结果集

{add=[44961373 (1645499799657512961), 44961374 (1645499799658561538), 44962094 (1645499799659610114), 44962095 (1645499799659610117), 44962096 (1645499799660658689), 44962097 (1645499799660658691), 44962098 (1645499799661707264), 44962099 (1645499799661707267), 44962100 (1645499799662755840), 44962101 (1645499799662755843), ... (592 adds)]}

如果 add=[ 数组中有超过 10 个元素。然后它将 (x 添加) 放在语句的末尾以显示有多少实际添加。如果它少于 10,那么它不会放 (x 添加) 语句。我想要时间表以及将这些输出单值到仪表板(单独的模块)。

我可以得到一个或另一个,但我想使用逻辑来确定要报告哪一个。

index="index" host="host*" path=/update | eval count=mvcount(add) | stats count

将获得数组的计数

index="index" host="host*"  path=/update | stats sum(Adds)

将获得 (x 添加) 的值。添加是一个“提取的字段”。

我如何得到或?如果添加数组 >10,请同时使用 sum(Adds)。

标签: regexextractsplunksplunk-query

解决方案


index="index" host="host*" path=/update | eval count=mvcount(add)
| eval first_ten="{add=[".mvjoin(mvindex(add,0,9), ",")." (" (count-10)." adds)}"
| eval msg=if(count<10,_raw,first_ten)

你可以做这样的事情。获取 的计数adds,创建一个仅包含前 10 个元素的新字符串,并count-10 adds在末尾添加消息。然后,根据实际计数,使用原始消息 ( _raw) 或新消息。


推荐阅读