Splunk Enterprise Security

Count events for two period of time

Haleb
Path Finder

I need to calculate the average number of events in the last hour and compare it with the number of events in the last 10 minutes for each host.
index="cloudflare"
| spath path=ClientRequestHost output=host
| stats count as event_count by host
| eval avg_count_of_events = round(event_count/6)
| map search="search index=cloudflare ClientRequestHost=$host$ earliest=-10min | stats count as last_count_of_events | eval host=$host$ | eval avg_count_of_events=$avg_count_of_events$ | eval event_count=$event_count$ "
| eval percent_of_increase = round((last_count_of_events/avg_count_of_events)*100)-100
| table host avg_count_of_events last_count_of_events percent_of_increase

Is the more effective way to do that?

Labels (1)
Tags (5)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

map is slow and limited - try something like this

| timechart span=10m aligntime=latest count by host
| addcoltotals label="Total" labelfield=_time
| tail 2
| eval _time=if(_time=="Total", _time, "last_count_of_events")
| fields - _span
| transpose 0 column_name=host header_field=_time
| eval avg_count_of_events=round(Total/6)
| eval percent_of_increase = round((last_count_of_events/avg_count_of_events)*100)-100
| table host avg_count_of_events last_count_of_events percent_of_increase

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

map is slow and limited - try something like this

| timechart span=10m aligntime=latest count by host
| addcoltotals label="Total" labelfield=_time
| tail 2
| eval _time=if(_time=="Total", _time, "last_count_of_events")
| fields - _span
| transpose 0 column_name=host header_field=_time
| eval avg_count_of_events=round(Total/6)
| eval percent_of_increase = round((last_count_of_events/avg_count_of_events)*100)-100
| table host avg_count_of_events last_count_of_events percent_of_increase
Get Updates on the Splunk Community!

New in Observability - Improvements to Custom Metrics SLOs, Log Observer Connect & ...

The latest enhancements to the Splunk observability portfolio deliver improved SLO management accuracy, better ...

Improve Data Pipelines Using Splunk Data Management

  Register Now   This Tech Talk will explore the pipeline management offerings Edge Processor and Ingest ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

Register Join this Tech Talk to learn how unique features like Service Centric Views, Tag Spotlight, and ...