def test_setAggregation(self): """Create a db, change aggregation, xFilesFactor, then use info() to validate""" retention = [(1, 60), (60, 60)] # create a new db with a valid configuration whisper.create(self.db, retention) #set setting every AggregationMethod available for ag in whisper.aggregationMethods: for xff in 0.0, 0.2, 0.4, 0.7, 0.75, 1.0: #original xFilesFactor info0 = whisper.info(self.db) #optional xFilesFactor not passed whisper.setAggregationMethod(self.db, ag) #original value should not change info1 = whisper.info(self.db) self.assertEqual(info0['xFilesFactor'], info1['xFilesFactor']) #the selected aggregation method should have applied self.assertEqual(ag, info1['aggregationMethod']) #optional xFilesFactor used whisper.setAggregationMethod(self.db, ag, xff) #new info should match what we just set it to info2 = whisper.info(self.db) #packing and unpacking because #AssertionError: 0.20000000298023224 != 0.2 target_xff = struct.unpack("!f", struct.pack("!f", xff))[0] self.assertEqual(info2['xFilesFactor'], target_xff) #same aggregationMethod asssertion again, but double-checking since #we are playing with packed values and seek() self.assertEqual(ag, info2['aggregationMethod']) self._removedb()
def test_setAggregation(self): """Create a db, change aggregation, xFilesFactor, then use info() to validate""" retention = [(1, 60), (60, 60)] # create a new db with a valid configuration whisper.create(self.db, retention) #set setting every AggregationMethod available for ag in whisper.aggregationMethods: for xff in 0.0,0.2,0.4,0.7,0.75,1.0: #original xFilesFactor info0 = whisper.info(self.db) #optional xFilesFactor not passed whisper.setAggregationMethod(self.db, ag) #original value should not change info1 = whisper.info(self.db) self.assertEqual(info0['xFilesFactor'],info1['xFilesFactor']) #the selected aggregation method should have applied self.assertEqual(ag,info1['aggregationMethod']) #optional xFilesFactor used whisper.setAggregationMethod(self.db, ag, xff) #new info should match what we just set it to info2 = whisper.info(self.db) #packing and unpacking because #AssertionError: 0.20000000298023224 != 0.2 target_xff = struct.unpack("!f", struct.pack("!f",xff))[0] self.assertEqual(info2['xFilesFactor'], target_xff) #same aggregationMethod asssertion again, but double-checking since #we are playing with packed values and seek() self.assertEqual(ag,info2['aggregationMethod']) self._removedb()
def set_aggregation(path, mode): if not mode: return 0 if not os.path.exists(path): return 0 try: whisper.setAggregationMethod(path, mode) return 1 except whisper.WhisperException as exc: logging.warning("{} failed ({})".format(path, str(exc)))
def setAggregation(path, mode): if not mode: return 0 if not os.path.exists(path): return 0 try: whisper.setAggregationMethod(path, mode) return 1 except whisper.WhisperException, exc: logging.warning("%s failed (%s)" % (path, str(exc)))
def set_xff(path, xff): with open(path) as f: header = whisper.__readHeader(f) agg_method = header['aggregationMethod'] old_xff = header['xFilesFactor'] try: whisper.setAggregationMethod(path, agg_method, xff) except IOError as e: sys.stderr.write("[ERROR] file '%s' not exist!\n" % path) option_parser.print_help() sys.exit(1) except whisper.WhisperException as e: raise SystemExit("[ERROR] %s" % e) print 'update xff: %s (%s -> %s)' % (path, old_xff, xff)
def test_setAggregation(self): """ Create a db, change aggregation, xFilesFactor, then use info() to validate """ original_lock = whisper.LOCK original_caching = whisper.CACHE_HEADERS original_autoflush = whisper.AUTOFLUSH whisper.LOCK = True whisper.AUTOFLUSH = True whisper.CACHE_HEADERS = True # create a new db with a valid configuration whisper.create(self.filename, self.retention) with AssertRaisesException( whisper.InvalidAggregationMethod( 'Unrecognized aggregation method: yummy beer')): whisper.setAggregationMethod(self.filename, 'yummy beer') #set setting every AggregationMethod available for ag in whisper.aggregationMethods: for xff in 0.0, 0.2, 0.4, 0.7, 0.75, 1.0: # original xFilesFactor info0 = whisper.info(self.filename) # optional xFilesFactor not passed whisper.setAggregationMethod(self.filename, ag) # original value should not change info1 = whisper.info(self.filename) self.assertEqual(info0['xFilesFactor'], info1['xFilesFactor']) # the selected aggregation method should have applied self.assertEqual(ag, info1['aggregationMethod']) # optional xFilesFactor used whisper.setAggregationMethod(self.filename, ag, xff) # new info should match what we just set it to info2 = whisper.info(self.filename) # packing and unpacking because # AssertionError: 0.20000000298023224 != 0.2 target_xff = struct.unpack("!f", struct.pack("!f", xff))[0] self.assertEqual(info2['xFilesFactor'], target_xff) # same aggregationMethod asssertion again, but double-checking since # we are playing with packed values and seek() self.assertEqual(ag, info2['aggregationMethod']) with SimulatedCorruptWhisperFile(): with AssertRaisesException( whisper.CorruptWhisperFile('Unable to read header', self.filename)): whisper.setAggregationMethod(self.filename, ag) whisper.LOCK = original_lock whisper.AUTOFLUSH = original_autoflush whisper.CACHE_HEADERS = original_caching
def test_setAggregation(self): """ Create a db, change aggregation, xFilesFactor, then use info() to validate """ original_lock = whisper.LOCK original_caching = whisper.CACHE_HEADERS original_autoflush = whisper.AUTOFLUSH whisper.LOCK = True whisper.AUTOFLUSH = True whisper.CACHE_HEADERS = True # create a new db with a valid configuration whisper.create(self.filename, self.retention) with AssertRaisesException(whisper.InvalidAggregationMethod('Unrecognized aggregation method: yummy beer')): whisper.setAggregationMethod(self.filename, 'yummy beer') #set setting every AggregationMethod available for ag in whisper.aggregationMethods: for xff in 0.0, 0.2, 0.4, 0.7, 0.75, 1.0: # original xFilesFactor info0 = whisper.info(self.filename) # optional xFilesFactor not passed whisper.setAggregationMethod(self.filename, ag) # original value should not change info1 = whisper.info(self.filename) self.assertEqual(info0['xFilesFactor'], info1['xFilesFactor']) # the selected aggregation method should have applied self.assertEqual(ag, info1['aggregationMethod']) # optional xFilesFactor used whisper.setAggregationMethod(self.filename, ag, xff) # new info should match what we just set it to info2 = whisper.info(self.filename) # packing and unpacking because # AssertionError: 0.20000000298023224 != 0.2 target_xff = struct.unpack("!f", struct.pack("!f", xff))[0] self.assertEqual(info2['xFilesFactor'], target_xff) # same aggregationMethod assertion again, but double-checking since # we are playing with packed values and seek() self.assertEqual(ag, info2['aggregationMethod']) with SimulatedCorruptWhisperFile(): with AssertRaisesException(whisper.CorruptWhisperFile('Unable to read header', self.filename)): whisper.setAggregationMethod(self.filename, ag) whisper.LOCK = original_lock whisper.AUTOFLUSH = original_autoflush whisper.CACHE_HEADERS = original_caching
def setMetadata(metric, key, value): if key != 'aggregationMethod': return dict(error="Unsupported metadata key \"%s\"" % key) wsp_path = getFilesystemPath(metric) try: old_value = whisper.setAggregationMethod(wsp_path, value) return dict(old_value=old_value, new_value=value) except Exception: log.err() return dict(error=traceback.format_exc())
def update_aggregations(filename, schemas, root_dir): metrics_path = filename_to_metrics_path(filename) for schema in schemas[:-1]: # the last item is 'default', we don't want to bother changing anything to that if schema.matches(metrics_path): method = schema.archives[1] # TODO: check and set xFilesFactor? full_filename = get_full_file_path(root_dir, filename) old_method = whisper.setAggregationMethod(full_filename, method) if method != old_method: print "changed {} to {} ({}, was {})".format(metrics_path, method, schema.name, old_method) # rules are in priority order, so only apply the first return
def setMetadata(self, metric, key, value): if key != 'aggregationMethod': raise ValueError("Unsupported metadata key \"%s\"" % key) wsp_path = self.getFilesystemPath(metric) return whisper.setAggregationMethod(wsp_path, value)
import whisper except ImportError: raise SystemExit('[ERROR] Please make sure whisper is installed properly') # Ignore SIGPIPE signal.signal(signal.SIGPIPE, signal.SIG_DFL) option_parser = optparse.OptionParser( usage='%%prog path <%s>' % '|'.join(whisper.aggregationMethods)) (options, args) = option_parser.parse_args() if len(args) < 2: option_parser.print_usage() sys.exit(1) path = args[0] aggregationMethod = args[1] try: oldAggregationMethod = whisper.setAggregationMethod(path, aggregationMethod) except IOError, exc: sys.stderr.write("[ERROR] File '%s' does not exist!\n\n" % path) option_parser.print_usage() sys.exit(1) except whisper.WhisperException, exc: raise SystemExit('[ERROR] %s' % str(exc)) print 'Updated aggregation method: %s (%s -> %s)' % (path,oldAggregationMethod,aggregationMethod)
#windows? pass option_parser = optparse.OptionParser( usage='%%prog path <%s> [xFilesFactor]' % '|'.join(whisper.aggregationMethods)) (options, args) = option_parser.parse_args() if len(args) < 2: option_parser.print_help() sys.exit(1) path = args[0] aggregationMethod = args[1] xFilesFactor = None if len(args) == 3: xFilesFactor = args[2] try: oldAggregationMethod = whisper.setAggregationMethod(path, aggregationMethod, xFilesFactor) except IOError: sys.stderr.write("[ERROR] File '%s' does not exist!\n\n" % path) option_parser.print_help() sys.exit(1) except whisper.WhisperException as exc: raise SystemExit('[ERROR] %s' % str(exc)) print('Updated aggregation method: %s (%s -> %s)' % (path,oldAggregationMethod,aggregationMethod))
pass option_parser = optparse.OptionParser(usage='%%prog path <%s> [xFilesFactor]' % '|'.join(whisper.aggregationMethods)) (options, args) = option_parser.parse_args() if len(args) < 2: option_parser.print_help() sys.exit(1) path = args[0] aggregationMethod = args[1] xFilesFactor = None if len(args) == 3: xFilesFactor = args[2] try: oldAggregationMethod = whisper.setAggregationMethod( path, aggregationMethod, xFilesFactor) except IOError, exc: sys.stderr.write("[ERROR] File '%s' does not exist!\n\n" % path) option_parser.print_help() sys.exit(1) except whisper.WhisperException, exc: raise SystemExit('[ERROR] %s' % str(exc)) print 'Updated aggregation method: %s (%s -> %s)' % ( path, oldAggregationMethod, aggregationMethod)
def setAggregationMethod(self, metric, aggregationMethod, xFilesFactor=None): return whisper.setAggregationMethod(self.getFilesystemPath(metric), aggregationMethod, xFilesFactor)