Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
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)))
Ejemplo n.º 4
0
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)))
Ejemplo n.º 5
0
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)))
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
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())
Ejemplo n.º 10
0
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())
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
        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)
    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))
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
 def setAggregationMethod(self, metric, aggregationMethod, xFilesFactor=None):
     return whisper.setAggregationMethod(self.getFilesystemPath(metric), aggregationMethod, xFilesFactor)
Ejemplo n.º 19
0
Archivo: db.py Proyecto: jbooth/carbon
 def setAggregationMethod(self,
                          metric,
                          aggregationMethod,
                          xFilesFactor=None):
     return whisper.setAggregationMethod(self.getFilesystemPath(metric),
                                         aggregationMethod, xFilesFactor)