def _get_value(self, metric): if metric.type == MetricType.Discovery: metric.callback() return self._correct_type(metric.type, self.test_data) key = metric.kwargs.get("key") if self.first_ip is None: raise CheckFail("Required parameter 'firstip' missing.") if self.first_ip not in self.test_data: raise CheckFail("Specified first ip (%s) not found in data" % self.first_ip) return self._correct_type(metric.type, self.test_data[self.first_ip][key])
def _filter_data(self): if self.pxname is None or self.svname is None: raise CheckFail("Required parameters not set (pxname, svname)") for nr, line in enumerate(self.test_data.split("\n")): if self.pxname in line and self.svname in line: self.test_data = line
def _get(self, metric=None, *args, **kwargs): self.pool = kwargs.get("pool", None) if self.pool is None: raise CheckFail("Required parameters not set (pool)") self.test_data = self._load_data() return self._get_value(self.metrics[metric])
def _filter_data(self, separator): if self.pxname is None or self.svname is None: raise CheckFail("Required parameters not set (pxname, svname)") for id, line in enumerate(self.test_data): values = line.split(separator) if self.pxname in values and self.svname in values: self.test_data = values
def _filter_data(self, separator): if self.db is None: raise CheckFail("Required parameters not set (db)") for db_id, line in enumerate(self.test_data): values = line.split(separator) if self.db in values: self.test_data = values[1].split(",")
def _filter_data(self): if self.db is None: raise CheckFail("Required parameters not set (db)") position = self.test_data.index("# Keyspace") self.test_data = [ value.strip() for nr, value in enumerate(self.test_data[position:].split("\n")) if "#" not in value and self.db in value and value.strip() != "" ][0]
def _read_fpm_config(self): if self.fpm_config is not None: return fpm_config_path = self.config.get("fpm_config_path", "/etc/php-fpm.d") self.fpm_config = ConfigParser() self.fpm_config.read( utils.find_files_by_extension(fpm_config_path, "conf")) if len(self.fpm_config.sections()) == 0: self.logger.error("Can't read from PHP-FPM config") if self.pool not in self.fpm_config.sections(): raise CheckFail("Pool %s does not exist in config files" % self.pool) if not self.fpm_config.has_option(self.pool, "pm.status_path"): raise CheckFail("Status path is not configured for pool %s" % self.pool)
def _get_value(self, metric): self._read_fpm_config() if metric.type == MetricType.Discovery: metric.callback() return self._correct_type(metric.type, self.test_data) self._load_data() if self.pool is None: raise CheckFail("Required parameters not set (pool)") if self.pool not in self.fpm_config.sections(): raise CheckFail("Pool %s does not exist in config files" % self.pool) if not self.fpm_config.has_option(self.pool, "pm.status_path"): raise CheckFail("Status path is not configured for pool %s" % self.pool) return self._correct_type(metric.type, metric.parser.get_value(self.test_data))
def _load_data(self): self.test_data = Cache.read(self.name) if self.test_data is not None: return connector = self._get_connector() code, headers, self.test_data, error = connector.get() self.test_data += connector.get_load_time() if not code.startswith("200"): raise CheckFail("Unable to get response: %s (code: %s)" % (error, code)) Cache.write(self.name, self.test_data)
def _load_data(self): self.test_data = Cache.read(self.name) if self.test_data is not None: return url = "%s://%s:%s%s" % (self.config.get( "proto", "http"), self.config.get( "host", "localhost"), self.config.get("port", "80"), self.config.get("resource", "/nginx-status")) connector = UrlConnector(url) data = connector.get() if data.status_code != 200: raise CheckFail("Unable to retrieve data (error code: %s)" % data.status_code) self.test_data = data.text.strip() self.test_data += connector.get_load_time() Cache.write(self.name, self.test_data)