theRealGabacho
theRealGabacho

Reputation: 41

How can I enable CloudWatchLogs in an ElasticBeanstalk environment running Windows?

I have a webservice that spools out data to a flat file. In non-EC2, raw Windows instances we use the EC2Config service to pump our log files and some performance counters to CloudWatch (See here: http://blogs.aws.amazon.com/application-management/post/Tx1KG4IKXZ94QFK/Using-CloudWatch-Logs-with-Amazon-EC2-Running-Microsoft-Windows-Server ).

How can I configure my application and ElasticBeanstalk to enable CloudWatch Logging in my Windows Instance?

Upvotes: 4

Views: 1931

Answers (2)

ZeW
ZeW

Reputation: 195

If you want to just append logs to the original ones set up by Elastic Beanstalk, use the answer from @mike-mckechnie, but don't include the stop command at the bottom. You'll also need to replace fetch-config with append-config

Upvotes: 1

mike mckechnie
mike mckechnie

Reputation: 874

I use an .ebextensions file for this purpose. The following cloudwatch.config file is in the .ebextensions directory of my application root. It installs the agent, sets it up as a service, and updates the configuration. The metrics are chosen from the list available from perfmon.

packages:
  msi:
    cloudwatch: https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi
services:
  windows:
    AmazonCloudWatchAgent:
      enabled: 'true'
      ensureRunning: 'true'
      files:
        - "C:/ProgramData/Amazon/AmazonCloudWatchAgent/amazon-cloudwatch-agent.json"
files:
  "C:/ProgramData/Amazon/AmazonCloudWatchAgent/amazon-cloudwatch-agent.json":
    content: |
      {
        "metrics": {
          "namespace": "suprep",
          "append_dimensions": {
            "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
            "ImageId": "${aws:ImageId}",
            "InstanceId": "${aws:InstanceId}",
            "InstanceType": "${aws:InstanceType}"
          },
          "metrics_collected": {
            "LogicalDisk": {
              "measurement": [
                "% Free Space",
                "Avg. Disk Bytes/Transfer"
              ],
              "metrics_collection_interval": 60,
              "resources": [
                "C:"
              ]
            },
            "Memory": {
              "measurement": [
                "Available MBytes",
                "Page Faults/sec",
                "% Committed Bytes In Use"
              ],
              "metrics_collection_interval": 60
            },
            "Network Interface": {
              "measurement": [
                "Bytes Total/sec"
              ],
              "metrics_collection_interval": 60,
              "resources": [
                "_Total"
              ]
            },
            "Paging File": {
              "measurement": [
                "% Usage"
              ],
              "metrics_collection_interval": 60,
              "resources": [
                "_Total"
              ]
            },
            "Process": {
              "measurement": [
                "% Processor Time",
                "Private Bytes"
              ],
              "metrics_collection_interval": 60,
              "resources": [
                "dotnet"
              ]
            }
          }
        },
        "aggregation_dimensions" : [["AutoScalingGroupName"], ["InstanceId"],[]],
        "logs": {
          "logs_collected": {
            "files": {
              "collect_list": [
                {
                  "file_path": "c:\\Windows\\Temp\\log*.txt",
                  "log_group_name": "MyLogGroup",
                  "timezone": "UTC"
                }
              ]
            },
            "windows_events": {
              "collect_list": [
                {
                  "event_name": "System",
                  "event_levels": [
                    "WARNING",
                    "ERROR"
                  ],
                  "log_group_name": "MyLogGroup",
                  "log_stream_name": "System",
                  "event_format": "xml"
                },
                {
                  "event_name": "Application",
                  "event_levels": [
                    "WARNING",
                    "ERROR"
                  ],
                  "log_group_name": "MyLogGroup",
                  "log_stream_name": "Application",
                  "event_format": "xml"
                }
              ]
            }
          },
          "log_stream_name": "MyLogStream"
        }
      }
commands:
  01_stop_service:
    command: powershell -NoProfile -ExecutionPolicy Bypass -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a stop"
  02_start_service:
    command: powershell -NoProfile -ExecutionPolicy Bypass -Command "C:\\'Program Files'\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:C:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\amazon-cloudwatch-agent.json -s"

Upvotes: 1

Related Questions