5
5
from optparse import OptionParser
7
now = int( time.time() )
14
'y' : 60 * 60 * 24 * 365,
18
def parseRetentionDef(retentionDef):
19
(precision, points) = retentionDef.strip().split(':')
21
if precision.isdigit():
23
precision = int(precision)
25
precisionUnit = precision[-1]
26
precision = int( precision[:-1] )
32
pointsUnit = points[-1]
33
points = int( points[:-1] )
35
if precisionUnit not in UnitMultipliers:
36
raise ValueError("Invalid unit: '%s'" % precisionUnit)
38
if pointsUnit not in UnitMultipliers and pointsUnit is not None:
39
raise ValueError("Invalid unit: '%s'" % pointsUnit)
41
precision = precision * UnitMultipliers[precisionUnit]
44
points = points * UnitMultipliers[pointsUnit] / precision
46
return (precision, points)
49
option_parser = OptionParser(usage='''%prog path precision:retention [precision:retention]*
51
precision and retention specify lengths of time, for example:
9
option_parser = OptionParser(
10
usage='''%prog path timePerPoint:timeToStore [timePerPoint:timeToStore]*
12
timePerPoint and timeToStore specify lengths of time, for example:
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
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')
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')
63
33
(options, args) = option_parser.parse_args()
70
new_archives = [ parseRetentionDef(retentionDef) for retentionDef in args[1:] ]
40
new_archives = [whisper.parseRetentionDef(retentionDef)
41
for retentionDef in args[1:]]
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)
76
48
if options.xFilesFactor is None:
77
49
xff = info['xFilesFactor']