~graphite-dev/graphite/1.1

« back to all changes in this revision

Viewing changes to whisper/bin/whisper-resize.py

  • Committer: Chris Davis
  • Date: 2011-08-08 03:32:25 UTC
  • mfrom: (337.5.115 trunk)
  • Revision ID: chrismd@gmail.com-20110808033225-oncjaxk2pvd6651m
cherrypicking trunk revs 450-460

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
import whisper
5
5
from optparse import OptionParser
6
6
 
7
 
now = int( time.time() )
8
 
 
9
 
UnitMultipliers = {
10
 
  's' : 1,
11
 
  'm' : 60,
12
 
  'h' : 60 * 60,
13
 
  'd' : 60 * 60 * 24,
14
 
  'y' : 60 * 60 * 24 * 365,
15
 
}
16
 
 
17
 
 
18
 
def parseRetentionDef(retentionDef):
19
 
  (precision, points) = retentionDef.strip().split(':')
20
 
 
21
 
  if precision.isdigit():
22
 
    precisionUnit = 's'
23
 
    precision = int(precision)
24
 
  else:
25
 
    precisionUnit = precision[-1]
26
 
    precision = int( precision[:-1] )
27
 
 
28
 
  if points.isdigit():
29
 
    pointsUnit = None
30
 
    points = int(points)
31
 
  else:
32
 
    pointsUnit = points[-1]
33
 
    points = int( points[:-1] )
34
 
 
35
 
  if precisionUnit not in UnitMultipliers:
36
 
    raise ValueError("Invalid unit: '%s'" % precisionUnit)
37
 
 
38
 
  if pointsUnit not in UnitMultipliers and pointsUnit is not None:
39
 
    raise ValueError("Invalid unit: '%s'" % pointsUnit)
40
 
 
41
 
  precision = precision * UnitMultipliers[precisionUnit]
42
 
 
43
 
  if pointsUnit:
44
 
    points = points * UnitMultipliers[pointsUnit] / precision
45
 
 
46
 
  return (precision, points)
47
 
 
48
 
 
49
 
option_parser = OptionParser(usage='''%prog path precision:retention [precision:retention]*
50
 
 
51
 
precision and retention specify lengths of time, for example:
 
7
now = int(time.time())
 
8
 
 
9
option_parser = OptionParser(
 
10
    usage='''%prog path timePerPoint:timeToStore [timePerPoint:timeToStore]*
 
11
 
 
12
timePerPoint and timeToStore specify lengths of time, for example:
52
13
 
53
14
60:1440      60 seconds per datapoint, 1440 datapoints = 1 day of retention
54
15
15m:8        15 minutes per datapoint, 8 datapoints = 2 hours of retention
55
16
1h:7d        1 hour per datapoint, 7 days of retention
56
17
12h:2y       12 hours per datapoint, 2 years of retention
57
18
''')
58
 
option_parser.add_option('--xFilesFactor', default=None, type='float', help="Change the xFilesFactor")
59
 
option_parser.add_option('--force', default=False, action='store_true', help="Perform a destructive change")
60
 
option_parser.add_option('--newfile', default=None, action='store', help="Create a new database file without removing the existing one")
61
 
option_parser.add_option('--nobackup', action='store_true', help='Delete the .bak file after successful execution')
 
19
 
 
20
option_parser.add_option(
 
21
    '--xFilesFactor', default=None,
 
22
    type='float', help="Change the xFilesFactor")
 
23
option_parser.add_option(
 
24
    '--force', default=False, action='store_true',
 
25
    help="Perform a destructive change")
 
26
option_parser.add_option(
 
27
    '--newfile', default=None, action='store',
 
28
    help="Create a new database file without removing the existing one")
 
29
option_parser.add_option(
 
30
    '--nobackup', action='store_true',
 
31
    help='Delete the .bak file after successful execution')
62
32
 
63
33
(options, args) = option_parser.parse_args()
64
34
 
67
37
  sys.exit(1)
68
38
 
69
39
path = args[0]
70
 
new_archives = [ parseRetentionDef(retentionDef) for retentionDef in args[1:] ]
 
40
new_archives = [whisper.parseRetentionDef(retentionDef)
 
41
                for retentionDef in args[1:]]
71
42
 
72
43
info = whisper.info(path)
73
44
old_archives = info['archives']
74
 
old_archives.sort(key=lambda a: a['secondsPerPoint'], reverse=True) #sort by precision, lowest to highest
 
45
# sort by precision, lowest to highest
 
46
old_archives.sort(key=lambda a: a['secondsPerPoint'], reverse=True)
75
47
 
76
48
if options.xFilesFactor is None:
77
49
  xff = info['xFilesFactor']