Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 "{} >> {} bytes".format(args.archive, archive_to_bytes(args.archive))
@jjmaestro

This comment has been minimized.

Show comment
Hide comment
@jjmaestro

jjmaestro Jun 13, 2013

Just made the script executable (chmod 755 :)

Owner

jjmaestro commented Jun 13, 2013

Just made the script executable (chmod 755 :)

@arnaudmm

This comment has been minimized.

Show comment
Hide comment
@arnaudmm

arnaudmm Aug 1, 2014

Very nice :)
Would you try to pull request to get into whisper contrib ?
See : https://github.com/graphite-project/whisper/tree/master/contrib

arnaudmm commented Aug 1, 2014

Very nice :)
Would you try to pull request to get into whisper contrib ?
See : https://github.com/graphite-project/whisper/tree/master/contrib

@ndemengel

This comment has been minimized.

Show comment
Hide comment
@ndemengel

ndemengel Apr 9, 2015

Thanks for your script, it came handy today!

Note : I just forked it to add support for weeks.

ndemengel commented Apr 9, 2015

Thanks for your script, it came handy today!

Note : I just forked it to add support for weeks.

@mrmanc

This comment has been minimized.

Show comment
Hide comment
@mrmanc

mrmanc Oct 6, 2015

I got this error running Python 2.6.6

Traceback (most recent call last):
  File "/export/home/mark-c/bin/whisper-calculator.py", line 48, in <module>
    print "{} >> {} bytes".format(args.archive, archive_to_bytes(args.archive))
ValueError: zero length field name in format

To resolve this I added indices to the format tokens (as older versions of Python require) on line 48 to read:
print "{0} >> {1} bytes".format(args.archive, archive_to_bytes(args.archive))

mrmanc commented Oct 6, 2015

I got this error running Python 2.6.6

Traceback (most recent call last):
  File "/export/home/mark-c/bin/whisper-calculator.py", line 48, in <module>
    print "{} >> {} bytes".format(args.archive, archive_to_bytes(args.archive))
ValueError: zero length field name in format

To resolve this I added indices to the format tokens (as older versions of Python require) on line 48 to read:
print "{0} >> {1} bytes".format(args.archive, archive_to_bytes(args.archive))

@m30m

This comment has been minimized.

Show comment
Hide comment
@m30m

m30m commented Mar 22, 2016

Just made a simple UI for it:
http://alex-mercer.github.io/whisper-calculator/

@andrewgee

This comment has been minimized.

Show comment
Hide comment
@andrewgee

andrewgee Aug 15, 2016

@m30m Where's the UI gone? I used to use that lots :(

andrewgee commented Aug 15, 2016

@m30m Where's the UI gone? I used to use that lots :(

@sokratisg

This comment has been minimized.

Show comment
Hide comment
@sokratisg

sokratisg Aug 24, 2016

@m30m please check, very useful tool, shame it is not available any more

sokratisg commented Aug 24, 2016

@m30m please check, very useful tool, shame it is not available any more

@bjorand

This comment has been minimized.

Show comment
Hide comment
@bjorand

bjorand commented Sep 6, 2016

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