gpt4 book ai didi

how to sum of items of array field of Splunk row(Splunk行数组字段项求和)

转载 作者:bug小助手 更新时间:2023-10-25 11:48:32 24 4
gpt4 key购买 nike



I have following structure of data in Splunk. Each JSON block represents one splunk row or record

我在Splunk中有以下数据结构。每个JSON块代表一个Splunk行或记录



{
"startTime": "2023-09-09T05:10:16.2360649Z",
"version": "1.0.0",
"duration": 64,
"status": "Allow",
"method": "POST",
"recordId": "PF6ZN3ALJS9S",
"setSpans": [0.31, 0.98, 0.9, 0.49, 1.02, 1.07, 0.41, 0.5, 1.01, 0.99, 0.49],
"getSpans": [0.48, 1.76, 0.41, 0.31, 0.41, 0.31, 0.43, 0.91, 0.32, 0.4, 0.9]
}
{
"startTime": "2023-09-09T05:10:16.6549716Z",
"version": "1.0.0",
"duration": 34,
"status": "OK",
"method": "GET",
"recordId": "CU5WJKHHAAKM",
"setSpans": [1.04],
"getSpans": [0.46, 1.03, 0.41, 0.97, 0.41, 0.34, 0.94, 0.4, 0.39, 0.95]
}
{
"startTime": "2023-09-09T05:10:17.6927429Z",
"version": "1.0.0",
"duration": 75,
"status": "Allow",
"method": "POST",
"recordId": "764YR7FK7EZQ",
"setSpans": [0.98, 0.9, 1.04, 1.01, 0.99, 1.01, 1.0, 1.02],
"getSpans": [1.11, 1.82, 0.41, 0.31, 1.08, 0.37, 1.02, 0.33, 1.13, 0.9, 1.0, 0.93, 0.34, 0.33, 0.99, 0.9]
}

There are two fields setSpans and getSpans which are in the form of array. They have double numbers in array.

有两个字段setSpans和getSpans,它们都是数组形式的。它们在数组中有两个数字。


I need to calculate of sum of items of these arrays individually. I need to have an additional fields created using eval or something for each record so that I can perform stats or timechart on them.

我需要单独计算这些数组的项的总和。我需要有一个额外的领域创建使用评估或为每个记录的东西,以便我可以执行他们的统计数据或时间表。


or may be a table something like following.

或者可能是下面这样的一张桌子。


recordId      | totalSetSpan | totalGetSpan
-------------------------------------------
PF6ZN3ALJS9S | 7.68 | 5.74
-------------------------------------------
CU5WJKHHAAKM | 1.04 | 5.35
-------------------------------------------
764YR7FK7EZQ | 7.95 | 12.07

I need to be able to run query something like following.

我需要能够运行类似如下的查询。


... my search ... | ... eval or stats or something to get setSpanSum and getSpanSum... | timechart span=1m p99(setSpanSum)

I hope I am able to explain my issue properly. Any help or direction towards solving this will be a great help.

我希望我能够适当地解释我的问题。任何解决这个问题的帮助或方向都将是一个巨大的帮助。


更多回答
优秀答案推荐

Splunk can treat the JSON arrays as multi-value fields, but to add the contents of the multi-value fields you'll need the mvstats external command. Get from Splunkbase (https://splunkbase.splunk.com/app/5198) and install it. Then you can use this run-anywhere example as a guide.

Splunk可以将JSON数组视为多值字段,但是要添加多值字段的内容,您需要使用mvstats外部命令。从Sprint kbase(https://splunkbase.splunk.com/app/5198))获取并安装它。然后您可以使用这个随时随地运行的示例作为指南。


| makeresults format=json data="[ {
\"startTime\": \"2023-09-09T05:10:16.2360649Z\",
\"version\": \"1.0.0\",
\"duration\": 64,
\"status\": \"Allow\",
\"method\": \"POST\",
\"recordId\": \"PF6ZN3ALJS9S\",
\"setSpans\": [0.31, 0.98, 0.9, 0.49, 1.02, 1.07, 0.41, 0.5, 1.01, 0.99, 0.49],
\"getSpans\": [0.48, 1.76, 0.41, 0.31, 0.41, 0.31, 0.43, 0.91, 0.32, 0.4, 0.9]
},
{
\"startTime\": \"2023-09-09T05:10:16.6549716Z\",
\"version\": \"1.0.0\",
\"duration\": 34,
\"status\": \"OK\",
\"method\": \"GET\",
\"recordId\": \"CU5WJKHHAAKM\",
\"setSpans\": [1.04],
\"getSpans\": [0.46, 1.03, 0.41, 0.97, 0.41, 0.34, 0.94, 0.4, 0.39, 0.95]
},
{
\"startTime\": \"2023-09-09T05:10:17.6927429Z\",
\"version\": \"1.0.0\",
\"duration\": 75,
\"status\": \"Allow\",
\"method\": \"POST\",
\"recordId\": \"764YR7FK7EZQ\",
\"setSpans\": [0.98, 0.9, 1.04, 1.01, 0.99, 1.01, 1.0, 1.02],
\"getSpans\": [1.11, 1.82, 0.41, 0.31, 1.08, 0.37, 1.02, 0.33, 1.13, 0.9, 1.0, 0.93, 0.34, 0.33, 0.99, 0.9]
}]"
``` Above creates test data. Remove IRL ```
``` Convert the setSpans array into a Splunk multi-value field ```
| eval mvSetSpans=json_array_to_mv(setSpans, false())
``` Add the contents of the MV field ```
| mvstats sum mvSetSpans as totalSetSpan
``` Repeat for getSpans ```
| eval mvGetSpans=json_array_to_mv(getSpans, false())
| mvstats sum mvGetSpans as totalGetSpan
``` Display the results ```
| table recordId totalSetSpan totalGetSpan

更多回答

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com