How to query the Application Loadbalancer associated with a Target Group in Grafana template?

I am setting up a dashboard in Grafana that would take data from Cloudwatch and show metrics related to TargetGroups. Most of the metrics need the loadbalancer as a dimension as well. How to query the loadbalancer name if I have the Target Group name?

For templating, I am getting the available loadbalancers with a query. This is giving all the loadbalancer names and that is not very helpful for the user

This is giving all the loadbalancer names.


Is there any filter or another method to only get the loadbalancers associated with the specific Target Group I have?

This will get you the TargetGroups attached to the loadbalancer.
Where $loadbalancer is your variable containing the loadbalancer name.

dimension_values($region,AWS/ApplicationELB,HealthyHostCount,TargetGroup, {"LoadBalancer":"$loadbalancer"})

Using this I’ve managed to display a graph showing HealthyHostCount so long as I repeat the panel per TargetGroup.
I’ve tried to do a single stat panel to show an aggregate of this, to show if one target group drops an instance but so far I’ve failed.
Let me know if you have more success if you try this.