Alert check notification time threshold

Hi, I’m currently playing around with alert checks, but have a couple questions about setting the length of time for when I want a threshold alert to trigger and go back to the okay status.

For context, I’m creating an alert for checking cpu-total and have it configured so that it goes to critical when above 80% usage and back to okay below 81% usage.

  1. How can I set the length of time for when I want the ‘Critical’ threshold level to be set? For e.g. I would only want the ‘Critical’ alert to be sent out if the cpu usage has been over 80% for 10 mins.
  2. Can I separately set the length of time for when the cpu usage goes below 81%? For e.g. I’d want the ‘Okay’ level alert to be sent out once the cpu usage drops below 81% for 5 mins.

Any help would be much appreciated.

Welcome @Awab_Amin to the InfluxDB forum.

I read through this. If you scroll down to the Creating a Custom Notification Rule, you will see this:

I am pretty sure you can create two separate rules (one for when CPU usage has been over 80% for 10 min, and another for when the CPU goes below 81% for 5 min).

Hi @grant1,

Thank you for the welcome.

Yes, this looks like something that would help with this. However, I’m not too familar with Flux, how would I implement that stateDuration() line in my check below?

data =
    from(bucket: "Servers")
        |> range(start: -5m)
        |> filter(fn: (r) => r["_measurement"] == "cpu")
        |> filter(fn: (r) => r["cpu"] == "cpu-total")
        |> filter(fn: (r) => r["_field"] == "usage_active")
        |> filter(
            fn: (r) =>
                r["host"] == "aquamarine.test" or r["host"] == "ebony.test"
                    "seashell.test" or r["host"] == "violet.test",
        |> aggregateWindow(every: 5m, fn: mean, createEmpty: false)

option task = {name: "CPU Used (%)", every: 5m, offset: 0s}

check = {_check_id: "0b0abd925181a000", _check_name: "CPU Used (%)", _type: "threshold", tags: {}}
ok = (r) => r["usage_active"] < 81.0
crit = (r) => r["usage_active"] > 80.0
messageFn = (r) => "Check: ${ r._check_name } is: ${ r._level }"

    |> v1["fieldsAsCols"]()
    |> monitor["check"](data: check, messageFn: messageFn, ok: ok, crit: crit)

Unfortunately I do not have much time today, but it looks like you are on the right track. I’ll try to come back with some more.

Hi @grant1, I’ve been playing around with this but still haven’t been able to get it to work unfortunately, any ideas on how to write the code?