当前位置: 首页>>代码示例>>Python>>正文


Python KubeUtil.process_events方法代码示例

本文整理汇总了Python中utils.kubernetes.KubeUtil.process_events方法的典型用法代码示例。如果您正苦于以下问题:Python KubeUtil.process_events方法的具体用法?Python KubeUtil.process_events怎么用?Python KubeUtil.process_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.kubernetes.KubeUtil的用法示例。


在下文中一共展示了KubeUtil.process_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Kubernetes

# 需要导入模块: from utils.kubernetes import KubeUtil [as 别名]
# 或者: from utils.kubernetes.KubeUtil import process_events [as 别名]

#.........这里部分代码省略.........
            else:
                self.service_check(service_check_base, AgentCheck.CRITICAL)

    def check(self, instance):
        self.max_depth = instance.get('max_depth', DEFAULT_MAX_DEPTH)
        enabled_gauges = instance.get('enabled_gauges', DEFAULT_ENABLED_GAUGES)
        self.enabled_gauges = ["{0}.{1}".format(NAMESPACE, x) for x in enabled_gauges]
        enabled_rates = instance.get('enabled_rates', DEFAULT_ENABLED_RATES)
        self.enabled_rates = ["{0}.{1}".format(NAMESPACE, x) for x in enabled_rates]

        self.publish_aliases = _is_affirmative(instance.get('publish_aliases', DEFAULT_PUBLISH_ALIASES))
        self.use_histogram = _is_affirmative(instance.get('use_histogram', DEFAULT_USE_HISTOGRAM))
        self.publish_rate = FUNC_MAP[RATE][self.use_histogram]
        self.publish_gauge = FUNC_MAP[GAUGE][self.use_histogram]
        # initialized by _filter_containers
        self._filtered_containers = set()

        try:
            pods_list = self.kubeutil.retrieve_pods_list()
        except:
            pods_list = None

        # kubelet health checks
        self._perform_kubelet_checks(self.kubeutil.kube_health_url)

        if pods_list is not None:
            # kubelet metrics
            self._update_metrics(instance, pods_list)

        # kubelet events
        if self.event_retriever is not None:
            try:
                events = self.event_retriever.get_event_array()
                changed_cids = self.kubeutil.process_events(events, podlist=pods_list)
                if (changed_cids and self._sd_backend):
                    self._sd_backend.update_checks(changed_cids)
                if events and self._collect_events:
                    self._update_kube_events(instance, pods_list, events)
            except Exception as ex:
                self.log.error("Event collection failed: %s" % str(ex))

    def _publish_raw_metrics(self, metric, dat, tags, depth=0):
        if depth >= self.max_depth:
            self.log.warning('Reached max depth on metric=%s' % metric)
            return

        if isinstance(dat, numbers.Number):
            if self.enabled_rates and any([fnmatch(metric, pat) for pat in self.enabled_rates]):
                self.publish_rate(self, metric, float(dat), tags)
            elif self.enabled_gauges and any([fnmatch(metric, pat) for pat in self.enabled_gauges]):
                self.publish_gauge(self, metric, float(dat), tags)

        elif isinstance(dat, dict):
            for k, v in dat.iteritems():
                self._publish_raw_metrics(metric + '.%s' % k.lower(), v, tags, depth + 1)

        elif isinstance(dat, list):
            self._publish_raw_metrics(metric, dat[-1], tags, depth + 1)

    @staticmethod
    def _shorten_name(name):
        # shorten docker image id
        return re.sub('([0-9a-fA-F]{64,})', lambda x: x.group(1)[0:12], name)

    def _get_post_1_2_tags(self, cont_labels, subcontainer, kube_labels):
        tags = []
开发者ID:dblackdblack,项目名称:integrations-core,代码行数:70,代码来源:check.py


注:本文中的utils.kubernetes.KubeUtil.process_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。