Grafana exported example with 2 thresholds (jsonencode)

From wikieduonline
Jump to navigation Jump to search
resource "grafana_rule_group" "rule_group_12312423423" {
  org_id           = 1
  name             = "your_alert"
  folder_uid       = "your_folder"
  interval_seconds = 60

  rule {
    name      = "your Rule Name with 2 threshold"
    condition = "C"

    data {
      ref_id = "A"

      relative_time_range {
        from = 43200
        to   = 0
      }

      datasource_uid = "xxxxxyyyzzzz12345"
      model          = jsonencode({
        datasource = {
          type = "influxdb"
          uid  = "xxxxxyyyzzzz12345"
        }
        groupBy = [
          { params = ["$__interval"], type = "time" },
          { params = ["null"], type = "fill" }
        ]
        intervalMs     = 1000
        maxDataPoints  = 43200
        measurement    = "yourdb.your.telemetry"
        orderByTime    = "ASC"
        policy         = "default"
        refId          = "A"
        resultFormat   = "time_series"
        select         = [[{ params = ["YourField"], type = "field" }, { params = [], type = "last" }]]
        tags           = []
      })
    }

    data {
      ref_id = "B"

      relative_time_range {
        from = 0
        to   = 0
      }

      datasource_uid = "__expr__"
      model          = jsonencode({
        conditions = [{
          evaluator = { params = [], type = "gt" }
          operator  = { type = "and" }
          query     = { params = ["B"] }
          reducer   = { params = [], type = "last" }
          type      = "query"
        }]
        datasource  = { type = "__expr__", uid = "__expr__" }
        expression  = "A"
        intervalMs  = 1000
        maxDataPoints = 43200
        reducer     = "last"
        refId       = "B"
        type        = "reduce"
      })
    }

    data {
      ref_id = "C"

      relative_time_range {
        from = 0
        to   = 0
      }

      datasource_uid = "__expr__"
      model          = jsonencode({
        conditions = [{
          evaluator = { params = [100], type = "gt"" }
          operator  = { type = "and" }
          query     = { params = ["C"] }
          reducer   = { params = [], type = "last" }
          type      = "query"
        }]
        datasource  = { type = "__expr__", uid = "__expr__" }
        expression  = "B"
        intervalMs  = 1000
        maxDataPoints = 43200
        refId       = "C"
        type        = "threshold"
      })
    }

    data {
      ref_id = "D"

      relative_time_range {
        from = 0
        to   = 0
      }

      datasource_uid = "__expr__"
      model          = jsonencode({
        conditions = [{
          evaluator = { params = [60, 0], type = "lt" }
          operator  = { type = "and" }
          query     = { params = [] }
          reducer   = { params = [], type = "avg" }
          type      = "query"
        }]
        datasource  = { name = "Expression", type = "__expr__", uid = "__expr__" }
        expression  = "B"
        hide        = false
        intervalMs  = 1000
        maxDataPoints = 43200
        refId       = "D"
        type        = "threshold"
      })
    }

    no_data_state  = "NoData"
    exec_err_state = "Error"
    for            = "1m"
    is_paused      = false
  }
}

See also[edit]

Advertising: