summaryrefslogtreecommitdiff
path: root/src/daq/flumotion-rrd
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2014-10-12 20:40:59 +0200
committerChristian Pointner <equinox@spreadspace.org>2014-10-12 20:40:59 +0200
commit8db3fd119bb267e9ae7ae1eb6b145741e922e2b1 (patch)
tree63714fa1b08bc9c19df28a13a19d7ae24e01827e /src/daq/flumotion-rrd
parentopen log file (diff)
improved error handling
Diffstat (limited to 'src/daq/flumotion-rrd')
-rwxr-xr-xsrc/daq/flumotion-rrd/sfive-flumotion-rrd.py62
1 files changed, 36 insertions, 26 deletions
diff --git a/src/daq/flumotion-rrd/sfive-flumotion-rrd.py b/src/daq/flumotion-rrd/sfive-flumotion-rrd.py
index 0ce7287..4b0a2d1 100755
--- a/src/daq/flumotion-rrd/sfive-flumotion-rrd.py
+++ b/src/daq/flumotion-rrd/sfive-flumotion-rrd.py
@@ -107,35 +107,41 @@ class FlumotionRRD():
self._bytes_rrdfile = properties['bytes-rrdfile']
self._clients_rrdfile = properties['clients-rrdfile']
- self._initRRD()
-
self._proto = None
self._conn = None
+ def run(self):
+ if self._initRRD():
+ reactor.callWhenRunning(self._initSocket)
+ reactor.run()
+
def _initRRD(self):
- info_bytes = rrdtool.info(self._bytes_rrdfile)
- step_bytes = info_bytes['step']
- lastupdate_bytes = info_bytes['last_update']
- info_clients = rrdtool.info(self._clients_rrdfile)
- step_clients = info_clients['step']
- lastupdate_clients = info_clients['last_update']
-
- self._duration = step_bytes
- if step_bytes != step_clients:
- print 'SFive: ERROR step size of the RRD Files don\'t match'
- reactor.stop()
-
- self._end = lastupdate_bytes if lastupdate_bytes < lastupdate_clients else lastupdate_clients
- if lastupdate_bytes != lastupdate_clients:
- print 'SFive: WARNING the last update timestamp of the RRD Files don\'t match - will use smaller timestamp'
- reactor.stop()
-
- print 'SFive: will use 7 days of data ending with %s using a step size of %d seconds' % (
- datetime.datetime.utcfromtimestamp(self._end).isoformat('T'), self._duration)
+ try:
+ info_bytes = rrdtool.info(self._bytes_rrdfile)
+ step_bytes = info_bytes['step']
+ lastupdate_bytes = info_bytes['last_update']
+ info_clients = rrdtool.info(self._clients_rrdfile)
+ step_clients = info_clients['step']
+ lastupdate_clients = info_clients['last_update']
- def run(self):
- reactor.callWhenRunning(self._initSocket)
- reactor.run()
+ self._duration = step_bytes
+ if step_bytes != step_clients:
+ print 'SFive: ERROR step size of the RRD Files don\'t match'
+ return False
+
+ self._end = lastupdate_bytes if lastupdate_bytes < lastupdate_clients else lastupdate_clients
+ if lastupdate_bytes != lastupdate_clients:
+ print 'SFive: WARNING the last update timestamp of the RRD Files don\'t match - will use smaller timestamp'
+ return False
+
+ print 'SFive: will use 7 days of data ending with %s using a step size of %d seconds' % (
+ datetime.datetime.utcfromtimestamp(self._end).isoformat('T'), self._duration)
+
+ except rrdtool.error as e:
+ print 'SFive: rrdtool-error: %s' % (e)
+ return False
+
+ return True
def _initSocket(self):
print 'SFive: trying to connect to %s...' % (self._socket)
@@ -163,8 +169,12 @@ class FlumotionRRD():
self._proto.sendDatagram('%s\n' % (json.dumps(initdata)));
def _sendRRDData(self):
- data_bytes = rrdtool.fetch(self._bytes_rrdfile, 'AVERAGE', '-s', 'end-7d', '-e', '%d' % self._end)
- data_clients = rrdtool.fetch(self._clients_rrdfile, 'AVERAGE', '-s', 'end-7d', '-e', '%d' % self._end)
+ try:
+ data_bytes = rrdtool.fetch(self._bytes_rrdfile, 'AVERAGE', '-s', 'end-7d', '-e', '%d' % self._end)
+ data_clients = rrdtool.fetch(self._clients_rrdfile, 'AVERAGE', '-s', 'end-7d', '-e', '%d' % self._end)
+ except rrdtool.error as e:
+ print 'SFive: rrdtool-error: %s' % (e)
+ return 0
ts = data_bytes[0][0]
max = len(data_bytes[2])