Splunk Search

Conditional statements based on metric trends

winknotes
Path Finder

This may actually be 2 questions, but I have 3 metrics I'd like to compare based on how they're trending. So......

Condition is met when metric 1 is trending up, metric 2 and metric 3 are trending down.

I'm not sure how to write a query that ascertains a trend and I'm guessing an if statement would work for the condition.

Tags (1)
0 Karma
1 Solution

adonio
Ultra Champion

hello there,
there are many ways to do it in Splunk. couple of commands to consider: streamstats, detla, trendline, autoregress, accumn
look here for example: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Trendline

As there are many other ways to do this, here is a very simplified version of what i understand you are trying to achieve:

    | gentimes start=-1 increment=1m
    | head 10
    | eval _time = starttime
    | table _time
    | eval v1 = random()%10
    | eval v2 = random()%10
    | eval v3 = random()%10
    | rename COMMENT as "the above generates data below is the solution" 
    | delta v1 as dv1 
    | delta v2 as dv2
    | delta v3 as dv3
    | eval alert = if(dv1 > 0 AND dv2 < 0 AND dv3 < 0,"ALERT","OK")

hope it helps

View solution in original post

0 Karma

adonio
Ultra Champion

hello there,
there are many ways to do it in Splunk. couple of commands to consider: streamstats, detla, trendline, autoregress, accumn
look here for example: https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Trendline

As there are many other ways to do this, here is a very simplified version of what i understand you are trying to achieve:

    | gentimes start=-1 increment=1m
    | head 10
    | eval _time = starttime
    | table _time
    | eval v1 = random()%10
    | eval v2 = random()%10
    | eval v3 = random()%10
    | rename COMMENT as "the above generates data below is the solution" 
    | delta v1 as dv1 
    | delta v2 as dv2
    | delta v3 as dv3
    | eval alert = if(dv1 > 0 AND dv2 < 0 AND dv3 < 0,"ALERT","OK")

hope it helps

0 Karma

winknotes
Path Finder

Thanks so much adonio. I'll experiment with this but looks promising.

0 Karma

adonio
Ultra Champion

@winknotes i converted your answer to a comment, if this works for you, kindly accept the answer and up-vote it

0 Karma
Get Updates on the Splunk Community!

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...