Beispiel #1
0
    def execute(self, tracker, tmaster, start, end):
        # Fetch metrics for start-60 to end+60 because the minute mark
        # may be a little skewed. By getting a couple more values,
        # we can then truncate based on the interval needed.
        metrics = yield getMetricsTimeline(tmaster, self.component,
                                           [self.metricName], self.instances,
                                           start - 60, end + 60)
        if not metrics:
            return
        if "message" in metrics:
            raise Exception(metrics["message"])

        # Put a blank timeline.
        if "timeline" not in metrics or not metrics["timeline"]:
            metrics["timeline"] = {self.metricName: {}}
        timelines = metrics["timeline"][self.metricName]
        allMetrics = []
        for instance, timeline in timelines.items():
            toBeDeletedKeys = []
            for key, value in timeline.items():
                floatValue = float(value)
                # Check if the value is really float or not.
                # In python, float("nan") returns "nan" which is actually a float value,
                # but it is not what we required.
                if math.isnan(floatValue):
                    toBeDeletedKeys.append(key)
                    continue
                timeline[key] = floatValue

            # Remove all keys for which the value was not float
            for key in toBeDeletedKeys:
                timeline.pop(key)

            allMetrics.append(
                Metrics(self.component, self.metricName, instance, start, end,
                        timeline))
        raise tornado.gen.Return(allMetrics)
Beispiel #2
0
  def execute(self, tracker, tmaster, start, end):
    # Fetch metrics for start-60 to end+60 because the minute mark
    # may be a little skewed. By getting a couple more values,
    # we can then truncate based on the interval needed.
    metrics = yield getMetricsTimeline(
        tmaster, self.component, [self.metricName], self.instances,
        start - 60, end + 60)
    if not metrics:
      return
    if "message" in metrics:
      raise Exception(metrics["message"])

    # Put a blank timeline.
    if "timeline" not in metrics or not metrics["timeline"]:
      metrics["timeline"] = {
          self.metricName: {}
      }
    timelines = metrics["timeline"][self.metricName]
    allMetrics = []
    for instance, timeline in timelines.iteritems():
      toBeDeletedKeys = []
      for key, value in timeline.iteritems():
        floatValue = float(value)
        # Check if the value is really float or not.
        # In python, float("nan") returns "nan" which is actually a float value,
        # but it is not what we required.
        if math.isnan(floatValue):
          toBeDeletedKeys.append(key)
          continue
        timeline[key] = floatValue

      # Remove all keys for which the value was not float
      for key in toBeDeletedKeys:
        timeline.pop(key)

      allMetrics.append(Metrics(self.component, self.metricName, instance, start, end, timeline))
    raise tornado.gen.Return(allMetrics)