def compute(self, parameters, name, start, end, query): logger.debug("Computing the QoS in {0} check".format(self.name)) timeseries = 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: threshold = float(parameters["threshold"]) except ValueError: msg = "Threshold is not valid (must be float): {}".format( parameters["threshold"]) raise BadConfigurationException(msg) # Compute the QoS try: result = compute_threshold(timeseries, start.timestamp, end.timestamp, threshold) except DataFetchException as e: raise UnknownStateException(e) result.update({"timeseries": timeseries}) return result
async 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 = await client.async_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 = [] try: for ts in response[0]: timeseries.append({ "dps": _transform_warp10_values(ts["v"]), "metric": ts["c"], "tags": ts["l"], }) # Response is not parsable, return it to the user for debugging except TypeError: raise BadConfigurationException( "Script does not return valid format : {}".format(response)) if not timeseries: msg = "No data for {} (from {} to {})".format(name, start, end) logger.warning(msg) raise UnknownStateException(msg) # Parse the threshold try: threshold = float(parameters["threshold"]) except ValueError: msg = "Threshold is not valid (must be float): {}".format( parameters["threshold"]) raise BadConfigurationException(msg) # Compute the QoS try: result = compute_threshold(timeseries, start.timestamp, end.timestamp, threshold) except DataFetchException as e: raise UnknownStateException(e) result.update({"timeseries": timeseries}) return result
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