1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
23
24
25 try:
26 import rrdtool
27 except ImportError:
28 rrdtool = None
29
30 from flumotion.component.plugs import base
31 from flumotion.common import common, messages, i18n, log
32 from flumotion.common.poller import Poller
33
34 from flumotion.common.i18n import N_
35 T_ = i18n.gettexter()
36
37 _DEFAULT_POLL_INTERVAL = 60
38 _DEFAULT_STEP_SIZE = 300
39
40 __version__ = "$Rev: 7162 $"
41
42
44 """Class to create or update a RRD file with statistics"""
45
46
47
48 - def start(self, component):
64
65 - def stop(self, component):
66 if self._rrdpoller:
67 self._rrdpoller.stop()
68
70 """Check rrdtool availability"""
71 if not rrdtool:
72 m = messages.Warning(T_(N_(
73 "Cannot import module '%s'.\n"), 'rrdtool'),
74 mid='rrdtool-import-error')
75 m.add(T_(N_(
76 "The RRD plug for this component is disabled.")))
77 self._component.addMessage(m)
78 return False
79
80 return True
81
100
102 """Create the RRD file using the CACTI standard configuration
103 if it doesn't exist"""
104 paths = []
105 rrds = (
106 (self._clientsPath, 'clients', 'GAUGE'),
107 (self._bytesPath, 'bytes', 'DERIVE'),
108 )
109
110 for path, name, counterType in rrds:
111 if not os.path.exists(path):
112 try:
113 DAY = 60 * 60 * 24
114 count = [
115 8 * DAY // self._stepSize,
116 56 * DAY // (self._stepSize * 6),
117 250 * DAY // (self._stepSize * 24),
118 3000 * DAY // (self._stepSize * 288),
119 ]
120
121 rrdtool.create(path,
122 '-s %d' % self._stepSize,
123 'DS:%s:%s:600:0:U' % (name, counterType),
124 'RRA:AVERAGE:0.5:1:%d' % count[0],
125 'RRA:AVERAGE:0.5:6:%d' % count[1],
126 'RRA:AVERAGE:0.5:24:%d' % count[2],
127 'RRA:AVERAGE:0.5:288:%d' % count[3],
128 'RRA:MAX:0.5:1:%d' % count[0],
129 'RRA:MAX:0.5:6:%d' % count[1],
130 'RRA:MAX:0.5:24:%d' % count[2],
131 'RRA:MAX:0.5:288:%d' % count[3])
132 paths.append(path)
133 self.info("Created RRD file: '%s'", path)
134 except Exception, e:
135 self.warning("Error creating RRD file '%s': %s",
136 path, log.getExceptionMessage(e))
137 m = messages.Warning(T_(N_(
138 "Could not create RRD file '%s'.\n"), path),
139 debug=log.getExceptionMessage(e),
140 mid='rrd-create-error-%s' % path)
141 self._component.addMessage(m)
142 else:
143 paths.append(path)
144 self.info("Using existing RRD file: '%s'", path)
145
146 return paths
147