From 4c972605ac0b264f18b44b158edd111a211aa1a6 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 12 Oct 2014 20:02:37 +0200 Subject: cleanups --- src/daq/flumotion-rrd/sfive-flumotion-rrd.py | 49 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src/daq/flumotion-rrd') diff --git a/src/daq/flumotion-rrd/sfive-flumotion-rrd.py b/src/daq/flumotion-rrd/sfive-flumotion-rrd.py index 86422fa..0ce7287 100755 --- a/src/daq/flumotion-rrd/sfive-flumotion-rrd.py +++ b/src/daq/flumotion-rrd/sfive-flumotion-rrd.py @@ -107,9 +107,32 @@ class FlumotionRRD(): self._bytes_rrdfile = properties['bytes-rrdfile'] self._clients_rrdfile = properties['clients-rrdfile'] + self._initRRD() + self._proto = None self._conn = None + 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) + def run(self): reactor.callWhenRunning(self._initSocket) reactor.run() @@ -127,41 +150,19 @@ class FlumotionRRD(): def _socketReady(self): print 'SFive: connection to sfive hub established' - self._checkRRD() self._sendInit() - cnt = self._sendRRD() + cnt = self._sendRRDData() print 'SFive: sent %d datasets' % (cnt) reactor.stop() - def _checkRRD(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) - def _sendInit(self): initdata = { "hostname": self._hostname, "streamer-id": { "content-id": self._content_id, "format": self._format, "quality": self._quality }, "tags": self._tags } self._proto.sendDatagram('%s\n' % (json.dumps(initdata))); - def _sendRRD(self): + 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) -- cgit v1.2.3