Splunk Search

Possible to achieve eval results per host?

geek238
Engager

Working with stat log events from DJB's dnscache. These look like:

@400000004f3ebb59244cc72c stats 275245265 10318311576 81 0

The first field is timestamp in tai64nlocal. Splunk deals with that. The first field after the 'stats' string is a query counter, constantly incrementing. To get querys/second for the DNS resolver, I can do:

index=dns earliest=-1m host=dns1 | rex field=_raw "stats\s(?<querycount>\d+) " | stats max(querycount) as hq,min(querycount) as lq | eval qps=(hq-lq)/60 | table host,qps,hq,lq

What I'd like to do is search against the index and execute stats and eval against values retrieved from each host observed in the index, without creating a separate search for each host. I've been thinking something along the lines of finding hosts in a subsearch then for each value returned, execute the search to gather statistics.

I'm sure someone has done something cool like this before.

Tags (3)
0 Karma
1 Solution

Ayn
Legend

You can use chart and then eval() stuff directly inside of it, so something like this should work:

index=dns earliest=-1m host=dns1 | rex field=_raw "stats\s(?<querycount>\d+) " | chart eval((max(querycount)-min(querycount))/60) as qps,max(querycount) as hq,min(querycount) as lq by host

View solution in original post

geek238
Engager

Both answers work great, thanks!

0 Karma

gkanapathy
Splunk Employee
Splunk Employee
index=dns earliest=-1m host=dns1 
| rex field=_raw "stats\s(?<querycount>\d+) " 
| stats max(querycount) as hq,
        min(querycount) as lq 
  by host
| eval qps=(hq-lq)/60

The "by" clause of the stats command does what you want.

0 Karma

Ayn
Legend

You can use chart and then eval() stuff directly inside of it, so something like this should work:

index=dns earliest=-1m host=dns1 | rex field=_raw "stats\s(?<querycount>\d+) " | chart eval((max(querycount)-min(querycount))/60) as qps,max(querycount) as hq,min(querycount) as lq by host
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

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 Certification at ...

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