summaryrefslogtreecommitdiff
path: root/src/daq/accesslog/sfive-accesslog.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/daq/accesslog/sfive-accesslog.py')
-rwxr-xr-xsrc/daq/accesslog/sfive-accesslog.py29
1 files 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: