def fetch_samples(self, adapter, dur, interval, method, mode, delta, stats, end_seconds_ago=0): samples = dict() if mode == "rate": for stat in stats: os = adapter.samples(stat, dur+600, interval, method, secs2=end_seconds_ago, delta=delta) ns = list() prev = None for sample in reversed(os): if prev is not None: rate = calc_rate(float(sample[1]), float(prev[1]), secs(sample[0]), secs(prev[0])) ns.insert(0, (sample[0], rate, None)) prev = sample samples[stat] = ns else: threads = [] for i, stat in enumerate(stats): # start a thread to do the db query, etc for each stat requested threads.append(threading.Thread(target = self.getStatSamples, args = (adapter, samples, stat, dur, interval, method, end_seconds_ago, delta))) threads[i].start() for th in threads: while th.isAlive(): pass return samples
def get_vals(self, session, samples, stat, text, duration, end_secs): tnow = time() vals = list() min_dt = tnow - duration - end_secs for dt, value, dev in samples[stat]: if value is not None: vals.append({"dt": secs(dt), "y": value}) if secs(dt) < min_dt: break vals.sort(key=lambda stat: stat["dt"], reverse=False) #here, we sort by dt to be sure that our graphs are valid return vals
def get_vals(self, session, samples, stat, text, duration, end_secs): tnow = time() vals = list() points = self.points.get(session) if points: min_dt = tnow - duration - end_secs for dt, value, stacked_value in points[stat]: if value is not None: vals.append({"dt": secs(dt), "y": stacked_value}) if secs(dt) < min_dt: break vals.reverse() return vals
def get_vals(self, session, samples, stat, text, duration, end_secs): tnow = time() vals = list() percent = self.page.percent_property.get(session) total = self.page.get_object_property(session, percent) min_dt = tnow - duration - end_secs for dt, value, dev in samples[stat]: if value is not None: if total is None or total == 0.0: vals.append({"dt": secs(dt), "y": 0.0}) else: vals.append({"dt": secs(dt), "y": (float(value) / float(total)) * 100.0}) if secs(dt) < min_dt: break vals.reverse() return vals