Skip to content

Instantly share code, notes, and snippets.

@mrmanc
Forked from jjmaestro/whisper-calculator.py
Last active October 6, 2015 15:40
Show Gist options
  • Save mrmanc/e259469e439352e3f876 to your computer and use it in GitHub Desktop.
Save mrmanc/e259469e439352e3f876 to your computer and use it in GitHub Desktop.
whisper-calculator.py:Calculates the size of the whisper storage for the given retention (in frequency:history format)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
'd': 1 * 60 * 60 * 24,
'y': 1 * 60 * 60 * 24 * 365,
}
return int(s[:-1]) * SECONDS_IN_A[s[-1]]
archive = [map(to_seconds, point.split(':'))
for point in args.archive.split(',')]
SIZE_METADATA = 2 * 4 + 4 + 4 # 16 [!2LfL]
SIZE_ARCHIVE_INFO = 3 * 4 # 12 [!3L]+
SIZE_POINT = 4 + 8 # 12 [!Ld]+
size = 0
for resolution, retention in archive:
size += SIZE_ARCHIVE_INFO + SIZE_POINT * retention/resolution
if size:
size += SIZE_METADATA
return size
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(
description="Calculates the size of the whisper storage for the given \
archive (in resolution:retention format, e.g. 1m:24h,5m:3m)"
)
parser.add_argument(
'archive',
help="Archive in storage-schemas.conf format (resolution:retention)"
)
args = parser.parse_args()
print "{0} >> {1} bytes".format(args.archive, archive_to_bytes(args.archive))
@mrmanc
Copy link
Author

mrmanc commented Oct 6, 2015

Added positional indices to format on line 48 to work with older versions of Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment