Ways to count number of values in a template variable

I have 2 template variables, for example assume it as region, instanceid. All the regions and instance id are listed if i click on the dropdown it shows all values. I want to create a dashboard in grafana with two pannels to show how many regions and instanceid are there in that variable by cloudwatch as a datasource, how can i achieve this

@midhun12

What queries did you use to create the list of available choices in each template variable? Can you paste here?

Hi @grant2, i am using cloudwatch as a datasource, and i have added multiple template variables, i am actually fetching the resource with tags and with query resource_arn, the below are the variables i have used,

– ec2_instance_attribute($region, Tags.Name, {})
– resource_arns($region,elasticloadbalancing:loadbalancer,{“Name”:[“$instancename”]})
– resource_arns($region,rds:db,{“Name”:[“$instancename”]})
– resource_arns($region,autoscaling:autoscalinggroup,{“Name”:[“$instancename”]})

I can see the template variables created now. I have 2 requirements now

  1. How do i calculate the number of asg, rds, lb with that tag name. Basically i just want to count how many ever is listed in template variable.

  2. can i add this query in grafana pannel instead of template variables and add count. If possible please suggest how could this be done

Thanks

Why you don’t use AWS/Usage ResourceCount metrics?
For example number of RDS clusters:

Hi @jangaraj
I have tagged few resources and I would like to fetch only my tagged resources. For example I have tagged key as ‘env‘ and value as ‘prod’. So in the Grafana panel, I would like to fetch only the rds with this particular tag.

Got it. Use Cloudwatch math. Query 1 will return some metrics per resource (e. g. avg CPU utilization per EC2 per selected dashboard time range) and then use expression to count those values from query 1.

Hi @jangaraj,Sorry I didnt get that right. So how can we filter based on the tags here?

Yes, that’s another good point. Direct filtering by tag is not possible. But you have already list of resource ids filtered on the dashboard variable level. So use that variable in the query to filter only selected resource ids. Example: filter only selected Lambdas:

@jangaraj With the sample which you have mentioned i couldnt get the count of lambda functions. Meaning i want to fetch the count of lambda functions with Tag as env…
If this is not possible by Namespace, please suggest if i can use ‘resource_arns’ query somehow in the grafana pannel

Sorry, I’m not giving you copy&paste solution, because that needs a time and my time is not free. I gave you a hint. As I said, first query and then expression to count it - example:

1 Like