本文整理汇总了Python中utils.kubernetes.KubeUtil.get_event_retriever方法的典型用法代码示例。如果您正苦于以下问题:Python KubeUtil.get_event_retriever方法的具体用法?Python KubeUtil.get_event_retriever怎么用?Python KubeUtil.get_event_retriever使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.kubernetes.KubeUtil
的用法示例。
在下文中一共展示了KubeUtil.get_event_retriever方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Kubernetes
# 需要导入模块: from utils.kubernetes import KubeUtil [as 别名]
# 或者: from utils.kubernetes.KubeUtil import get_event_retriever [as 别名]
class Kubernetes(AgentCheck):
""" Collect metrics and events from kubelet """
pod_names_by_container = {}
def __init__(self, name, init_config, agentConfig, instances=None):
if instances is not None and len(instances) > 1:
raise Exception('Kubernetes check only supports one configured instance.')
AgentCheck.__init__(self, name, init_config, agentConfig, instances)
inst = instances[0] if instances is not None else None
self.kubeutil = KubeUtil(instance=inst)
if not self.kubeutil.kubelet_api_url:
raise Exception('Unable to reach kubelet. Try setting the host parameter.')
if agentConfig.get('service_discovery') and \
agentConfig.get('service_discovery_backend') == 'docker':
self._sd_backend = get_sd_backend(agentConfig)
else:
self._sd_backend = None
self.k8s_namespace_regexp = None
if inst:
regexp = inst.get('namespace_name_regexp', None)
if regexp:
try:
self.k8s_namespace_regexp = re.compile(regexp)
except re.error as e:
self.log.warning('Invalid regexp for "namespace_name_regexp" in configuration (ignoring regexp): %s' % str(e))
self._collect_events = _is_affirmative(inst.get('collect_events', DEFAULT_COLLECT_EVENTS))
if self._collect_events:
self.event_retriever = self.kubeutil.get_event_retriever()
elif self.kubeutil.collect_service_tag:
# Only fetch service and pod events for service mapping
event_delay = inst.get('service_tag_update_freq', DEFAULT_SERVICE_EVENT_FREQ)
self.event_retriever = self.kubeutil.get_event_retriever(kinds=['Service', 'Pod'],
delay=event_delay)
else:
self.event_retriever = None
else:
self._collect_events = None
self.event_retriever = None
def _perform_kubelet_checks(self, url):
service_check_base = NAMESPACE + '.kubelet.check'
is_ok = True
try:
req = self.kubeutil.perform_kubelet_query(url)
for line in req.iter_lines():
# avoid noise; this check is expected to fail since we override the container hostname
if line.find('hostname') != -1:
continue
matches = re.match('\[(.)\]([^\s]+) (.*)?', line)
if not matches or len(matches.groups()) < 2:
continue
service_check_name = service_check_base + '.' + matches.group(2)
status = matches.group(1)
if status == '+':
self.service_check(service_check_name, AgentCheck.OK)
else:
self.service_check(service_check_name, AgentCheck.CRITICAL)
is_ok = False
except Exception as e:
self.log.warning('kubelet check %s failed: %s' % (url, str(e)))
self.service_check(service_check_base, AgentCheck.CRITICAL,
message='Kubelet check %s failed: %s' % (url, str(e)))
else:
if is_ok:
self.service_check(service_check_base, AgentCheck.OK)
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)
#.........这里部分代码省略.........