regex - 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)。
解决方案
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
) 或新消息。
推荐阅读
- dialogflow-es - 如何在日期是基本参数的情况下编写代理的意图?
- data-binding - 实时数据绑定
- python - 通过 ansible 中的 pip 将 python 要求安装到现有的 venv
- android - 从推送通知打开 Web 浏览器而不启动应用程序?
- batch-file - 如何通过另一个批处理文件更新一个批处理文件中的值
- python - TypeError:仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但有一个“RangeIndex”实例,我不知道为什么
- c++ - 使用月份值计算过去日期
- bash - ${##} 在 bash 中是什么意思?
- python - 需要具有嵌套 div 和跨度的高效 Beautifulsoup webscrape 到 pandas 数据框 python
- ibm-mq - 如何使用脚本检查远程队列管理器的队列深度?