Splunk Search

Splitting up data into multiple columns

eb1929
Explorer

Hello i am using the following search 

host=XXX sourcetype=ZZZ http_status=500 OR http_status=502 "HighCostAPI"
| stats count by http_status, _time, pzInsKey
| fields http_status _time pzInsKey count
| addcoltotals count

I get the following results 

eb1929_0-1610048280317.png

Which is what we wanted originally, now the customer would like to have a count for the 500 errors and the 502 errors separately. I guess it wouldn't be necessary to split the http_status into 2 columns just as long as i can have a count for both.   

Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@eb1929 

You can use the appendpipe command to put 'subtotals' between the different status values like this

host=XXX sourcetype=ZZZ http_status=500 OR http_status=502 "HighCostAPI"
| stats count by http_status, _time, pzInsKey
| fields http_status _time pzInsKey count
| appendpipe [
  | stats sum(count) as count by http_status
  | eval pzInsKey="Total - Status code ".http_status
]
| sort http_status

which will give you a subtotal row with count as the total for the status. Note that the appendpipe also sets the pzInsKey field to a simple text string to indicate total.

In your dashboard you can then use a technique to highlight that subtotal row. (See dashboard examples Table Row Highlighting) for how to do that.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@eb1929 

You can use the appendpipe command to put 'subtotals' between the different status values like this

host=XXX sourcetype=ZZZ http_status=500 OR http_status=502 "HighCostAPI"
| stats count by http_status, _time, pzInsKey
| fields http_status _time pzInsKey count
| appendpipe [
  | stats sum(count) as count by http_status
  | eval pzInsKey="Total - Status code ".http_status
]
| sort http_status

which will give you a subtotal row with count as the total for the status. Note that the appendpipe also sets the pzInsKey field to a simple text string to indicate total.

In your dashboard you can then use a technique to highlight that subtotal row. (See dashboard examples Table Row Highlighting) for how to do that.

 

eb1929
Explorer

That works thank you!!!

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @eb1929,

You can count http_status codes separately like below;

host=XXX sourcetype=ZZZ http_status=500 OR http_status=502 "HighCostAPI"
| eval status_500=if(http_status==500,1,0)
| eval status_502=if(http_status==502,1,0)
| stats sum(status_500) as status_500 sum(status_502) as status_502 count by http_status, _time, pzInsKey
| fields http_status _time pzInsKey status_500 status_502 count
| addcoltotals status_500 status_502 count

 

If this reply helps you an upvote is appreciated.

If this reply helps you an upvote and "Accept as Solution" is appreciated.

eb1929
Explorer

This one worked as well thank you both for this!!!

0 Karma
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...