aws / amazon-cloudwatch-agent

CloudWatch Agent enables you to collect and export host-level metrics and logs on instances running Linux or Windows server.
MIT License
420 stars 185 forks source link

Add Host To JMX Metrics #1184

Closed sethAmazon closed 1 month ago

sethAmazon commented 1 month ago

Description of the issue

JMX metrics require having host just like cpu metrics.

Description of changes

Add host as a metric to jmx metrics unless omit_hostname is true

License

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Tests

{
  "agent": {
    "debug": true
  },
    "namespace": "HostnameTest",
    "metrics_collected": {
      "cpu": {
        "resources": [
          "*"
        ],
        "measurement": [
          {"name": "cpu_usage_idle", "rename": "CPU_USAGE_IDLE", "unit": "Percent"},
          {"name": "cpu_usage_nice", "unit": "Percent"},
          "cpu_usage_guest"
        ],
        "totalcpu": false,
        "drop_original_metrics": [ "cpu_usage_guest" ],
        "metrics_collection_interval": 10
      },
      "jmx": [
        {
          "endpoint": "localhost:2020",
          "jvm": []
        }
      ]
    }
  }
}
Screenshot 2024-05-21 at 12 57 45 PM
{
  "agent": {
    "debug": true,
    "omit_empty": true
  },
  "metrics": {
    "append_dimensions": {
      "ImageId": "${aws:ImageId}",
      "InstanceId": "${aws:InstanceId}",
      "InstanceType": "${aws:InstanceType}",
      "AutoScalingGroupName": "${aws:AutoScalingGroupName}"
    },
    "namespace": "HostnameTest",
    "metrics_collected": {
      "cpu": {
        "resources": [
          "*"
        ],
        "measurement": [
          {"name": "cpu_usage_idle", "rename": "CPU_USAGE_IDLE", "unit": "Percent"},
          {"name": "cpu_usage_nice", "unit": "Percent"},
          "cpu_usage_guest"
        ],
        "totalcpu": false,
        "drop_original_metrics": [ "cpu_usage_guest" ],
        "metrics_collection_interval": 10
      },
      "jmx": [
        {
          "endpoint": "localhost:2020",
          "jvm": []
        }
      ]
    }
  }
}
Screenshot 2024-05-21 at 1 08 03 PM

Requirements

Before commit the code, please do the following steps.

  1. Run make fmt and make fmt-sh
  2. Run make lint