def test_file_fetch_edge_cases(self): """ Test some of the edge cases in file_fetch() that should return None or raise an exception """ whisper.create(self.filename, [(1, 60)]) with open(self.filename, 'rb') as fh: msg = "Invalid time interval: from time '{0}' is after until time '{1}'" until_time = 0 from_time = int(time.time()) + 100 with AssertRaisesException( whisper.InvalidTimeInterval(msg.format(from_time, until_time))): whisper.file_fetch(fh, fromTime=from_time, untilTime=until_time) # fromTime > now aka metrics from the future self.assertIsNone( whisper.file_fetch(fh, fromTime=int(time.time()) + 100, untilTime=int(time.time()) + 200), ) # untilTime > oldest time stored in the archive headers = whisper.info(self.filename) the_past = int(time.time()) - headers['maxRetention'] - 200 self.assertIsNone( whisper.file_fetch(fh, fromTime=the_past - 1, untilTime=the_past), ) # untilTime > now, change untilTime to now now = int(time.time()) self.assertEqual( whisper.file_fetch(fh, fromTime=now, untilTime=now + 200, now=now), ((now + 1, now + 2, 1), [None]), )
def fetch(self, startTime, endTime): if not gzip: raise Exception("gzip module not available, GzippedWhisperFile not supported") fh = gzip.GzipFile(self.fs_path, 'rb') try: return whisper.file_fetch(fh, startTime, endTime) finally: fh.close()
def run(args): with open(args.filename, 'rb') as fh: info = whisper.__readHeader(fh) print '%s: period=%s, aggregation=%s, propagation=%s, archives=%s' % \ (args.filename, info['maxRetention'], info['aggregationMethod'], info['xFilesFactor'], len(info['archives'])) for i, archive in enumerate(info['archives']): print ' period=%s, points=%s, seconds=%s, size=%s, offset=%s' % \ (archive['retention'], archive['points'], archive['secondsPerPoint'], archive['size'], archive['offset']) if not args.header: # Request all points until now. toInterval will be equal to now + step. (fromInterval, toInterval, step), points = whisper.file_fetch(fh, 0, None) print 'from=%s, to=%s, step=%s' % (fromInterval, toInterval, step) if any(points): for point in points: print point
def fetch(self, startTime, endTime): fh = gzip.GzipFile(self.fs_path, 'rb') try: return whisper.file_fetch(fh, startTime, endTime) finally: fh.close()