cloudformation/ec2-asg.yaml [477:558]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
               mode: '000400'
               owner: root
               group: root
        CloudwatchSetup:
          files:
            # https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html
            /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json:
              content: !Sub |
                {
                  "metrics": {
                    "append_dimensions": {
                      "ImageId": "${!aws:ImageId}",
                      "InstanceId": "${!aws:InstanceId}",
                      "InstanceType": "${!aws:InstanceType}"
                    },
                    "metrics_collected": {
                      "mem": {
                        "measurement": [
                          "mem_used_percent"
                        ]
                      }
                    }
                  },
                  "logs": {
                    "logs_collected": {
                      "files": {
                        "collect_list": [
                          {
                            "file_path": "/var/log/torchserve/ts_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "ApplicationLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/ts_metrics.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "TorchServeMetrics",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/access_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "AccessLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/model_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "ModelLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/model_metrics.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "TorchServeModelMetrics",
                            "timezone": "UTC"
                          }
                        ]
                      }
                    }
                  }
                }
          commands:
            01_stop_service:
              command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop
            02_start_service:
              command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
        CFNSetup:
          files:
            /etc/cfn/cfn-hup.conf:
               content: !Sub |
                 [main]
                 stack=${AWS::StackId}
                 region=${AWS::Region}
                 interval=1
               mode: '000400'
               owner: root
               group: root
            /etc/cfn/hooks.d/cfn-auto-reloader.conf:
               content: !Sub |
                 [cfn-auto-reloader-hook]
                 triggers=post.update
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



cloudformation/ec2.yaml [275:356]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
               mode: '000400'
               owner: root
               group: root
        CloudwatchSetup:
          files:
            # https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html
            /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json:
              content: !Sub |
                {
                  "metrics": {
                    "append_dimensions": {
                      "ImageId": "${!aws:ImageId}",
                      "InstanceId": "${!aws:InstanceId}",
                      "InstanceType": "${!aws:InstanceType}"
                    },
                    "metrics_collected": {
                      "mem": {
                        "measurement": [
                          "mem_used_percent"
                        ]
                      }
                    }
                  },
                  "logs": {
                    "logs_collected": {
                      "files": {
                        "collect_list": [
                          {
                            "file_path": "/var/log/torchserve/ts_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "ApplicationLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/ts_metrics.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "TorchServeMetrics",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/access_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "AccessLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/model_log.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "ModelLogs",
                            "timezone": "UTC"
                          },
                          {
                            "file_path": "/var/log/torchserve/model_metrics.log",
                            "log_group_name": "${AWS::StackName}/{instance_id}/TorchServe",
                            "log_stream_name": "TorchServeModelMetrics",
                            "timezone": "UTC"
                          }
                        ]
                      }
                    }
                  }
                }
          commands:
            01_stop_service:
              command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a stop
            02_start_service:
              command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s
        CFNSetup:
          files:
            /etc/cfn/cfn-hup.conf:
               content: !Sub |
                 [main]
                 stack=${AWS::StackId}
                 region=${AWS::Region}
                 interval=1
               mode: '000400'
               owner: root
               group: root
            /etc/cfn/hooks.d/cfn-auto-reloader.conf:
               content: !Sub |
                 [cfn-auto-reloader-hook]
                 triggers=post.update
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



