我如何使用 terraform 将特定资源(例如:ec2、ebs)的所有小部件包含在 AWS cloudwatch 的仪表板中

发布于 2025-01-09 22:31:54 字数 1857 浏览 3 评论 0原文

我创建了 terraform 文件来在 AWS cloudwatch 中创建仪表板。

这是我用于创建仪表板的示例文件

// provider module

provider "aws"{
    access_key = var.access_key                 
    secret_key = var.secret_key
    region     = var.region
        }

// cloudwatch dashboard module

resource "aws_cloudwatch_dashboard" "main" {
  dashboard_name = var.dashboard_name

  dashboard_body = <<EOF
{
  "widgets": [
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "VolumeReadOps",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "VolumeRead"
      }
    },
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "VolumeQueueLength",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "VolumeQueueLength"
      }
    },
    {
      "type": "metric",
      "x": 14,
      "y": 13,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "BurstBalance",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "BurstBalance"
      }
    }
  ]
}
EOF
}

是否有可能将特定资源(例如:ec2、ebs、rds)中的所有可用指标添加到同一个小部件或单独的小部件中,为一个函数中的所有指标添加所有指标,而不指示其中的每个指标terraform 文件中的单独函数?

在 aws 控制台中,只需勾选资源内所有指标上方的复选框即可包含同一小部件​​中的所有指标。但我找不到地形供应的正确答案

I created terraform file to create dashboard in AWS cloudwatch.

here is my sample file to create dashboard

// provider module

provider "aws"{
    access_key = var.access_key                 
    secret_key = var.secret_key
    region     = var.region
        }

// cloudwatch dashboard module

resource "aws_cloudwatch_dashboard" "main" {
  dashboard_name = var.dashboard_name

  dashboard_body = <<EOF
{
  "widgets": [
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "VolumeReadOps",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "VolumeRead"
      }
    },
    {
      "type": "metric",
      "x": 0,
      "y": 0,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "VolumeQueueLength",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "VolumeQueueLength"
      }
    },
    {
      "type": "metric",
      "x": 14,
      "y": 13,
      "width": 12,
      "height": 6,
      "properties": {
        "metrics": [
          [
            "AWS/EBS",
            "BurstBalance",
            "VolumeId",
            "vol-04b26d88efe8ecd54"
          ]
        ],
        "period": 300,
        "stat": "Average",
        "region": "ap-south-1",
        "title": "BurstBalance"
      }
    }
  ]
}
EOF
}

Is there any possibility to add all the metrics available in the particular resource (eg:ec2, ebs, rds) in same widget or separate widget for each all the metrics in one function without indicating every metrics in separate function in terraform file?

In aws console just tick the checkbox above all the metrics inside the resource will include all the metrics in same widget. But i couldnt find the proper answer for terraform provision

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文