Splunk Search

Group data on a query which results in table data after multiple splits.

npandit1020
Engager

I have a query which results in to a table data.

I want to group the data and the count column should sum of grouped data.

but this just results in total of all the fields in all the row and shows up against all the values as same sum.

 

example log:

2021-11-15 11:17:25.899 level=INFO com.a.b.MyClass - Average latency=0.0 someRandomCount=12800 mySearchValue=SearchValue1=167,SearchValue2=154,SearchValue3=163 // AppId=3ba33f54-4588-49f8-9702-bf957392a029 

 

my Query for this log is:

mySearchValue="*"
| rex "mySearchValue=(?<sValue>[^\"]+) //"
| eval field1=split( sValue,",")
| rex field=field1 "(?<Field1>[^\,]+)\=(?<Field2>[^\,]*)"
| eval c=mvzip(Field1,Field2)
| table Field1,Field2
| mvexpand c
| rename Field1 as "My Values"
| rename Field2 as "Count"

 

Note the string against "mySearchValue" in my log is not fixed to have 3 values, it can have any number different values. But the format of each one of them would be same : someString=123 (comma seperated).

 

The above queries sample result comes like below:

My ValuesCount
SearchValue1
SearchValue2
SearchValue3
167
154
163
SearchValue1
SearchValue2
SearchValue3
417
378
399

 

Each line is one row here, but the first section is extracted form first log encountered and splitted up in to rows then columns. and so on with other log lines.

 

I want this data to be grouped by My Values and sum respective Count values.

If I add : stats sum(Field2) AS "groupCount" by Field1

Then I do get distinct "My Values" but the count (for every row) comes out to be the same which is total of all values (in this case: 1678) .

Labels (3)
Tags (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| makeresults 
| eval _raw="2021-11-15 11:17:25.899 level=INFO com.a.b.MyClass - Average latency=0.0 someRandomCount=12800 mySearchValue=SearchValue1=167,SearchValue2=154,SearchValue3=163 // AppId=3ba33f54-4588-49f8-9702-bf957392a029"


| rex "mySearchValue=(?<sValue>[^\"]+) //"
| eval field1=split( sValue,",")
| mvexpand field1
| rex field=field1 "(?<Field1>[^\,]+)\=(?<Field2>[^\,]*)"
| stats sum(Field2) as total by Field1

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| makeresults 
| eval _raw="2021-11-15 11:17:25.899 level=INFO com.a.b.MyClass - Average latency=0.0 someRandomCount=12800 mySearchValue=SearchValue1=167,SearchValue2=154,SearchValue3=163 // AppId=3ba33f54-4588-49f8-9702-bf957392a029"


| rex "mySearchValue=(?<sValue>[^\"]+) //"
| eval field1=split( sValue,",")
| mvexpand field1
| rex field=field1 "(?<Field1>[^\,]+)\=(?<Field2>[^\,]*)"
| stats sum(Field2) as total by Field1
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...