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!

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...