def check_aws_metrics( metric_infos: List[Dict[str, Union[float, Optional[str], Optional[Tuple], Optional[Callable]]]] ) -> Iterable[ServiceCheckResult]: go_stale = True for metric_info in metric_infos: metric_val = metric_info["metric_val"] if metric_val is None: continue go_stale = False yield check_levels( metric_val, # type: ignore[arg-type] metric_info.get("metric_name"), # type: ignore[arg-type] metric_info.get("levels"), human_readable_func=metric_info.get( "human_readable_func"), # type: ignore[arg-type] infoname=metric_info.get("info_name"), # type: ignore[arg-type] ) if go_stale: raise MKCounterWrapped("Currently no data from AWS")
def wrapped_check_function(item, params, parsed): if not isinstance(parsed, dict): return 3, "Wrong usage of decorator function 'aws_get_parsed_item_data': parsed is " \ "not a dict" if item not in parsed: raise MKCounterWrapped("Currently no data from AWS") return check_function(item, params, parsed[item])
def get( self, row: Union[str, int], column: Union[str, int], silently_skip_timed_out=False, ) -> Optional[str]: if not silently_skip_timed_out and self.timed_out: raise MKCounterWrapped("WMI query timed out") return self._get_row_col_value(row, column)
def is_ibm_mq_service_vanished(item, parsed): """ Returns true if queue or channel is not contained anymore in the agent output but queue manager is known as RUNNING. Throws MKCounterWrapped to mark service as STALE if QMGR is not RUNNING. """ if item in parsed: return False qmgr_name = item.split(':', 1)[0] qmgr_status = "RUNNING" if qmgr_name in parsed: qmgr_status = parsed[qmgr_name]["STATUS"] if qmgr_status == "RUNNING": return True raise MKCounterWrapped("Stale because queue manager %s" % qmgr_status)
def check_aws_http_errors(params, parsed, http_err_codes, cloudwatch_metrics_format, key_all_requests='RequestCount'): request_rate = parsed.get(key_all_requests) if request_rate is None: raise MKCounterWrapped("Currently no data from AWS") yield check_aws_request_rate(request_rate) for http_err_code in http_err_codes: # CloudWatch only reports HTTPCode_... if the value is nonzero for result in check_aws_error_rate( parsed.get(cloudwatch_metrics_format % http_err_code.upper(), 0), request_rate, 'aws_http_%s_rate' % http_err_code, 'aws_http_%s_perc' % http_err_code, params.get('levels_http_%s_perc' % http_err_code), "%s-Errors" % http_err_code.upper()): yield result
def check_aws_metrics( metric_infos: List[Dict[str, Union[float, Optional[str], Optional[Tuple], Optional[Callable]]]] ) -> Iterable[ServiceCheckResult]: go_stale = True for metric_info in metric_infos: metric_val = metric_info['metric_val'] if metric_val is None: continue go_stale = False yield check_levels(metric_val, metric_info.get('metric_name'), metric_info.get('levels'), human_readable_func=metric_info.get('human_readable_func'), infoname=metric_info.get('info_name')) if go_stale: raise MKCounterWrapped("Currently no data from AWS")
def wrapped_check_function(item, params, parsed): if not isinstance(parsed, dict): return 3, "Wrong usage of decorator: parsed is not a dict" if item not in parsed or not parsed[item]: raise MKCounterWrapped("Data not present at the moment") return check_function(item, params, parsed[item])
def check_cpu_util_unix(values: CPUInfo, params, cores=None, values_counter=True): this_time = time.time() if values_counter: diff_values = util_counter(values, this_time) sum_jiffies = diff_values.total_sum if sum_jiffies == 0: raise MKCounterWrapped("Too short time difference since last check") user_perc, system_perc, wait_perc, steal_perc, guest_perc, util_total_perc = diff_values.utils_perc else: user_perc = values.user system_perc = values.system wait_perc = values.iowait steal_perc = values.steal guest_perc = values.guest util_total_perc = values.util_total yield check_levels(user_perc, 'user', None, human_readable_func=get_percent_human_readable, infoname="User") yield check_levels(system_perc, 'system', None, human_readable_func=get_percent_human_readable, infoname="System") yield check_levels(wait_perc, 'wait', params.get('iowait'), human_readable_func=get_percent_human_readable, infoname="Wait") # Compute values used in virtualized environments (Xen, etc.) # Only do this for counters that have counted at least one tick # since the system boot. This avoids silly output in systems # where these counters are not being used if values.steal: yield check_levels(steal_perc, "steal", params.get('steal'), human_readable_func=get_percent_human_readable, infoname="Steal") if values.guest: yield check_levels(guest_perc, 'guest', None, human_readable_func=get_percent_human_readable, infoname="Guest") summary_cores = [] if cores: for core in cores: prev_total = get_item_state("cpu.util.%s.total" % core.name, 0) util_total = core.util_total total_diff = util_total - prev_total set_item_state("cpu.util.%s.total" % core.name, util_total) total_perc = (100.0 * total_diff / sum_jiffies) * len(cores) summary_cores.append((core.name, total_perc)) for check_result in check_cpu_util(util_total_perc, params, this_time, summary_cores, perf_max=None): yield check_result
def get(self, row, column, silently_skip_timed_out=False): if not silently_skip_timed_out and self.timed_out: raise MKCounterWrapped('WMI query timed out') return self._get_row_col_value(row, column)