Grafana alert based on mapped column from Influx query

Hi Team,

I have the below custom InfluxDB query where I wanted to write an alert on

import "strings"

from(bucket: "monitoring_metrics")
  |> range(start: -1h)  // You can adjust the time range for your needs
  |> filter(fn: (r) => 
      r["_measurement"] == "jvm_memory" and
      (r["_field"] == "HeapMemoryUsage.committed" or r["_field"] == "HeapMemoryUsage.used") and
      r["type"] == "APP" and
      (r["app_env"] == "ENV1" or r["miles_env"] == "ENV2" or r["miles_env"] == "ENV3") and
      strings.containsStr(v: r.jolokia_agent_url, substr: "20888")
  )
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
  |> map(fn: (r) => ({
      r with
      heap_usage_percent: (r["HeapMemoryUsage.used"] / r["HeapMemoryUsage.committed"]) * 100.0
  }))
  |> yield(name: "mean")

I wanted to get the alert to be based on “heap_usage_percent” field. If the value is above 90 percent.

Also each of the “app_env” have the rows which contains this value calculated. Can someone please shed some light on this how get the alert condition set ?

It looks like the alert is basing on "_measurement " as a default.

thank you

Hi @dumpalap

In your query, can you try inserting this statement right after your map() statement and see how that changes the results? I presume you have the rest of the alerting section filled out where you reduce the value and set the threshold (90).

|> rename(columns: {_value: "something"})

Source: example 5 from this blog post.