Knowledge Management

count events by index and by sourcetype from an inputlookup

jip31
Motivator

hello

I need to count the events generated by index and by sourcetype from an host list (csv file)
It seems to work but its very very long
how to do this with better performances please??

index=toto
| join host type="outer"
[| inputlookup host.csv]
| stats count by sourcetype

Tags (1)
0 Karma
1 Solution

niketn
Legend

@jip31 try the following search based on tstats which should run much faster.

| tstats count where index=toto [| inputlookup hosts.csv | table host ] by sourcetype

Following is a run anywhere example based on Splunk's _internal index.

| tstats count where index=_internal 
    [| tstats count where index=_internal by sourcetype 
    | search sourcetype IN ("splunkd*") 
    | table sourcetype] by host sourcetype
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@jip31 try the following search based on tstats which should run much faster.

| tstats count where index=toto [| inputlookup hosts.csv | table host ] by sourcetype

Following is a run anywhere example based on Splunk's _internal index.

| tstats count where index=_internal 
    [| tstats count where index=_internal by sourcetype 
    | search sourcetype IN ("splunkd*") 
    | table sourcetype] by host sourcetype
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

FrankVl
Ultra Champion

Use tstats to count the index contents:

| tstats count where index=toto by sourcetype,host
| join host type=outer [
| inputlookup host.csv
]

niketn
Legend

@FrankVl you beat me to it. I have slightly different answer, but that also involves sub-search.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

FrankVl
Ultra Champion

Yours filters the tstats results with the lookup list, it doesn't show the lookup entries that do not occur in the index and vice versa (which his original search with outer join does). So that's why I tried to stay as close as possible to his existing search.

If filtering is all you need, your solution would indeed also work.

Since he does a stats count by sourcetype in the end, he might actually be destroying the hosts that are only in the lookup anyway (unless that lookup also contains sourcetype field).

Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...