How to use the whisper.parseRetentionDef function in whisper

To help you get started, we’ve selected a few whisper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github j5int / warden / test / test_warden_carbon_cache.py View on Github external
    @classmethod
    def setUpClass(self):

        self.manager = CarbonManager(temp_dir)
        self.manager.add_daemon(CarbonManager.CACHE, test_conf)
        self.manager.start_daemons()

        config_parser = ConfigParser()
        if not config_parser.read(test_stor):
            print "Error: Couldn't read config file: %s" % test_stor

        secindex = config_parser.sections().index('carboncache')
        section = config_parser.sections()[secindex]
        options = dict(config_parser.items(config_parser.sections()[secindex]))
        retentions = whisper.parseRetentionDef(options['retentions'])

        self.step = retentions[0]
        self.max_datapoints = retentions[1]
        self.max_sample = 20

        time.sleep(2)

        self.manager.print_status()
github graphite-project / whisper / test_whisper.py View on Github external
def test_valid_retentions(self):
        retention_map = (
            ('60:10', (60, 10)),
            ('10:60', (10, 60)),
            ('10s:10h', (10, 3600)),
        )
        for retention, expected in retention_map:
            results = whisper.parseRetentionDef(retention)
            self.assertEqual(results, expected)
github graphite-project / whisper / test_whisper.py View on Github external
def test_invalid_retentions(self):
        retention_map = (
            # From getUnitString
            ('10x:10', ValueError("Invalid unit 'x'")),
            ('60:10x', ValueError("Invalid unit 'x'")),

            # From parseRetentionDef
            ('10', ValueError("Invalid retention definition '10'")),
            ('10X:10', ValueError("Invalid precision specification '10X'")),
            ('10:10$', ValueError("Invalid retention specification '10$'")),
            ('60:10', (60, 10)),
        )
        for retention, expected_exc in retention_map:
            try:
                results = whisper.parseRetentionDef(retention)
            except expected_exc.__class__ as exc:
                self.assertEqual(
                    str(expected_exc),
                    str(exc),
                )
                self.assertEqual(
                    expected_exc.__class__,
                    exc.__class__,
                )
            else:
                # When there isn't an exception raised
                self.assertEqual(results, expected_exc)
github lincolnloop / salmon / salmon / core / graph.py View on Github external
def _create(self):
        """Create the Whisper file on disk"""
        if not os.path.exists(settings.SALMON_WHISPER_DB_PATH):
            os.makedirs(settings.SALMON_WHISPER_DB_PATH)
        archives = [whisper.parseRetentionDef(retentionDef)
                    for retentionDef in settings.ARCHIVES.split(",")]
        whisper.create(self.path, archives,
                       xFilesFactor=settings.XFILEFACTOR,
                       aggregationMethod=settings.AGGREGATION_METHOD)
github graphite-project / whisper / bin / whisper-create.py View on Github external
help="Create new whisper as sparse file")
option_parser.add_option('--fallocate', default=False, action='store_true',
                         help="Create new whisper and use fallocate")

(options, args) = option_parser.parse_args()

if options.estimate:
  if len(args) == 0:
    option_parser.print_usage()
    sys.exit(1)
  if len(args) == 1 and args[0].find(",") > 0:
    args = args[0].split(",")

  archives = 0
  total_points = 0
  for (precision, points) in map(whisper.parseRetentionDef, args):
    print("Archive %s: %s points of %ss precision" % (archives, points, precision))
    archives += 1
    total_points += points

  size = 16 + (archives * 12) + (total_points * 12)
  disk_size = int(math.ceil(size / 4096.0) * 4096)
  print("\nEstimated Whisper DB Size: %s (%s bytes on disk with 4k blocks)\n" %
        (byte_format(size), disk_size))
  for x in [1, 5, 10, 50, 100, 500]:
    print("Estimated storage requirement for %sk metrics: %s" %
          (x, byte_format(x * 1000 * disk_size)))
  sys.exit(0)

if len(args) < 2:
  option_parser.print_help()
  sys.exit(1)
github graphite-project / carbon / lib / carbon / storage.py View on Github external
  @staticmethod
  def fromString(retentionDef):
    (secondsPerPoint, points) = whisper.parseRetentionDef(retentionDef)
    return Archive(secondsPerPoint, points)