Splunk Search

2 searches, 1 csv

casspugh
Explorer

Hello,

I have searched around, but I haven't found an example that has shown me the way.

What I am trying to do is a search on one location, and compare the stats with another location.

Here are the two searches:

host="server01" OR host="server03" source="/opt/httpd/logs/access_log"  | stats count by status | rename count AS countA

and

host="server13" OR host="server14" source="/data/logs/apache/access_log" | stats count by status | rename count AS countB

I would like to output this information to a csv file that would look like this, using the static error code as one column, and then the variables countA and countB:

status,countA,countB
200,563805,6345
206,10,1345
301,33529,345
302,84470,673468
304,1747,46
400,42,23
403,36,346
404,25,46
500,29,45
502,2,345

The best that I was able to do was to get them all into the file, with duplicate entries for the status codes...

Any ideas?

Tags (1)
0 Karma
1 Solution

casspugh
Explorer

OK - this post helped me.

http://splunk-base.splunk.com/answers/51740/comparing-results-from-two-searches/62359

I was able to use this search to obtain the result I wanted. It takes about 45s to run though, so if anyone has a better idea, I am all ears!

host="server01" OR host="server03" source="/opt/httpd/logs/access_log"  | stats count by status | rename count AS countA | appendcols [ search ( host="server13" OR host="server14" source="/data/logs/apache/access_log"  )| stats count by status | rename count AS countB ] | outputcsv combinedstats.csv

View solution in original post

0 Karma

casspugh
Explorer

OK - this post helped me.

http://splunk-base.splunk.com/answers/51740/comparing-results-from-two-searches/62359

I was able to use this search to obtain the result I wanted. It takes about 45s to run though, so if anyone has a better idea, I am all ears!

host="server01" OR host="server03" source="/opt/httpd/logs/access_log"  | stats count by status | rename count AS countA | appendcols [ search ( host="server13" OR host="server14" source="/data/logs/apache/access_log"  )| stats count by status | rename count AS countB ] | outputcsv combinedstats.csv
0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Since they are over the same time range, append would work. If you find there are more than 1 value for each status and count (ex. 13 and 402 for countA with status 500) you can replace values() with max() or latest().

host="server01" OR host="server03" source="/opt/httpd/logs/access_log" | stats count by status | rename count AS countA | append[ search host="server13" OR host="server14" source="/data/logs/apache/access_log" | stats count by status | rename count AS countB ] | stats values(countA) as countA values(countB) as countB by status

casspugh
Explorer

Thanks! This does work too! I will compare the two searches to see if there are any differences!

0 Karma
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!

Monitoring AI Agents with Splunk Observability Cloud

Let’s say I’m running a travel planning AI app in production. A user asks for three concise hotel options in ...

[Puzzles] Solve, Learn, Repeat: Tiling

This puzzle (first published here) is based on finding groups of tessellated tiles (inspired by floor tiles I ...

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...