Splunk Search

How to join two searches?

skphi13
New Member

I need help joining the following 2 searches.

Search 1:

app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan | stats avg(*responseTime) by date_mday

Search 2:

app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan statusCode=200 | stats avg(*responseTime) by date_mday

I tried using Join and Append but it's no working.

Tags (2)
0 Karma
1 Solution

jplumsdaine22
Influencer

Assuming all your events have a status code, you can do it one:

app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan statusCode=* 
|  eventstats sum(*responseTime) as total* count as count_events by date_mday
|  where status=200
| stats max(total*) as total* max(count_events) as count_events avg(*responseTime) as avg_*responseTime_200 by status date_mday
|  foreach total* 
    [eval <<FIELD>>=<<FIELD>>/count_events]
|  rename total* as avg*_all_status

View solution in original post

0 Karma

jplumsdaine22
Influencer

You should see something like this:alt text

0 Karma

jplumsdaine22
Influencer

Assuming all your events have a status code, you can do it one:

app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan statusCode=* 
|  eventstats sum(*responseTime) as total* count as count_events by date_mday
|  where status=200
| stats max(total*) as total* max(count_events) as count_events avg(*responseTime) as avg_*responseTime_200 by status date_mday
|  foreach total* 
    [eval <<FIELD>>=<<FIELD>>/count_events]
|  rename total* as avg*_all_status
0 Karma

skphi13
New Member

this is what i get alt text

0 Karma

skphi13
New Member

Yes all event should have a status code. When i tried running this, nothing shows up.

0 Karma

jplumsdaine22
Influencer

Ah sorry in my test search I had just status. Change status to statsCode and you should be good to go

0 Karma

skphi13
New Member

so it does return events but no statistics or visualization.

0 Karma

jplumsdaine22
Influencer

Er that has a stats command in there, it can't return events unless you're running in verbose mode, in which case just switch to the relevant tab

0 Karma

skphi13
New Member

i switch it to smart mode and ran the search again and nothing. I even change the timeframe to the last 7 days. I have posted the picture of the results but it's awaiting moderator approval.

0 Karma

skphi13
New Member

it's showing 0 events, but i know that's incorrect

0 Karma

jplumsdaine22
Influencer

OK, step back through the search.

ie I assume you get events for this:

 app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan statusCode=* 

So just keep adding the search commands until you find the one that breaks it. Most likely it is a misnamed field

0 Karma

skphi13
New Member

so i ran the following in smart mode

app="atlas" source="/usr/local/homeaway/atlas-production/logs/" index="aws_prod_applogs" titan statusCode= | eventstats sum(responseTime) as total count as count_events by date_mday

It returns a bunch of events but no stats...

0 Karma

jplumsdaine22
Influencer

Eventstats will add the stats to each event - this is so you can calculate the averages of all events even after dropping the others

0 Karma

skphi13
New Member

yea so when i ran the serach with eventstats no statistics show up in the results. But when i ran it with stats the statistics shows up in the result.

0 Karma

jplumsdaine22
Influencer

See in the stats command you have by status

Change that to statusCode

0 Karma

skphi13
New Member

it works! thanks for pointing out that small details.

0 Karma

hortonew
Builder

I believe with stats you need appendcols not append. For instance:

| appendcols [search app="atlas" source="/usr/local/homeaway/atlas-production/logs/*" index="aws_prod_applogs" titan statusCode=200 | stats avg(*responseTime) by date_mday]

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...