Splunk Search

How to count number of events in a search result?

echojacques
Builder

The objective of this search is to count the number of events in a search result. This is the current search logic that I am using (which uses the linecount command):

sourcetype="my_source" filter_result="hello_world" | stats sum(linecount) as Total

Is there an "eventcount" command that simply counts the number of events that I can use instead of "linecount"? The reason is that linecount sometimes over-counts some results (i.e. it will count 100 when there are actually only 75 events).

Thanks!

Tags (2)
1 Solution

gfuente
Motivator

Hello

Linecount is the number of lines per event

I guess you are looking for something like:

sourcetype="my_source" filter_result="hello_world" | stats count as Total

Regards

View solution in original post

bbialek
Path Finder

Here is a way to count events per minute if you search in hours:

* | timechart count(_raw) span=1h

stevenatmit
Explorer

I finally found something that works, but it is a slow way of doing it.

index=* [|inputcsv allhosts.csv] | stats count by host | stats count AS totalReportingHosts| appendcols [| inputlookup allhosts.csv | stats count AS totalAssets]

gfuente
Motivator

Hello

Linecount is the number of lines per event

I guess you are looking for something like:

sourcetype="my_source" filter_result="hello_world" | stats count as Total

Regards

echojacques
Builder

Yes, this is exactly what I was looking for. I just tested it and it works. Thank you!

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...