summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/daq/nginx-lua/s5-nginx-lua-fetch.py30
-rw-r--r--src/daq/nginx-lua/s5-nginx.lua2
2 files changed, 22 insertions, 10 deletions
diff --git a/src/daq/nginx-lua/s5-nginx-lua-fetch.py b/src/daq/nginx-lua/s5-nginx-lua-fetch.py
index 78f5f73..87c7bd1 100755
--- a/src/daq/nginx-lua/s5-nginx-lua-fetch.py
+++ b/src/daq/nginx-lua/s5-nginx-lua-fetch.py
@@ -68,7 +68,6 @@ class SFiveNGXluaProto(Protocol):
if len(lines) > 0:
for line in lines:
- print "SFive: '%s'" % line.strip()
self._importer.updateData(json.loads(line))
def connectionLost(self, reason):
@@ -126,8 +125,7 @@ class SFiveProto(protocol.ConnectedDatagramProtocol):
class ClientList:
- def __init__(self, re):
- self._re = re
+ def __init__(self):
self._clients = { }
def clear(self):
@@ -147,12 +145,11 @@ class ClientList:
return self._clients.itervalues()
def update(self, logdata):
- ## TODO: parse logdata['uri'] !!!
if logdata['client'] in self._clients.keys():
self._clients[logdata['client']]['bytes-sent'] += logdata['bytes-sent']
else:
self._clients[logdata['client']] = { 'ip': logdata['client'],
- 'bytes-sent': logdata['bytes-sent'] }
+ 'bytes-sent': logdata['bytes-sent'] }
class NGXLuaFetcher():
@@ -173,7 +170,7 @@ class NGXLuaFetcher():
self._proto = None
self._conn = None
- self._clients = None
+ self._url_re = None
self._reactor = reactor
def run(self):
@@ -183,7 +180,7 @@ class NGXLuaFetcher():
def _initFetch(self):
try:
- self._clients = ClientList(re.compile(self._nameformat)) # TODO: check for named matches
+ self._url_re = re.compile(self._nameformat)
print "SFive: trying to fetch from '%s'" % self._url
agent = Agent(self._reactor)
@@ -226,7 +223,20 @@ class NGXLuaFetcher():
self._proto.sendDatagram('%s\n' % (json.dumps(initdata)));
def updateData(self, data):
- self._clients.update(data)
+ try:
+ m = re.match(self._url_re, data['url'])
+ if not m:
+ return
+ streamerid = m.groupdict()
+ except re.error as e:
+ print 'SFive: regex error: %s' % (e)
+
+ try:
+ print "url='%s' -> contend-id: '%s', format: '%s', quality: '%s'" % (data['url'],
+ streamerid['content'], streamerid['format'], streamerid['quality'])
+ #self._clients.update(data)
+ except KeyError as e:
+ print 'SFive: %s' % (e)
def _sendDataset(self, timestamp, duration, clients):
data = { "start-time": timestamp.isoformat('T') + 'Z',
@@ -260,7 +270,7 @@ if __name__ == '__main__':
help='the quality (i.e. high) - only used if nameformat doesn\'t contain a named match')
parser.add_argument('--url', '-u', dest='url', required=False,
help='the url of the nginx sfive exporert, default http://localhost/sfive')
- parser.add_argument('--nameformat', '-F', dest='nameformat', required=True,
+ parser.add_argument('--nameformat', '-F', dest='nameformat', required=False,
help='a regular expression (containing named matches for content, format, quality)')
args = vars(parser.parse_args())
if not args['tags']:
@@ -269,5 +279,7 @@ if __name__ == '__main__':
args['duration'] = 15
if not args['url']:
args['url'] = 'http://localhost/sfive'
+ if not args['nameformat']:
+ args['nameformat'] = '/[^/]+/(?P<format>hls|dash)/(?P<content>.+)-(?P<quality>[^-]+)/.*'
fetcher = NGXLuaFetcher(args)
fetcher.run()
diff --git a/src/daq/nginx-lua/s5-nginx.lua b/src/daq/nginx-lua/s5-nginx.lua
index 2ae7e69..673ccba 100644
--- a/src/daq/nginx-lua/s5-nginx.lua
+++ b/src/daq/nginx-lua/s5-nginx.lua
@@ -90,7 +90,7 @@ function _SFIVE.log()
json = json .. '"client": "' .. ngx.var.remote_addr .. '",'
json = json .. '"port": ' .. ngx.var.remote_port .. ','
json = json .. '"ua": "' .. ngx.var.http_user_agent .. '",'
- json = json .. '"uri": "' .. ngx.var.uri .. '",'
+ json = json .. '"url": "' .. ngx.var.uri .. '",'
json = json .. '"status": ' .. status .. ','
json = json .. '"bytes-sent": ' .. ngx.var.bytes_sent
json = json .. '}'