Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JOINING kapacitor queries with count and difference methods #2733

Open
vinayaktiwari opened this issue Dec 2, 2022 · 0 comments
Open

JOINING kapacitor queries with count and difference methods #2733

vinayaktiwari opened this issue Dec 2, 2022 · 0 comments

Comments

@vinayaktiwari
Copy link

vinayaktiwari commented Dec 2, 2022

I have been trying to run this script but no alert is getting created on alerta and logs are not showing any error as well, can anyone help me with this ?
avg_time_gap = sum(current_time - previous_time)/count(num_of_entries)
current_time_gap = (current_value-previous_value)
thresh = abs(current_time_gap-avg_time_gap)
alert when thresh > 0

var window = 20s
var every = 5s // defines the frequency at which the window is emitted to the next node in the pipeline.
var timeout = 360s // alert expiry time
var avg_time = batch
    |query('select 20.0/count(content) as avg_time_gap from mydb..measurement')
        .period(window)
        .every(every)
    //numerator must be as same as the window value

var adjacent_time_gap = batch
    |query('select difference(content) as time_gap from mydb..measurement')
       .period(window)
       .every(every)

var data = avg_time
    |join(adjacent_time_gap)
        .as('avg_time','actual_time')
        .tolerance(1s)

    |eval(lambda: abs("avg_time.avg_time_gap"-"actual_time.time_gap"))
        .as('time_delay')

var alert = data
    |alert()
        .id(event_name)
        .crit(lambda: "time_delay" > 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant