How to create alert query template?

We have many CPU, Memory, GC monitor on different system.
We want to build a template and input some variables to get different system monitor in alerting.
I know the monitor panel can input variables in query.
For example below query, there are sys_role and pod two variables.

sum(rate(container_cpu_usage_seconds_total{namespace="$sys_role", pod=~"$pod", container="", vpc_amazonaws_com_has_trunk_attached!="false"}[4m])) by (pod)

Hi, in alerts you cannot use variables. I don’t know of any alert templates either but I don’t think anything like that is implemented. What you can do is to remove filtering by namespace and pod, group by those labels and create a multidimensional alert (it would create an alert instance per every (namespace, pod) pair. Two disadvantages on those would be that it would only take one threshold and it might be quite a big query.

1 Like