Splunk Search

Need count for fields value

rakesh44
Communicator

Hi Friends,

I have two field component and eventtype, need count of component=root and component=Metrics and venttype=splunkd-log and eventtype=splunkd-access .

Am using below command but getting count of components only not eventtype, morover my data is big can we used tstats command in such case.Thanks

index="_internal" component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access | stats count by component

Tags (1)
0 Karma
1 Solution

rakesh44
Communicator

index="_internal" component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access | stats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count

If you want to improve performance use below command ( Both command are working fine )

| tstats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count count from datamodel=internal_server WHERE component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access

View solution in original post

0 Karma

rakesh44
Communicator

index="_internal" component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access | stats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count

If you want to improve performance use below command ( Both command are working fine )

| tstats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count count from datamodel=internal_server WHERE component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rakesh44

Can you please try this search for performace?

| tstats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count count from datamodel=internal_server WHERE component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access
0 Karma

rakesh44
Communicator

Thanks Kamlesh for quick reply

Tried with given command , but ending with error

Error in 'TsidxStats': The tstats / mstats command cannot apply eval function to aggregation function.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rakesh44

It's working for me in Splunk 7.2.3. Check below link.

https://drive.google.com/open?id=1DCEOpNokZBA6OLW6m7MxgJYVZFPcmvzz

Can you please share your search if you have changed and Splunk version information?

0 Karma

rakesh44
Communicator

appreciate for your help

0 Karma

rakesh44
Communicator

I dont see option to accept your answer and hence posting your answer again

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rakesh44

Now you can mark it Accept.

0 Karma

rakesh44
Communicator

Thanks Kamlesh for quick reply

Its works for me, can we expedite search its very slow , I have many events.

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@rakesh44
You can use eval() to get the count of specific value.
Check below search:

index="_internal" component=root OR component=Metrics OR eventtype=splunkd-log OR eventtype=splunkd-access | stats count(eval(component="Metrics")) as Metrics_count, count(eval(component="root")) as Root_count, count(eval(eventtype="splunkd-log")) as Splunkd_log_count, count(eval(eventtype="splunkd-access")) as Splunkd_access_count
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...