Skip to content

Instantly share code, notes, and snippets.

@lenolib
Created January 26, 2016 08:24
Show Gist options
  • Save lenolib/c191eb5125c04a6e301c to your computer and use it in GitHub Desktop.
Save lenolib/c191eb5125c04a6e301c to your computer and use it in GitHub Desktop.
graphite retention schema breakdown
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]]
old_archive = archive
archive = [map(to_seconds, point.split(':'))
for point in 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 (n_points, (resolution, retention)) in zip(old_archive.split(','), archive):
level_size = SIZE_ARCHIVE_INFO + SIZE_POINT * retention/resolution
size += level_size
print('{:<10}: {:>4} points --> {:>6} KiB'.format(n_points, int(retention/resolution), level_size/1000))
if size:
size += SIZE_METADATA
return size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment