def _init_orchestrators(self): # Try to detect if we are on Swarm self.fetch_swarm_state() try: containers = self.client.containers() for co in containers: if '/ecs-agent' in co.get('Names', ''): self._is_ecs = True break elif '/rancher-agent' in co.get('Names', ''): self._is_rancher = True break except Exception as e: if self._no_conf_file: log.debug("Error while detecting orchestrator: %s" % e) else: log.warning("Error while detecting orchestrator: %s" % e) pass try: from utils.kubernetes import detect_is_k8s self._is_k8s = detect_is_k8s() except Exception: self._is_k8s = False
def _init_orchestrators(self): # Try to detect if we are on Swarm self.fetch_swarm_state() try: containers = self.client.containers() for co in containers: if '/ecs-agent' in co.get('Names', ''): self._is_ecs = True break elif '/rancher-agent' in co.get('Names', ''): self._is_rancher = True break except Exception as e: if self._no_conf_file: log.debug("Error while detecting orchestrator: %s" % e) else: log.warning("Error while detecting orchestrator: %s" % e) pass try: from utils.kubernetes import detect_is_k8s self._is_k8s = detect_is_k8s() except Exception: self._is_k8s = False
def __init__(self, **kwargs): self._docker_root = None self.events = [] self.hostname = None self._default_gateway = None if 'init_config' in kwargs and 'instance' in kwargs: init_config = kwargs.get('init_config') instance = kwargs.get('instance') else: init_config, instance = self.get_check_config() self.set_docker_settings(init_config, instance) # At first run we'll just collect the events from the latest 60 secs self._latest_event_collection_ts = int(time.time()) - 60 # Memory cache for sha256 to image name mapping self._image_sha_to_name_mapping = {} # Try to detect if we are on Swarm self.fetch_swarm_state() # Try to detect if an orchestrator is running self._is_ecs = False self._is_rancher = False self._is_k8s = False try: containers = self.client.containers() for co in containers: if '/ecs-agent' in co.get('Names', ''): self._is_ecs = True break elif '/rancher-agent' in co.get('Names', ''): self._is_rancher = True break except Exception as e: log.warning("Error while detecting orchestrator: %s" % e) pass try: from utils.kubernetes import detect_is_k8s self._is_k8s = detect_is_k8s() except Exception: self._is_k8s = False # Build include/exclude patterns for containers self._include, self._exclude = instance.get('include', []), instance.get( 'exclude', []) if not self._exclude: # In Kubernetes, pause containers are not interesting to monitor. # This part could be reused for other platforms where containers can be safely ignored. if self.is_k8s(): self.filtering_enabled = True self._exclude = DEFAULT_CONTAINER_EXCLUDE else: if self._include: log.warning( "You must specify an exclude section to enable filtering" ) self.filtering_enabled = False else: self.filtering_enabled = True if self.filtering_enabled: self.build_filters()
def __init__(self, **kwargs): self._docker_root = None self.events = [] self.hostname = None self._default_gateway = None if 'init_config' in kwargs and 'instance' in kwargs: init_config = kwargs.get('init_config') instance = kwargs.get('instance') else: init_config, instance = self.get_check_config() self.set_docker_settings(init_config, instance) # At first run we'll just collect the events from the latest 60 secs self._latest_event_collection_ts = int(time.time()) - 60 # Memory cache for sha256 to image name mapping self._image_sha_to_name_mapping = {} # Try to detect if we are on Swarm self.fetch_swarm_state() # Try to detect if an orchestrator is running self._is_ecs = False self._is_rancher = False self._is_k8s = False try: containers = self.client.containers() for co in containers: if '/ecs-agent' in co.get('Names', ''): self._is_ecs = True break elif '/rancher-agent' in co.get('Names', ''): self._is_rancher = True break except Exception as e: log.warning("Error while detecting orchestrator: %s" % e) pass try: from utils.kubernetes import detect_is_k8s self._is_k8s = detect_is_k8s() except Exception: self._is_k8s = False # Build include/exclude patterns for containers self._include, self._exclude = instance.get('include', []), instance.get('exclude', []) if not self._exclude: # In Kubernetes, pause containers are not interesting to monitor. # This part could be reused for other platforms where containers can be safely ignored. if self.is_k8s(): self.filtering_enabled = True self._exclude = DEFAULT_CONTAINER_EXCLUDE else: if self._include: log.warning("You must specify an exclude section to enable filtering") self.filtering_enabled = False else: self.filtering_enabled = True if self.filtering_enabled: self.build_filters()