Splunk Search

conditional distinct count

zahmadian
Engager

Hello,

Is there a way I can merge these two searches into a single conditional search?

index="webs" (process_resource>0) AND (subs_id>0)| bucket _time span=1h |stats distinct_count(process_id) as NumProcesses by _time

index="webs" (process_resource==0) AND (subs_id>0)| bucket _time span=1h |stats distinct_count(process_id) as NumProcesses0 by _time

Tags (3)
0 Karma
1 Solution

sideview
SplunkTrust
SplunkTrust

I suspect you want something like this. It uses an eval command to make a new field on each event called "type". For each event the value will be either "zero" or "greater than zero", depending. Then we simply use timechart to render the chart you already had, except we split it by our new type field.

index="webs" (process_resource>=0) AND (subs_id>0) 
| eval type=if(process_resource==0,"zero","greater_than_zero") 
| timechart span=1h distinct_count(process_id) by type

View solution in original post

sideview
SplunkTrust
SplunkTrust

I suspect you want something like this. It uses an eval command to make a new field on each event called "type". For each event the value will be either "zero" or "greater than zero", depending. Then we simply use timechart to render the chart you already had, except we split it by our new type field.

index="webs" (process_resource>=0) AND (subs_id>0) 
| eval type=if(process_resource==0,"zero","greater_than_zero") 
| timechart span=1h distinct_count(process_id) by type

Runals
Motivator

index = webs process_resource>=0 subs_id>0 | bucket span=1h _time | stats dc(eval(process_resource>0)) as NumProcesses dc(eval(process_reaource=0)) as NumProcesses0 by _time

0 Karma

stephanefotso
Motivator

Here you go with appendcols!

index="webs" (process_resource>0) subs_id>0| bucket _time span=1h |stats distinct_count(process_id) as NumProcesses by _time|appendcols [search index="webs" (process_resource>0) subs_id>0| bucket _time span=1h |stats distinct_count(process_id) as NumProcesses0 by _time]|table _time NumProcesses NumProcesses0

SGF
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...