我在 CloudWatch 代理配置的append_dimensions
和选项中找到了我需要的内容。aggregate_dimensions
在配置中“指标”块的顶层,您可以添加维度:
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
...
但是,您只能添加这些 AWS 维度。
您可以添加自定义维度,但仅限于特定指标。因此,例如,在 CPU 指标收集器中:
"metrics_collected": {
"cpu": {
"append_dimensions": {
"CustomDimension": "Foo"
},
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": false
},
您也可以将这些添加到 procstat 组中,尽管它是一个列表:
"procstat": [
{
"append_dimensions": {
"CustomDimension": "Foo"
},
"pid_file": "/var/run/celerybeat/beat.pid",
"measurement": [
"cpu_usage",
"memory_locked",
"pid_count"
]
}
aggregation_dimensions
最后,您可以在指标块的顶层使用这些自定义维度进行聚合。
虽然自定义维度附加在特定的 metric_collected 中,但您可以在 aggregation_dimensions 时将这些维度放在顶部
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"aggregation_dimensions" : [
["AutoScalingGroupName"],
["AutoScalingGroupName", "InstanceType"],
["CustomDimension"],
["CustomDimension", "InstanceType"],
["CustomDimension", "pidfile"],
],
"metrics_collected": {
...
这些文档位于https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html但我花了一段时间才将它们挖掘出来、测试它们并工作自定义维度需要存在于特定metrics_collected
部分中。