def initialize()

in azurelinuxagent/ga/cgroupconfigurator.py [0:0]


        def initialize(self):
            try:
                if self._initialized:
                    return
                # check whether cgroup monitoring is supported on the current distro
                self._cgroups_supported = self._check_cgroups_supported()
                if not self._cgroups_supported:
                    # If a distro is not supported, attempt to clean up any existing drop in files in case it was
                    # previously supported. It is necessary to cleanup in this scenario in case the OS hits any bugs on
                    # the kernel related to cgroups.
                    if not self.using_cgroup_v2():
                        log_cgroup_info("Agent will reset the quotas in case cgroup usage went from enabled to disabled")
                        self._reset_agent_cgroup_setup()
                    return

                # We check the agent unit 'Slice' property before setting up azure.slice. This check is done first
                # because the agent's Slice unit property will be 'azure.slice' if the slice drop-in file exists, even
                # though systemd has not moved the agent to azure.slice yet. Systemd will only move the agent to
                # azure.slice after a vm restart.
                agent_unit_name = systemd.get_agent_unit_name()
                agent_slice = systemd.get_unit_property(agent_unit_name, "Slice")
                if agent_slice not in (AZURE_SLICE, "system.slice"):
                    log_cgroup_warning("The agent is within an unexpected slice: {0}".format(agent_slice))
                    return

                # Before agent setup, cleanup the old agent setup (drop-in files) since new agent uses different approach(systemctl) to setup cgroups.
                self._cleanup_old_agent_setup()

                # Notes about slice setup:
                #   For machines where daemon version did not already create azure.slice, the
                #   agent creates azure.slice and the agent unit Slice drop-in file(without daemon-reload), but systemd does not move the agent
                #   unit to azure.slice until vm restart. It is ok to enable cgroup usage in this case if agent is
                #   running in system.slice.
                self._setup_azure_slice()

                # Log mount points/root paths for cgroup controllers
                self._cgroups_api.log_root_paths()

                # Get agent cgroup
                self._agent_cgroup = self._cgroups_api.get_unit_cgroup(unit_name=agent_unit_name, cgroup_name=AGENT_NAME_TELEMETRY)

                if conf.get_cgroup_disable_on_process_check_failure() and self._check_fails_if_processes_found_in_agent_cgroup_before_enable(agent_slice):
                    reason = "Found unexpected processes in the agent cgroup before agent enable cgroups."
                    self.disable(reason, DisableCgroups.ALL)
                    return

                # Get controllers to track
                agent_controllers = self._agent_cgroup.get_controllers(expected_relative_path=os.path.join(agent_slice, agent_unit_name))
                if len(agent_controllers) > 0:
                    self.enable()
                    self._enable_accounting(agent_unit_name)

                for controller in agent_controllers:
                    for prop in controller.get_unit_properties():
                        log_cgroup_info('Agent {0} unit property value: {1}'.format(prop, systemd.get_unit_property(systemd.get_agent_unit_name(), prop)))
                    if isinstance(controller, _CpuController):
                        self._set_cpu_quota(agent_unit_name, conf.get_agent_cpu_quota())
                    elif isinstance(controller, _MemoryController):
                        self._agent_memory_metrics = controller
                    CGroupsTelemetry.track_cgroup_controller(controller)

            except Exception as exception:
                log_cgroup_warning("Error initializing cgroups: {0}".format(ustr(exception)))
            finally:
                log_cgroup_info('Agent cgroups enabled: {0}'.format(self._agent_cgroups_enabled))
                self._initialized = True