templates/clickhouse.arm.template.yaml [1491:1657]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  ClickHouseInstance3: 
    Condition: 4NodesCondition
    Type: AWS::EC2::Instance
    Metadata:
      Comment: Install ClickHouse replica 1
      AWS::CloudFormation::Authentication:
        S3AccessCreds:
          type: S3
          roleName: !Ref ClickHouseInstanceRole
      AWS::CloudFormation::Init:
        configSets:
          default:
            - 01_setupCfnHup
            - 02_config-amazon-cloudwatch-agent
            - 03_restart_amazon-cloudwatch-agent
          UpdateEnvironment:
            - 02_config-amazon-cloudwatch-agent
            - 03_restart_amazon-cloudwatch-agent
        # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below.
        02_config-amazon-cloudwatch-agent:
          files:
            '/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json':
              content: !Sub |
                {
                  "agent": {
                    "metrics_collection_interval": 1,
                    "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
                  },
                  "metrics": {
                    "append_dimensions": {
                      "AutoScalingGroupName": "${!aws:AutoScalingGroupName}",
                      "ImageId": "${!aws:ImageId}",
                      "InstanceId": "${!aws:InstanceId}",
                      "InstanceType": "${!aws:InstanceType}"
                    },
                    "namespace": "ClickHouseNamespace",
                    "metrics_collected": {
                      "mem": {
                        "measurement": [
                          "mem_used_percent"
                        ]
                      },
                      "cpu": {
                        "resources": [
                          "*"
                        ],
                        "measurement": [
                          {"name": "cpu_usage_idle", "rename": "CPU_USAGE_IDLE", "unit": "Percent"},
                          {"name": "cpu_usage_nice", "unit": "Percent"},
                          {"name": "cpu_usage_user", "unit": "Percent"},
                          {"name": "cpu_usage_system", "unit": "Percent"}
                        ],
                        "totalcpu": true,
                        "metrics_collection_interval": 10
                      },
                      "disk": {
                        "resources": [
                          "/"
                        ],
                        "measurement": [
                          "used_percent",
                          "total",
                          "used"
                        ],
                        "ignore_file_system_types": [
                          "sysfs", "devtmpfs"
                        ],
                        "metrics_collection_interval": 60
                      },
                      "diskio": {
                        "resources": [
                          "*"
                        ],
                        "measurement": [
                          "reads",
                          "writes",
                          "read_time",
                          "write_time",
                          "io_time"
                        ],
                        "metrics_collection_interval": 60
                      },
                      "swap": {
                        "measurement": [
                          "swap_used_percent"
                        ]
                      },
                      "net": {
                        "resources": [
                          "eth0"
                        ],
                        "measurement": [
                          "bytes_sent",
                          "bytes_recv",
                          "drop_in",
                          "drop_out"
                        ]
                      }
                    }
                  },
                  "logs": {
                    "force_flush_interval": 5,
                    "logs_collected": {
                      "files": {
                        "collect_list": [
                          {
                            "file_path": "/var/log/clickhouse-server/clickhouse-server.log",
                            "log_group_name": "${ClickHouseMainLogGroup}",
                            "log_stream_name": "${ClickHouseNodeName3}",
                            "timestamp_format": "%Y-%m-%d %H:%M:%S",
                            "timezone": "UTC"
                          }
                        ]
                      }
                    }
                  }
                }
        # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent.
        03_restart_amazon-cloudwatch-agent:
          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
        # Cfn-hup setting, it is to monitor the change of metadata.
        # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent.
        01_setupCfnHup:
          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/amazon-cloudwatch-agent-auto-reloader.conf':
               content: !Sub |
                 [cfn-auto-reloader-hook]
                 triggers=post.update
                 path=Resources.ClickHouseInstance3.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent
                 action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource ClickHouseInstance3 --region ${AWS::Region} --configsets UpdateEnvironment
                 runas=root
               mode: '000400'
               owner: root
               group: root
             "/lib/systemd/system/cfn-hup.service":
                content: |
                  [Unit]
                  Description=cfn-hup daemon
                  [Service]
                  Type=simple
                  ExecStart=/opt/aws/bin/cfn-hup
                  Restart=always
                  [Install]
                  WantedBy=multi-user.target
          commands:
            01enable_cfn_hup:
              command: |
                systemctl enable cfn-hup.service
            02start_cfn_hup:
              command: |
                systemctl start cfn-hup.service
    Properties:
      KeyName: !Ref KeyPairName
      IamInstanceProfile: !Ref ClickHouseInstanceProfile
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



templates/clickhouse.template.yaml [1307:1473]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  ClickHouseInstance3: 
    Condition: 4NodesCondition
    Type: AWS::EC2::Instance
    Metadata:
      Comment: Install ClickHouse replica 1
      AWS::CloudFormation::Authentication:
        S3AccessCreds:
          type: S3
          roleName: !Ref ClickHouseInstanceRole
      AWS::CloudFormation::Init:
        configSets:
          default:
            - 01_setupCfnHup
            - 02_config-amazon-cloudwatch-agent
            - 03_restart_amazon-cloudwatch-agent
          UpdateEnvironment:
            - 02_config-amazon-cloudwatch-agent
            - 03_restart_amazon-cloudwatch-agent
        # Definition of json configuration of AmazonCloudWatchAgent, you can change the configuration below.
        02_config-amazon-cloudwatch-agent:
          files:
            '/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json':
              content: !Sub |
                {
                  "agent": {
                    "metrics_collection_interval": 1,
                    "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
                  },
                  "metrics": {
                    "append_dimensions": {
                      "AutoScalingGroupName": "${!aws:AutoScalingGroupName}",
                      "ImageId": "${!aws:ImageId}",
                      "InstanceId": "${!aws:InstanceId}",
                      "InstanceType": "${!aws:InstanceType}"
                    },
                    "namespace": "ClickHouseNamespace",
                    "metrics_collected": {
                      "mem": {
                        "measurement": [
                          "mem_used_percent"
                        ]
                      },
                      "cpu": {
                        "resources": [
                          "*"
                        ],
                        "measurement": [
                          {"name": "cpu_usage_idle", "rename": "CPU_USAGE_IDLE", "unit": "Percent"},
                          {"name": "cpu_usage_nice", "unit": "Percent"},
                          {"name": "cpu_usage_user", "unit": "Percent"},
                          {"name": "cpu_usage_system", "unit": "Percent"}
                        ],
                        "totalcpu": true,
                        "metrics_collection_interval": 10
                      },
                      "disk": {
                        "resources": [
                          "/"
                        ],
                        "measurement": [
                          "used_percent",
                          "total",
                          "used"
                        ],
                        "ignore_file_system_types": [
                          "sysfs", "devtmpfs"
                        ],
                        "metrics_collection_interval": 60
                      },
                      "diskio": {
                        "resources": [
                          "*"
                        ],
                        "measurement": [
                          "reads",
                          "writes",
                          "read_time",
                          "write_time",
                          "io_time"
                        ],
                        "metrics_collection_interval": 60
                      },
                      "swap": {
                        "measurement": [
                          "swap_used_percent"
                        ]
                      },
                      "net": {
                        "resources": [
                          "eth0"
                        ],
                        "measurement": [
                          "bytes_sent",
                          "bytes_recv",
                          "drop_in",
                          "drop_out"
                        ]
                      }
                    }
                  },
                  "logs": {
                    "force_flush_interval": 5,
                    "logs_collected": {
                      "files": {
                        "collect_list": [
                          {
                            "file_path": "/var/log/clickhouse-server/clickhouse-server.log",
                            "log_group_name": "${ClickHouseMainLogGroup}",
                            "log_stream_name": "${ClickHouseNodeName3}",
                            "timestamp_format": "%Y-%m-%d %H:%M:%S",
                            "timezone": "UTC"
                          }
                        ]
                      }
                    }
                  }
                }
        # Invoke amazon-cloudwatch-agent-ctl to restart the AmazonCloudWatchAgent.
        03_restart_amazon-cloudwatch-agent:
          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
        # Cfn-hup setting, it is to monitor the change of metadata.
        # When there is change in the contents of json file in the metadata section, cfn-hup will call cfn-init to restart the AmazonCloudWatchAgent.
        01_setupCfnHup:
          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/amazon-cloudwatch-agent-auto-reloader.conf':
               content: !Sub |
                 [cfn-auto-reloader-hook]
                 triggers=post.update
                 path=Resources.ClickHouseInstance3.Metadata.AWS::CloudFormation::Init.02_config-amazon-cloudwatch-agent
                 action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackId} --resource ClickHouseInstance3 --region ${AWS::Region} --configsets UpdateEnvironment
                 runas=root
               mode: '000400'
               owner: root
               group: root
             "/lib/systemd/system/cfn-hup.service":
                content: |
                  [Unit]
                  Description=cfn-hup daemon
                  [Service]
                  Type=simple
                  ExecStart=/opt/aws/bin/cfn-hup
                  Restart=always
                  [Install]
                  WantedBy=multi-user.target
          commands:
            01enable_cfn_hup:
              command: |
                systemctl enable cfn-hup.service
            02start_cfn_hup:
              command: |
                systemctl start cfn-hup.service
    Properties:
      KeyName: !Ref KeyPairName
      IamInstanceProfile: !Ref ClickHouseInstanceProfile
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



