如何在容器中启动cloudwatch代理?

时间:2019-09-27 12:16:50

标签: docker amazon-ec2 amazon-cloudwatch

在docker hub上有一个image,该位置由亚马逊维护。

任何人都不知道如何配置和启动容器,因为我找不到任何文档

5 个答案:

答案 0 :(得分:3)

我已经开始工作了!当您看到Reading json config file path: /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json ... Cannot access /etc/cwagentconfig: lstat /etc/cwagentconfig: no such file or directoryValid Json input schema.

时,我也遇到了同样的问题

您需要做的是将您的配置文件放在/ etc / cwagentconfig中。功能齐全的dockerfile:

FROM amazon/cloudwatch-agent:1.230621.0
COPY config.json /etc/cwagentconfig

其中config.json是一些Cloudwatch代理配置,例如LinPy的答案给出的

您可以忽略有关/opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json的警告,也可以将config.json文件复制到dockerfile中的该位置。

我还将分享如何找到此答案:

我需要在ECS中作为辅助工具运行,而且我只能找到有关如何在kubernetes中运行它的文档。遵循本文档:https://docs.aws.amazon.com/en_pv/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-StatsD.html,当我看到此示例时,我决定下载所有示例k8s清单:

apiVersion: v1
kind: Pod
metadata:
  namespace: default
  name: amazonlinux
spec:
  containers:
    - name: amazonlinux
      image: amazonlinux
      command: ["/bin/sh"]
      args: ["-c", "sleep 300"]
    - name: cloudwatch-agent
      image: amazon/cloudwatch-agent
      imagePullPolicy: Always
      resources:
        limits:
          cpu:  200m
          memory: 100Mi
        requests:
          cpu: 200m
          memory: 100Mi
      volumeMounts:
        - name: cwagentconfig
          mountPath: /etc/cwagentconfig
  volumes:
    - name: cwagentconfig
      configMap:
        name: cwagentstatsdconfig
  terminationGracePeriodSeconds: 60

所以我看到卷挂载cwagentconfig挂载到/etc/cwagentconfig上,并且是从cwagentstatsdconfig配置图开始的,而那是只是json文件。

答案 1 :(得分:0)

您只需使用log-opt运行容器,因为日志代理是容器的主要过程。

docker run --log-driver=awslogs --log-opt awslogs-region=us-west-2 --log-opt awslogs-group=myLogGroup amazon/cloudwatch-agent

您可以找到更多详细信息herehere

我不知道您为什么在容器中需要一个代理,但是最佳实践是将每个容器日志直接发送到cloud watch using aws log driver.

这是容器的入口点。

  "Entrypoint": [
         "/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"
 ],

您需要拨打的电话

/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent

答案 2 :(得分:0)

尝试dockerfile

FROM amazonlinux:2.0.20190508
RUN yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
COPY agent.json  /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json
ENV RUN_IN_CONTAINER=True
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]

json示例:

  {
      "agent": {
        "metrics_collection_interval": 10,
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
      },
      "metrics": {
        "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,
            "metrics_collection_interval": 10,
            "append_dimensions": {
              "customized_dimension_key_1": "customized_dimension_value_1",
              "customized_dimension_key_2": "customized_dimension_value_2"
            }
          },
          "disk": {
            "resources": [
              "/",
   .
   .
   .
   .
}

答案 3 :(得分:0)

这是来自官方文档:

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

此处是文档:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-commandline-fleet.html#start-CloudWatch-Agent-EC2-commands-fleet

安装路径可能有所不同,但这就是根据文档启动代理的方式。

答案 4 :(得分:0)

Here是我如何在没有systemctl或System V init的情况下在我们的Docker容器中使用它的方法。