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