<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>JetLab</title>
  <language>zh-cn</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://jetlab.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://jetlab.pages.dev</link>
  <itunes:image href="https://pub-95991fbe4916479fa08945a675ecf616.r2.dev/jetlab/production/images/channel-c49e37636f615621aeb631999280a26f.jpg"/>
  <image>
    <title>JetLab</title>
    <url>https://pub-95991fbe4916479fa08945a675ecf616.r2.dev/jetlab/production/images/channel-c49e37636f615621aeb631999280a26f.jpg</url>
    <link>https://jetlab.pages.dev</link>
  </image>
  <copyright>©2024</copyright>
  <item>
    <title>使用 Greptime Cloud 监控AWS CloudWatch</title>
    <guid>l7pp6J245zb</guid>
    <pubDate>Fri, 06 Dec 2024 09:43:38 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<h1>使用 Greptime Cloud 监控AWS CloudWatch</h1><p>​<img src="http://127.0.0.1:50692/assets/greptime_cloudwatch-20241205224320-m9neyxu.png">​</p><p>‍</p><ul><li><strong>引言</strong></li><li>CloudWach 是 AWS 上进行监控的一个服务，如果你想把这些监控数据自行保存或进行分析，可以通过 API 接口将其导出并存储。</li><li>目前主流的监控平台是 Prometheus ，其易用性收到广泛的应用。但是由于其在 HA 和高基数的问题，而维护 Thanos 集群又提升了复杂度。近年来，GreptimeDB 作为个新的时序数据库，其原生支持高可用，并且兼容 Prometheus 协议。</li><li>本文将通过 Grafana Alloy 将 AWS CloudWatch 的数据抓取，并转化为 Prometheus 格式发送到 GreptimeCloud。</li><li><strong>核心工具简介</strong></li><li class="ql-indent-1"><strong>AWS CloudWatch</strong>：用于收集和监控 AWS 服务指标。</li><li class="ql-indent-1"><strong>Alloy</strong>：专注于数据抓取、转换与传输的工具。</li><li class="ql-indent-1"><strong>Greptime Cloud</strong>：高效的时序数据存储与分析平台。</li></ul><p>‍</p><ol><li>在 AWS 上创建 IAM 用户并绑定 Alloy 所需 Policy</li></ol><p><br></p><pre class="ql-syntax" spellcheck="false">
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1674249227793",
      "Action": [
        "tag:GetResources",
        "cloudwatch:GetMetricData",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:ListMetrics",
        "ec2:DescribeTags",
        "ec2:DescribeInstances",
        "ec2:DescribeRegions",
        "iam:ListAccountAliases",
        "ec2:DescribeTransitGateway*",
        "apigateway:GET",
        "dms:DescribeReplicationInstances",
        "dms:DescribeReplicationTasks"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
</pre><p><br></p><p>并将该 Policy 绑从对应的 AWS IAM User 上，将该用户的 Credential 保存到&nbsp;~/.aws/crendetails​</p><p>‍</p><p>‍</p><p>根据官方&nbsp;<a href="https://grafana.com/docs/alloy/latest/set-up/install/" rel="noopener noreferrer" target="_blank">安装文档</a>&nbsp;下载并安装到本地</p><p>新建一个&nbsp;config.alloy&nbsp;​文件，该文件将会有以下内容</p><pre class="ql-syntax" spellcheck="false">prometheus.exporter.cloudwatch "aws_ec2_metrics" {
    ......
}

prometheus.scrape "awsmonitoring" {
    ......
}

prometheus.remote_write "greptimedb" {
    ......
}
</pre><p>prometheus.exporter.cloudwatch​ 将会配置从 CloudWatch 拉取指标</p><pre class="ql-syntax" spellcheck="false">prometheus.exporter.cloudwatch "aws_ec2_metrics" {

    sts_region = "ap-east-1"

    discovery {
        type    = "AWS/EC2"
        regions = ["ap-east-1"]

        metric {
            name       = "CPUUtilization"
            statistics = ["Average"]
            period     = "5m"
        }

        metric {
            name       = "NetworkPacketsIn"
            statistics = ["Average"]
            period     = "5m"
        }
    }
}
</pre><p>该文件配置了从 ap-east-1 区域拉取 EC2 的两个指标：</p><ul><li>CPUUtilization，统计方式采用均值，统计周期 5 分钟</li><li>NetworkPacketsIn，统计方式采用均值，统计周期 5 分钟</li></ul><p>‍</p><p>​prometheus.scrape "awsmonitoring"​ 配置</p><pre class="ql-syntax" spellcheck="false">prometheus.scrape "awsmonitoring" {
  targets    = prometheus.exporter.cloudwatch.aws_ec2_metrics.targets
  forward_to = [prometheus.remote_write.greptimedb.receiver]
}
</pre><p>‍</p><p>对于prometheus.remote_write "greptimedb"​的配置请登录&nbsp;<a href="https://console.greptime.cloud/" rel="noopener noreferrer" target="_blank">GreptimeCloud&nbsp;</a>的控制台进行配置</p><p>选择Alloy，并将配置内容复制到config.alloy中</p><p>​<img src="http://127.0.0.1:50692/assets/image-20241206173847-c9lbpff.png">​</p><p>运行命令启动Alloy</p><pre class="ql-syntax" spellcheck="false">alloy-linux-amd64 run config.alloy
</pre><p>‍</p><p>回到Greptime Cloud 检查，如果出现了以下内容，说明配置成功。<img src="http://127.0.0.1:50692/assets/image-20241206005855-42b822u.png">​</p><p>​<img src="http://127.0.0.1:50692/assets/image-20241206010003-ydiseuo.png">​</p><p>‍</p><p>‍</p><p>‍</p><p>‍</p><p>Greptime</p><p>‍</p><p>​<img src="http://127.0.0.1:50692/assets/image-20241206005536-980gyn7.png">​</p><p>使用以下 JSON 文件作为 Dashboard 的配置</p><pre class="ql-syntax" spellcheck="false">{
  "kind": "Dashboard",
  "metadata": {
    "name": "aws_ec2",
    "project": "default",
    "version": 0
  },
  "spec": {
    "display": {
      "name": "aws_ec2"
    },
    "panels": {
      "CPUUtilization": {
        "kind": "Panel",
        "spec": {
          "display": {
            "name": "CPUUtilization"
          },
          "plugin": {
            "kind": "TimeSeriesChart",
            "spec": {
              "yAxis": {
                "show": true,
                "label": "",
                "format": {
                  "unit": "percent"
                }
              },
              "legend": {
                "position": "bottom"
              }
            }
          },
          "queries": [
            {
              "kind": "TimeSeriesQuery",
              "spec": {
                "plugin": {
                  "kind": "PrometheusTimeSeriesQuery",
                  "spec": {
                    "query": "aws_ec2_cpuutilization_average",
                    "seriesNameFormat": "{{ dimension_InstanceId}}"
                  }
                }
              }
            }
          ]
        }
      },
      "CPUUtilization-1": {
        "kind": "Panel",
        "spec": {
          "display": {
            "name": "NetworkPacketsIn"
          },
          "plugin": {
            "kind": "TimeSeriesChart",
            "spec": {
              "yAxis": {
                "show": true,
                "label": "",
                "format": {
                  "unit": "bytes"
                }
              },
              "legend": {
                "position": "bottom"
              }
            }
          },
          "queries": [
            {
              "kind": "TimeSeriesQuery",
              "spec": {
                "plugin": {
                  "kind": "PrometheusTimeSeriesQuery",
                  "spec": {
                    "query": "aws_ec2_network_packets_in_average",
                    "seriesNameFormat": "{{ dimension_InstanceId}}"
                  }
                }
              }
            }
          ]
        }
      }
    },
    "layouts": [
      {
        "kind": "Grid",
        "spec": {
          "display": {
            "title": "Panel Group",
            "collapse": {
              "open": true
            }
          },
          "items": [
            {
              "x": 0,
              "y": 0,
              "width": 13,
              "height": 7,
              "content": {
                "$ref": "#/spec/panels/CPUUtilization"
              }
            },
            {
              "x": 0,
              "y": 7,
              "width": 13,
              "height": 7,
              "content": {
                "$ref": "#/spec/panels/CPUUtilization-1"
              }
            }
          ]
        }
      }
    ],
    "variables": [],
    "duration": "1h",
    "refreshInterval": "0s"
  }
}

</pre>]]>
    </description>
    <link>https://jetlab.cloud/i/l7pp6J245zb/</link>
    <itunes:episodeType>full</itunes:episodeType>
  </item>
</channel>
</rss>