Splunk Search

Pass earliest/latest in pipeline

stwong
Communicator

Hi,

Sorry for the newbie question. We want to calculate percentage of time between 2 events over the entire search period. We use transaction and get the sum of time between each pair of events:

| transaction dest service startswith="CRITICAL;SOFT;1" endswith=OK | stats sum(duration) as total_downtime by dest

But we've no idea how to pass the earliest(_time) and latest(_time) of so that we can do the calculation like

percentage = (total_downtime/(latest-earliest))*100

Would anyone please help?
Thanks a lot.

0 Karma

woodcock
Esteemed Legend

Try this:

... | search OK OR "CRITICAL;SOFT;1" | streamstats count(eval(searchmatch("CRITICAL;SOFT;1"))) AS sessionID BY dest service | stats range(_time) AS duration min(_time) AS earliest BY dest service sessionID | stats sum(duration) as total_downtime min(earliest) AS earliest BY dest | eventstats min(earliest) AS earliest | percentDown = 100 * (total_downtime)/(now() - earliest)

Using search time parameters would be wrong because 0 from all time would be from 1977. This uses the oldest _time value from all events returned in the search and now() as the time frame.

0 Karma

stwong
Communicator

Thanks, will give it a try.

Rgds

0 Karma

woodcock
Esteemed Legend

Don't forget to upvote helpful answers and close the question by clicking Accept on the best one.

0 Karma

puneethgowda
Communicator

Host 1 2 minutes
Host 2 5 minutes
Host 3 40 minutes

Like this you can show what is the downtime of each server in minutes

0 Karma

stwong
Communicator

Hello, thanks. I'm able to get the downtime of each server now. Just hope to get the percentage of downtime of each host over the entire search period (time between the first and last records for all hosts, or better to get the start/end time of time picker). Thanks.

0 Karma

puneethgowda
Communicator

Why don't you fintune your Table

Try this

Host|now vs Latest max(transaction time in minutes)

0 Karma

woodcock
Esteemed Legend

Ditch transaction; try this:

... | search OK OR "CRITICAL;SOFT;1" | streamstats count(eval(searchmatch("CRITICAL;SOFT;1"))) AS sessionID BY dest service | stats range(_time) AS duration by dest service sessionID | stats sum(duration) as total_downtime by dest | addinfo | percentDown = 100 * (total_downtime)/(info_max_time - info_min_time)
0 Karma

stwong
Communicator

Hi, thanks. Tried addinfo before but seems add earliest/latest time for transaction instead of the first search in the pipe line.

Rgds
/st

0 Karma

woodcock
Esteemed Legend

Did you actually try my search?

0 Karma

stwong
Communicator

Hi, yes, tried and see info_max_time = +infinity and info_min_time = 0.000. thanks a lot.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi stwong,
try something like this:

your_search
| transaction dest service startswith="CRITICAL;SOFT;1" endswith=OK 
| stats earliest(_time) AS Earliest latest(_time) AS Latest sum(duration) as total_downtime by dest 
| eval percentage = (total_downtime/(Latest-Earliest))*100

Bye.
Giuseppe

0 Karma

stwong
Communicator

Hi Giuseppe,

Thanks. Seems this returns time period of transaction. Can I get the time span for "your_search" ? It's Nagios log and logs status of all hosts. Some are okay and some have down/up status change. We hope to get the percentage of downtime of each host (period betwen down/up) over the entire period.

Bye,
/st

0 Karma

gcusello
SplunkTrust
SplunkTrust

In this way you have the first and the latest events of your results.
to have earliest and latest you should follow this answer:
https://answers.splunk.com/answers/334498/how-to-use-eval-on-a-token-from-a-time-picker-and.html

Bye.
Giuseppe

0 Karma

stwong
Communicator

Thanks, will study and give a try.

Bye.
/st

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...