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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...