Пример #1
0
    async def compute(self, parameters, name, start, end, query):
        logger.debug("Computing the QoS in {0} check".format(self.name))

        timeseries = await self.make_query(query)
        if not timeseries:
            msg = "No data for {} (from {} to {})".format(name, start, end)
            logger.warning(msg)
            raise UnknownStateException(msg)

        # Parse the threshold
        try:
            top_threshold = float(parameters["top_threshold"])
            bottom_threshold = float(parameters["bottom_threshold"])
        except ValueError:
            msg = "Thresholds are not valid (must be floats): {} and {}".format(
                parameters["top_threshold"], parameters["bottom_threshold"])
            raise BadConfigurationException(msg)

        # Compute the QoS
        try:
            result = compute_interval(
                timeseries,
                start.timestamp,
                end.timestamp,
                bottom_threshold,
                top_threshold,
            )
        except DataFetchException as e:
            raise UnknownStateException(e)

        result.update({"timeseries": timeseries})

        return result
Пример #2
0
    def execute(self, parameters, name, start, end):
        client = Warp10Client(url=self.configuration["url"],
                              rotoken=self.configuration["token"])

        # Generate the WarpScript and
        # change the placeholders.
        client.generate_script(start=start.timestamp,
                               end=end.timestamp,
                               script=parameters["script"])

        try:
            response = client.execute()
        except Warp10Exception as e:
            try:
                message = html.unescape(
                    re.search("<pre>(.*)<\/pre>", str(e)).groups()[0].strip())
            except Exception:
                message = str(e)
            raise BadConfigurationException(
                "Warp10 Internal Error : {0}".format(message))

        # Transform the Warp10 values
        timeseries = []
        for ts in response[0]:
            timeseries.append({
                "dps": _transform_warp10_values(ts["v"]),
                "metric": ts["c"],
                "tags": ts["l"],
            })

        if not timeseries:
            msg = "No data for {} (from {} to {})".format(name, start, end)
            logger.warning(msg)
            raise UnknownStateException(msg)

        # Parse the threshold
        try:
            top_threshold = float(parameters["top_threshold"])
            bottom_threshold = float(parameters["bottom_threshold"])
        except ValueError:
            msg = "Thresholds are not valid (must be floats): {} and {}".format(
                parameters["top_threshold"], parameters["bottom_threshold"])
            raise BadConfigurationException(msg)

        # Compute the QoS
        try:
            result = compute_interval(
                timeseries,
                start.timestamp,
                end.timestamp,
                bottom_threshold,
                top_threshold,
            )
        except DataFetchException as e:
            raise UnknownStateException(e)

        result.update({"timeseries": timeseries})

        return result
Пример #3
0
    async def execute(self, parameters, name, start, end):
        metric = parameters["metric"]
        start = start.timestamp
        end = end.timestamp

        # Our fake database just provides 3 metrics
        random_metrics_dispatcher = {
            "depc.tutorial.ping": self._generate_fake_ping_data,
            "depc.tutorial.oco": self._generate_fake_oco_status,
            "depc.tutorial.dbconnections": self._generate_fake_db_connections,
        }

        if metric not in random_metrics_dispatcher.keys():
            raise UnknownStateException(
                "Metric is not available for the tutorial")

        random_state = super().create_random_state(start, end, name)

        # Generate datapoints
        timestamps = list(map(int, np.arange(start, end, 60, dtype=int)))
        values = random_metrics_dispatcher[metric](random_state,
                                                   len(timestamps))
        dps = dict(zip(timestamps, values))

        timeseries = [{"dps": dps, "metric": metric, "tags": {"name": name}}]

        # Parse the threshold
        try:
            threshold = float(parameters["threshold"])
        except ValueError:
            msg = "Threshold is not valid (must be float): {}".format(
                parameters["threshold"])
            raise BadConfigurationException(msg)

        try:
            result = compute_threshold(timeseries, start, end, threshold)
        except DataFetchException as e:
            raise UnknownStateException(e)

        result.update({"timeseries": timeseries})

        return result
Пример #4
0
    def execute(self, parameters, name, start, end):
        metric = parameters["metric"]
        start = start.timestamp
        end = end.timestamp

        # Our fake database just provides one metric for the interval check
        if metric != "depc.tutorial.httpstatus":
            raise UnknownStateException("Metric is not available for the tutorial")

        random_state = super().create_random_state(start, end, name)

        # Generate datapoints
        timestamps = list(map(int, np.arange(start, end, 60, dtype=int)))
        values = self._generate_fake_http_status(random_state, len(timestamps))

        dps = dict(zip(timestamps, values))

        timeseries = [{"dps": dps, "metric": metric, "tags": {"name": name}}]

        # Parse the thresholds
        try:
            top_threshold = float(parameters["top_threshold"])
            bottom_threshold = float(parameters["bottom_threshold"])
        except ValueError:
            msg = "Thresholds are not valid (must be floats): {} and {}".format(
                parameters["top_threshold"], parameters["bottom_threshold"]
            )
            raise BadConfigurationException(msg)

        try:
            result = compute_interval(
                timeseries, start, end, bottom_threshold, top_threshold
            )
        except DataFetchException as e:
            raise UnknownStateException(e)

        result.update({"timeseries": timeseries})

        return result