From bb66b44dbda8d533d03cddb3ea224416ef7065ba Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 13 Oct 2014 00:42:21 +0200 Subject: client aggregation works now - still counting all files --- src/daq/accesslog/sfive-accesslog.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/daq/accesslog/sfive-accesslog.py b/src/daq/accesslog/sfive-accesslog.py index a3140e0..0e68497 100755 --- a/src/daq/accesslog/sfive-accesslog.py +++ b/src/daq/accesslog/sfive-accesslog.py @@ -210,11 +210,21 @@ class AccessLog(): linedata['ts'] = self._parseDatetime(linedata['ts']) return linedata + def _updateClients(self, clients, linedata): + if linedata['status'] != 200 or linedata['req']['cmd'] != 'GET': + return + + # TODO: this currently counts all data downloaded from 'client' + + if linedata['client'] in clients.keys(): + clients[linedata['client']] += linedata['size'] + else: + clients[linedata['client']] = linedata['size'] + def _sendLogData(self, data, lastts): cnt = 0 nextts = None if not lastts else lastts + datetime.timedelta(seconds=self._duration) - bytes_sent = 0 - client_cnt = 0 + clients = { } try: regex = self._prepareLineRegex() for line in data: @@ -222,25 +232,20 @@ class AccessLog(): if not lastts: lastts = linedata['ts'] nextts = lastts + datetime.timedelta(seconds=self._duration) - client_cnt += 1 - bytes_sent += linedata['size'] + clients = { linedata['client'] : linedata['size'] } else: while linedata['ts'] > nextts: - self._sendDataset(nextts, self._duration, client_cnt, bytes_sent) + self._sendDataset(nextts, self._duration, len(clients), sum(clients.itervalues())) cnt += 1 lastts = nextts nextts = lastts + datetime.timedelta(seconds=self._duration) - client_cnt = 0 - bytes_sent = 0 + clients = { } - # TODO: update client_cnt and bytes_sent only if data matches - # also the data needs to be aggregated for clients - client_cnt += 1 - bytes_sent += linedata['size'] + self._updateClients(clients, linedata) # send remaining data if nextts: - self._sendDataset(nextts, self._duration, client_cnt, bytes_sent) + self._sendDataset(nextts, self._duration, len(clients), sum(clients.itervalues())) cnt += 1 except re.error as e: -- cgit v1.2.3