Filtering metrics info based on EC2 instances tag

Hello,

I have a requirement to export NetworkOut metric inside AWS/EC2 namespace for EC2 instances belonging to a specific AutoScaling Group. These instances have a custom tag which lets us know they belong to that ASG and I am using inputs.cloudwatch plugin for getting the AWS EC2 metrics.

Is it possible to specify the tags to be used inside the telegraf conf file for the plugin so that metrics are exported for only those instances which have that tag?

Really appreciate any pointers on this.

Search for namepass in the configuration file: telegraf/docs/CONFIGURATION.md at master · influxdata/telegraf · GitHub

1 Like

@npm_engineer , thanks for sharing the link. From this link, what I understand is that namepass will help to filter based on metric name. First I will need to ensure that the EC2 tag in question is passed along with the metric value ?

The plugin inputs.cloudwatch reads metrics for AWS/EC2 without reading any tags from the EC2 instance. I tried using [[processors.aws_ec2]] to get that tag value as per below, but getting the error: “[telegraf] Error running agent: starting processor processors.aws_ec2: failed getting instance identity document: operation error ec2imds: GetInstanceIdentityDocument, exceeded maximum number of attempts, 3, request send failed, Get “http://169.254.169.254/latest/dynamic/instance-identity/document”: dial tcp 169.254.169.254:80: connect: invalid argument”

[[processors.aws_ec2]]
ec2_tags = [“Name”]

Is there another way to achieve this or I am missing something?

Please note the Telegraf version I am using is 1.26.3. The telegraf solution is running as a Fargate service inside AWS ECS in a central AWS account and authentication to AWS accounts hosting the EC2 instances is through a role_arn defined in the inputs.cloudwatch section in the telegraf conf file.

I have never worked with the aws_ec2 processor or inputs.cloudwatch, so I can’t really help with issues with those. I was just going off your original question of how to specify the tags that are used in a telegraf config, which could be done through the namepass filter.

2 Likes