def execute(self, query, rid=None): # Request data given a simple target expression. data = BaseStatsHandler(rid).get_stats(metric=query.target, start=self.start, stop=self.stop) # If response is empty, then data is absent for the given interval. if not len(data): log.warning('No datapoints for %s.%s', rid, query.target) return None, None # Check whether the query to InfluxDB returned multiple series. if len(data) > 1: log.error('Got multiple series for %s.%s', rid, query.target) raise methods.MultipleSeriesReturnedError() # Ensure requested and returned measurements/columns match. data = data.values()[0] target = query.target.split('.') if data['measurement'] != target[0] or data['column'] != target[-1]: log.error('Got %s while expecting %s', data['name'], query.target) raise methods.RequestedTargetMismatchError() # Sanitize datapoints. datapoints = [val for val, _ in data['datapoints'] if val is not None] # Compare against the threshold and compute retval. return methods.compute(query.operator, query.aggregation, datapoints, query.threshold)
def execute(self, query, rid=None): # Request data given a simple target expression. data = hrs.MultiHandler(rid).get_data(query.target, start=self.window) # No data ever reached Graphite? Is the whisper file missing? if not len(data): log.warning('Empty response for %s.%s', rid, query.target) raise methods.EmptyResponseReturnedError() # Check whether the query to Graphite returned multiple series. This # should never occur actually, since the query's target belongs to a # pre-defined list of allowed targets which are quaranteed to return # a single series. if len(data) > 1: log.warning('Got multiple series for %s.%s', rid, query.target) raise methods.MultipleSeriesReturnedError() # Ensure requested and returned targets match. data = data[0] target = data['_requested_target'] if target != query.target: log.warning('Got %s while expecting %s', target, query.target) raise methods.RequestedTargetMismatchError() # Clean datapoints of None values. datapoints = [val for val, _ in data['datapoints'] if val is not None] if not datapoints: log.warning('No datapoints for %s.%s', rid, query.target) return None, None # Compare against the threshold and compute retval. triggered, retval = methods.compute(query.operator, query.aggregation, datapoints, query.threshold) return triggered, retval
def execute(self, query, rid=None): # Request data given a simple target expression. from mist.api.models import Machine m = Machine.objects.get(id=rid) data = fdb_methods.get_stats(machine=m, start=self.start, stop=self.stop, metrics=[ "fetch(\"{id}." + query.target + "\", start=\"{start}\"" + ", stop=\"{stop}\"" + ", step=\"{step}\")"]) # No data ever reached Graphite? Is the whisper file missing? if not len(data): log.warning('Empty response for %s.%s', rid, query.target) raise methods.EmptyResponseReturnedError() # Check whether the query to Graphite returned multiple series. This # should never occur actually, since the query's target belongs to a # pre-defined list of allowed targets which are quaranteed to return # a single series. if len(data) > 1: log.warning('Got multiple series for %s.%s', rid, query.target) raise methods.MultipleSeriesReturnedError() # Ensure requested and returned targets match. target = list(data.keys())[0] data = list(data.values())[0] if target != query.target: log.warning('Got %s while expecting %s', target, query.target) raise methods.RequestedTargetMismatchError() # Clean datapoints of None values. datapoints = [val for val, _ in data['datapoints'] if val is not None] if not datapoints: log.warning('No datapoints for %s.%s', rid, query.target) return None, None # Compare against the threshold and compute retval. return methods.compute(query.operator, query.aggregation, datapoints, query.threshold)