Esempio n. 1
0
    def get_team_qos(cls, team_id, label, start, end):
        cls.check_valid_period(start, end)
        client = Warp10Client()

        # Default values
        params = {"team": team_id}

        script = QOS_PER_TEAM
        if label:
            script = QOS_FILTERED_BY_LABEL
            params.update({"name": label})

        client.generate_script(start=start, end=end, script=script, extra_params=params)
        resp = client.execute()

        # Return list of datapoints
        if label:
            try:
                return _transform_warp10_values(resp[0][0]["v"])
            except IndexError:
                return {}

        # Order by Label
        data = {}

        for metrics in resp[0]:
            label = metrics["l"]["name"]

            if label not in data:
                data[label] = {}
            data[label] = _transform_warp10_values(metrics["v"])

        return data
Esempio n. 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
Esempio n. 3
0
    def get_team_item_qos(cls, team, label, name, start, end):
        cls.check_valid_period(start, end)
        client = Warp10Client()

        client.generate_script(
            start=start,
            end=end,
            script=QOS_ITEM_PER_TEAM_LABEL,
            extra_params={"team": team, "label": label, "name": name},
        )
        resp = client.execute()

        # No result
        if not resp[0]:
            return {}

        values = _transform_warp10_values(resp[0][0]["v"])
        return values