Splunk Dev

Grouping Aggregate Queries Together

slierninja
Communicator

We want a grouping query showing user activity (page views) using a sliding window. What is the best way to build the query?

We would like to join the results of the following queries, but present the results as one set.

index="myIndex" host=myHost daysago=30 | stats Count by username

index="myIndex" host=myHost daysago=60 | stats Count by username

index="myIndex" host=myHost daysago=90 | stats Count by username

index="myIndex" host=myHost daysago=120 | stats Count by username

The output would look like...

Page Views by User in Last xx Days

+--------+--------+---------+---------+----------+
|  User  | 30 Day | 60 Days | 90 Days | 120 Days |
+--------+--------+---------+---------+----------+
| James  |     40 |      55 |      85 |       90 |
| Janet  |     10 |      25 |      30 |       60 |
| Walter |      0 |      15 |      25 |       45 |
+--------+--------+---------+---------+----------+
0 Karma
1 Solution

slierninja
Communicator

This seems to work, but is there a better way? Would selfjoin, timechart, or buckets be a better approach?

index="myIndex" host=myHost daysago=30 | stats Count as 30Days by username | 
join username [search index="myIndex" host=myHost daysago=60 | stats Count as 60Days by username] | 
join username [search index="myIndex" host=myHost daysago=90 | stats Count as 90Days by username] |
join username [search index="myIndex" host=myHost daysago=120 | stats Count as 120Days by username]|
fields username, 30Days, 60Days, 90Days, 120Days

View solution in original post

0 Karma

slierninja
Communicator

This seems to work, but is there a better way? Would selfjoin, timechart, or buckets be a better approach?

index="myIndex" host=myHost daysago=30 | stats Count as 30Days by username | 
join username [search index="myIndex" host=myHost daysago=60 | stats Count as 60Days by username] | 
join username [search index="myIndex" host=myHost daysago=90 | stats Count as 90Days by username] |
join username [search index="myIndex" host=myHost daysago=120 | stats Count as 120Days by username]|
fields username, 30Days, 60Days, 90Days, 120Days
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...