docker_helper.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:docker-enforcer 作者: piontec 项目源码 文件源码
def check_container(self, container_id: str, check_source: CheckSource, remove_from_cache: bool=False) \
            -> Optional[Container]:
        try:
            if remove_from_cache:
                self.remove_from_cache(container_id)

            if not self._config.disable_params:
                params = self.get_params(container_id)
            else:
                params = {}
            if not self._config.disable_metrics:
                logger.debug("[{0}] Starting to fetch metrics for {1}".format(threading.current_thread().name,
                                                                              container_id))
                metrics = self._client.stats(container=container_id, decode=True, stream=False)
            else:
                metrics = {}
            logger.debug("[{0}] Fetched data for container {1}".format(threading.current_thread().name, container_id))
        except NotFound as e:
            logger.warning("Container {0} not found - {1}.".format(container_id, e))
            return None
        except (ReadTimeout, ProtocolError, JSONDecodeError) as e:
            logger.error("Communication error when fetching info about container {0}: {1}".format(container_id, e))
            return None
        except Exception as e:
            logger.error("Unexpected error when fetching info about container {0}: {1}".format(container_id, e))
            return None
        if params is None or metrics is None:
            logger.warning("Params or metrics were not fetched for container {}. Not returning container."
                           .format(container_id))
            return None
        return Container(container_id, params, metrics, 0, check_source)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号