AWS EKS 记录到 CloudWatch - 如何仅发送日志而不发送指标?

发布于 2025-01-11 13:36:07 字数 492 浏览 0 评论 0原文

我想将 EKS 集群上运行的选定服务的日志转发到 CloudWatch,以实现独立于集群的存储和更好的可观察性。

按照 https:/ 中概述的快速入门操作/docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-EKS-quickstart.html 我已设法通过转发日志Fluent Bit 服务,但也生成了 170 个 Container Insights 指标通道。这些指标不仅不需要,而且似乎成本也相当高。

如何禁用 cpu/内存/网络/等集群指标的收集,并仅继续将容器日志转发到 CloudWatch?我很难找到这方面的任何文档。

I would like to forward the logs of select services running on my EKS cluster to CloudWatch for cluster-independent storage and better observability.

Following the quickstart outlined at https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-EKS-quickstart.html I've managed to get the logs forwarded via Fluent Bit service, but that has also generated 170 Container Insights metrics channels. Not only are those metrics not required, but they also appear to cost a fair bit.

How can I disable the collection of cluster metrics such as cpu / memory / network / etc, and only keep forwarding container logs to CloudWatch? I'm having a very hard time finding any documentation on this.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无尽的现实 2025-01-18 13:36:07

我想我已经弄清楚了 - 快速入门指南中的 cloudwatch-agent 守护进程集是发送指标的内容,但日志转发不需要它。日志转发不需要快速启动 yaml 文件中与 cloudwatch-agent 相关名称的所有对象。

I think I figured it out - the cloudwatch-agent daemonset from quickstart guide is what's sending the metrics, but it's not required for log forwarding. All the objects with names related to cloudwatch-agent in quickstart yaml file are not required for log forwarding.

∞琼窗梦回ˉ 2025-01-18 13:36:07

根据 Toms Mikoss 的建议,您需要删除配置文件中的 metrics 对象。该文件是您在启动时传递给代理的文件

。这适用于“本地”“linux”安装。我没有在 Windows 上测试过这个,也没有在 EC2 上测试过,但我想它会是类似的。 AWS 文档说你也可以通过 SSM 分发配置,但我想这里的答案仍然适用。

包含指标的文件示例:

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/var/log/nginx.log",
                        "log_group_name": "nginx",
                        "log_stream_name": "{hostname}"
                    }
                ]
            }
        }
    },
    "metrics": {
        "metrics_collected": {
            "cpu": {
                "measurement": [
                    "cpu_usage_idle",
                    "cpu_usage_iowait"
                ],
                "metrics_collection_interval": 60,
                "totalcpu": true
            }
        }
    }
}

不包含指标的文件示例:

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/var/log/nginx.log",
                        "log_group_name": "nginx",
                        "log_stream_name": "{hostname}"
                    }
                ]
            }
        }
    }
}

作为参考,启动 Linux 本地服务器的命令:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config \
 -m onPremise -s -c file:configuration-file-path

更多详细信息,请参见 此处的 AWS 文档

As suggested by Toms Mikoss, you need to delete the metrics object in your configuration file. This file is the one that you pass to the agent when starting

This applies to "on-premises" "linux" installations. I havent tested this on windows, nor EC2 but I imagine it will be similar. The AWS Documentation here says that you can also distribute the configuration via SSM, but again, I imagine the answer here is still applicable.

Example of file with metrics:

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/var/log/nginx.log",
                        "log_group_name": "nginx",
                        "log_stream_name": "{hostname}"
                    }
                ]
            }
        }
    },
    "metrics": {
        "metrics_collected": {
            "cpu": {
                "measurement": [
                    "cpu_usage_idle",
                    "cpu_usage_iowait"
                ],
                "metrics_collection_interval": 60,
                "totalcpu": true
            }
        }
    }
}

Example of file without metrics:

{
    "agent": {
        "metrics_collection_interval": 60,
        "run_as_user": "root"
    },
    "logs": {
        "logs_collected": {
            "files": {
                "collect_list": [
                    {
                        "file_path": "/var/log/nginx.log",
                        "log_group_name": "nginx",
                        "log_stream_name": "{hostname}"
                    }
                ]
            }
        }
    }
}

For reference, the command to start for linux on-premises servers:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config \
 -m onPremise -s -c file:configuration-file-path

More details in the AWS Documentation here

时光无声 2025-01-18 13:36:07

如果使用 CloudWatch Observability EKS 插件,它将现在(从版本 1.5.0 开始)自动启用具有增强可观察性的 Container Insights

我设法在保留日志的同时禁用增强的可观察性指标,方法是将以下内容添加到控制台中附加组件的高级配置部分:

"agent": {
    "config": {
      "logs": {
        "metrics_collected": {
          "application_signals": {},
          "kubernetes": {
            "enhanced_container_insights": false
          }
        }
      },
      "traces": {
        "traces_collected": {
          "application_signals": {}
        }
      }
    }
}

请注意enhanced_container_insights: false行。

您还可以使用 CLI 执行此操作:

aws eks update-addon --cluster-name <CLUSTER_NAME> --addon-name amazon-cloudwatch-observability --addon-version <ADDON_VERSION> --configuration-values '
  "agent": {
    "config": {
      "logs": {
        "metrics_collected": {
          "application_signals": {},
          "kubernetes": {
            "enhanced_container_insights": false
          }
        }
      },
      "traces": {
        "traces_collected": {
          "application_signals": {}
        }
      }
    }

}' --resolve-conflicts preserve

该附加组件仍会提供常规指标和日志组,但您不会获得增强的指标(通常会深入到 Pod 或容器级别)。默认指标足以满足我的用例,并且我仅通过使用这些指标就可以节省成本。

If using the CloudWatch Observability EKS add-on, it will now (as of version 1.5.0) automatically enable Container Insights with enhanced observability.

I managed to disable the enhanced observability metrics while keeping logs by adding the following to the Advanced configuration section of the add-on in the console:

"agent": {
    "config": {
      "logs": {
        "metrics_collected": {
          "application_signals": {},
          "kubernetes": {
            "enhanced_container_insights": false
          }
        }
      },
      "traces": {
        "traces_collected": {
          "application_signals": {}
        }
      }
    }
}

Note the enhanced_container_insights: false line.

You can also do this with the CLI:

aws eks update-addon --cluster-name <CLUSTER_NAME> --addon-name amazon-cloudwatch-observability --addon-version <ADDON_VERSION> --configuration-values '
  "agent": {
    "config": {
      "logs": {
        "metrics_collected": {
          "application_signals": {},
          "kubernetes": {
            "enhanced_container_insights": false
          }
        }
      },
      "traces": {
        "traces_collected": {
          "application_signals": {}
        }
      }
    }

}' --resolve-conflicts preserve

The add-on will still give the regular metrics and log groups, but you won't get the enhanced metrics (which usually drill down to pod or container level). The default metrics were enough for my use case and I was able to save cost by only using those.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文