python/ray/autoscaler/_private/aws/cloudwatch/cloudwatch_helper.py
def ssm_install_cloudwatch_agent(self):
        """Install and Start CloudWatch Agent via Systems Manager (SSM)"""

        # wait for all EC2 instance checks to complete
        try:
            logger.info(
                "Waiting for EC2 instance health checks to complete before "
                "installing CloudWatch Unified Agent. This may take a few "
                "minutes...")
            waiter = self.ec2_client.get_waiter("instance_status_ok")
            waiter.wait(InstanceIds=list(self.node_ids))
        except botocore.exceptions.WaiterError as e:
            logger.error(
                "Failed while waiting for EC2 instance checks to complete: {}".
                format(e.message))
            raise e

        # install the cloudwatch agent on each cluster node
        parameters_cwa_install = {
            "action": ["Install"],
            "name": ["AmazonCloudWatchAgent"],
            "version": ["latest"]
        }
        logger.info(
            "Installing the CloudWatch Unified Agent package on {} nodes. "
            "This may take a few minutes as we wait for all package updates "
            "to complete...".format(len(self.node_ids)))
        try:
            self._ssm_command_waiter(
                "AWS-ConfigureAWSPackage",
                parameters_cwa_install,
            )
            logger.info(
                "Successfully installed CloudWatch Unified Agent on {} nodes".
                format(len(self.node_ids)))
        except botocore.exceptions.WaiterError as e:
            logger.error(
                "Failed while waiting for SSM CloudWatch Unified Agent "
                "package install command to complete on all cluster nodes: {}"
                .format(e))
            raise e

        # upload cloudwatch agent config to the SSM parameter store
        logger.info(
            "Uploading CloudWatch Unified Agent config to the SSM parameter"
            "store.")
        cwa_config = self._load_config_file("agent")
        self._replace_all_config_variables(
            cwa_config,
            None,
            self.cluster_name,
            self.provider_config["region"],
        )
        cwa_config_ssm_param_name = "{}_{}".format(
            CWA_CONFIG_SSM_PARAM_NAME_BASE,
            self.cluster_name,
        )
        self.ssm_client.put_parameter(
            Name=cwa_config_ssm_param_name,
            Type="String",
            Value=json.dumps(cwa_config),
            Overwrite=True,
        )

        # satisfy collectd preconditions before starting cloudwatch agent
        logger.info("Preparing to start CloudWatch Unified Agent on {} nodes."
                    .format(len(self.node_ids)))
        parameters_run_shell = {
            "commands": [
                "mkdir -p /usr/share/collectd/",
                "touch /usr/share/collectd/types.db"
            ],
        }
        self._ssm_command_waiter(
            "AWS-RunShellScript",
            parameters_run_shell,
        )

        # start cloudwatch agent
        logger.info("Starting CloudWatch Unified Agent package on {} nodes."
                    .format(len(self.node_ids)))
        parameters_start_cwa = {
            "action": ["configure"],
            "mode": ["ec2"],
            "optionalConfigurationSource": ["ssm"],
            "optionalConfigurationLocation": [cwa_config_ssm_param_name],
            "optionalRestart": ["yes"],
        }
        self._ssm_command_waiter(
            "AmazonCloudWatch-ManageAgent",
            parameters_start_cwa,
        )
        logger.info(
            "CloudWatch Unified Agent started successfully on all nodes."
            .format(len(self.node_ids)))
Install and Start CloudWatch Agent via Systems Manager (SSM)
Install and Start CloudWatch Agent via Systems Manager (SSM)
Install and Start CloudWatch Agent via Systems Manager ( SSM )
def ssm_install_cloudwatch_agent(self):
        try:
            logger.info(
                "Waiting for EC2 instance health checks to complete before "
                "installing CloudWatch Unified Agent. This may take a few "
                "minutes...")
            waiter = self.ec2_client.get_waiter("instance_status_ok")
            waiter.wait(InstanceIds=list(self.node_ids))
        except botocore.exceptions.WaiterError as e:
            logger.error(
                "Failed while waiting for EC2 instance checks to complete: {}".
                format(e.message))
            raise e
        parameters_cwa_install = {
            "action": ["Install"],
            "name": ["AmazonCloudWatchAgent"],
            "version": ["latest"]
        }
        logger.info(
            "Installing the CloudWatch Unified Agent package on {} nodes. "
            "This may take a few minutes as we wait for all package updates "
            "to complete...".format(len(self.node_ids)))
        try:
            self._ssm_command_waiter(
                "AWS-ConfigureAWSPackage",
                parameters_cwa_install,
            )
            logger.info(
                "Successfully installed CloudWatch Unified Agent on {} nodes".
                format(len(self.node_ids)))
        except botocore.exceptions.WaiterError as e:
            logger.error(
                "Failed while waiting for SSM CloudWatch Unified Agent "
                "package install command to complete on all cluster nodes: {}"
                .format(e))
            raise e
        logger.info(
            "Uploading CloudWatch Unified Agent config to the SSM parameter"
            "store.")
        cwa_config = self._load_config_file("agent")
        self._replace_all_config_variables(
            cwa_config,
            None,
            self.cluster_name,
            self.provider_config["region"],
        )
        cwa_config_ssm_param_name = "{}_{}".format(
            CWA_CONFIG_SSM_PARAM_NAME_BASE,
            self.cluster_name,
        )
        self.ssm_client.put_parameter(
            Name=cwa_config_ssm_param_name,
            Type="String",
            Value=json.dumps(cwa_config),
            Overwrite=True,
        )
        logger.info("Preparing to start CloudWatch Unified Agent on {} nodes."
                    .format(len(self.node_ids)))
        parameters_run_shell = {
            "commands": [
                "mkdir -p /usr/share/collectd/",
                "touch /usr/share/collectd/types.db"
            ],
        }
        self._ssm_command_waiter(
            "AWS-RunShellScript",
            parameters_run_shell,
        )
        logger.info("Starting CloudWatch Unified Agent package on {} nodes."
                    .format(len(self.node_ids)))
        parameters_start_cwa = {
            "action": ["configure"],
            "mode": ["ec2"],
            "optionalConfigurationSource": ["ssm"],
            "optionalConfigurationLocation": [cwa_config_ssm_param_name],
            "optionalRestart": ["yes"],
        }
        self._ssm_command_waiter(
            "AmazonCloudWatch-ManageAgent",
            parameters_start_cwa,
        )
        logger.info(
            "CloudWatch Unified Agent started successfully on all nodes."
            .format(len(self.node_ids)))
def ssm_install_cloudwatch_agent ( self ) : try : logger . info ( "Waiting for EC2 instance health checks to complete before " "installing CloudWatch Unified Agent. This may take a few " "minutes..." ) waiter = self . ec2_client . get_waiter ( "instance_status_ok" ) waiter . wait ( InstanceIds = list ( self . node_ids ) ) except botocore . exceptions . WaiterError as e : logger . error ( "Failed while waiting for EC2 instance checks to complete: {}" . format ( e . message ) ) raise e parameters_cwa_install = { "action" : [ "Install" ] , "name" : [ "AmazonCloudWatchAgent" ] , "version" : [ "latest" ] } logger . info ( "Installing the CloudWatch Unified Agent package on {} nodes. " "This may take a few minutes as we wait for all package updates " "to complete..." . format ( len ( self . node_ids ) ) ) try : self . _ssm_command_waiter ( "AWS-ConfigureAWSPackage" , parameters_cwa_install , ) logger . info ( "Successfully installed CloudWatch Unified Agent on {} nodes" . format ( len ( self . node_ids ) ) ) except botocore . exceptions . WaiterError as e : logger . error ( "Failed while waiting for SSM CloudWatch Unified Agent " "package install command to complete on all cluster nodes: {}" . format ( e ) ) raise e logger . info ( "Uploading CloudWatch Unified Agent config to the SSM parameter" "store." ) cwa_config = self . _load_config_file ( "agent" ) self . _replace_all_config_variables ( cwa_config , None , self . cluster_name , self . provider_config [ "region" ] , ) cwa_config_ssm_param_name = "{}_{}" . format ( CWA_CONFIG_SSM_PARAM_NAME_BASE , self . cluster_name , ) self . ssm_client . put_parameter ( Name = cwa_config_ssm_param_name , Type = "String" , Value = json . dumps ( cwa_config ) , Overwrite = True , ) logger . info ( "Preparing to start CloudWatch Unified Agent on {} nodes." . format ( len ( self . node_ids ) ) ) parameters_run_shell = { "commands" : [ "mkdir -p /usr/share/collectd/" , "touch /usr/share/collectd/types.db" ] , } self . _ssm_command_waiter ( "AWS-RunShellScript" , parameters_run_shell , ) logger . info ( "Starting CloudWatch Unified Agent package on {} nodes." . format ( len ( self . node_ids ) ) ) parameters_start_cwa = { "action" : [ "configure" ] , "mode" : [ "ec2" ] , "optionalConfigurationSource" : [ "ssm" ] , "optionalConfigurationLocation" : [ cwa_config_ssm_param_name ] , "optionalRestart" : [ "yes" ] , } self . _ssm_command_waiter ( "AmazonCloudWatch-ManageAgent" , parameters_start_cwa , ) logger . info ( "CloudWatch Unified Agent started successfully on all nodes." . format ( len ( self . node_ids ) ) )
Install and Start CloudWatch Agent via Systems Manager (SSM)
Install and Start CloudWatch Agent via Systems Manager ( SSM )
"""Install and Start CloudWatch Agent via Systems Manager (SSM)""" # wait for all EC2 instance checks to complete # install the cloudwatch agent on each cluster node # upload cloudwatch agent config to the SSM parameter store # satisfy collectd preconditions before starting cloudwatch agent # start cloudwatch agent
self