4

CloudWatch agent version: 1.3.411.60

The Objective: Get the localhost name of Windows EC2 instance to be a dimension (column) for each metric configured. So that you can filter by the instance's ComputerName

Per the AWS Docs for creating a CloudWatch Agent Config file,

omit_hostname – Optional. By default, the hostname is published as a dimension of metrics that are collected by the agent. Set this value to true to prevent the hostname from being published as a dimension. The default value is false.

Link to the doc: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html

Being that's the case, after applying my configurated json file, i see the configured metrics in CloudWatch successfully, but without a dimension/Column with the host's name showing.

When i view the log, i see that the agent successfully retrieved the localhost name of the instance, HOST-123456 (actual name redacted)

2020/05/11 22:59:23 I! I! Detected the instance is EC2
2020/05/11 22:59:23 Reading json config file path: C:\ProgramData\Amazon\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json ...
Valid Json input schema.
No csm configuration found.
Configuration validation first phase succeeded
2020/05/11 22:59:23 I! Config has been translated into TOML C:\ProgramData\Amazon\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.toml 
2020-05-11T22:59:27Z I! cloudwatch: get unique roll up list [[AutoScalingGroupName]]
2020-05-11T22:59:27Z I! Starting AmazonCloudWatchAgent (version 1.237768.0)
2020-05-11T22:59:27Z I! Loaded outputs: cloudwatchlogs cloudwatch
2020-05-11T22:59:27Z I! Loaded inputs: win_perf_counters windows_event_log
2020-05-11T22:59:27Z I! Tags enabled: host=HOST-123456
2020-05-11T22:59:27Z I! Agent Config: Interval:30s, Quiet:false, Hostname:"HOST-123456", Flush Interval:1s 
2020-05-11T22:59:27Z I! cloudwatch: publish with ForceFlushInterval: 1m0s, Publish Jitter: 43s

In the .json file it reads first (the one i configured), i explicitly state the false boolean for omitting the hostname, even though that is the default configuration (I've gotten the same results leaving this out and just letting the default be configured on it's own)

"agent": {
        "metrics_collection_interval": 30,
        "logfile": "c:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\Logs\\amazon-cloudwatch-agent.log",
        "omit_hostname": false
    },

In the .toml file that the agent converts the .json to, i see the hostname value is null,

[agent]
  collection_jitter = "0s"
  debug = false
  flush_interval = "1s"
  flush_jitter = "0s"
  hostname = ""
  interval = "30s"
  logfile = "c:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\Logs\\amazon-cloudwatch-agent.log"
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  omit_hostname = false
  precision = ""
  quiet = false
  round_interval = false

AND lower in the outputs.cloudwatch section i see there is a specific key called tagexclude with "host" in it, (and metricPath which i do not know what that is)

[outputs]

  [[outputs.cloudwatch]]
    force_flush_interval = "60s"
    namespace = "PerfMon"
    region = "us-west-1"
    rollup_dimensions = [["AutoScalingGroupName"]]
    tagexclude = ["host", "metricPath"]

I've not been successful googling around for deeper insight into this, so i'm hoping someone may be able to inform me with what's going on. Any insight is much appreciated.

to note: The default Name field in AWS for EC2 instance's is filled with the name of the ASG the EC2 resides in for other reasons so that field can't be utilized.

1 Answers1

0

This is an old question, but for future readers, I suspect the OP was using append_dimensions in the Cloudwatch agent configuration file which disables publishing hostname metric.

Note the highlighted bit from https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Metricssection :

append_dimensions – Optional. Adds Amazon EC2 metric dimensions to all metrics collected by the agent. This also causes the agent to not publish the hostname as a dimension.

The only supported key-value pairs for append_dimensions are shown in the following list. Any other key-value pairs are ignored.

"ImageID":"${aws:ImageId}" sets the instance's AMI ID as the value of the ImageID dimension.

"InstanceId":"${aws:InstanceId}" sets the instance's instance ID as the value of the InstanceID dimension.

"InstanceType":"${aws:InstanceType}" sets the instance's instance type as the value of the InstanceType dimension.

"AutoScalingGroupName":"${aws:AutoScalingGroupName}" sets the instance's Auto Scaling group name as the value of the

AutoScalingGroupName dimension.

If you want to append dimensions to metrics with arbitrary key-value pairs, use the append_dimensions parameter in the field for that particular type of metric.

If you specify a value that depends on Amazon EC2 metadata and you use proxies, you must make sure that the server can access the endpoint for Amazon EC2. For more information about these endpoints, see Amazon Elastic Compute Cloud (Amazon EC2) in the Amazon Web Services General Reference.

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91