summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daq/nginx-lua/s5-nginx.lua57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/daq/nginx-lua/s5-nginx.lua b/src/daq/nginx-lua/s5-nginx.lua
index 7a3e9ed..8393562 100644
--- a/src/daq/nginx-lua/s5-nginx.lua
+++ b/src/daq/nginx-lua/s5-nginx.lua
@@ -72,23 +72,25 @@ local sfive_data = ngx.shared.sfive_data
-----------------------------------------------
function _SFIVE.log(content, format, quality)
- -- TODO: acquire(data_lock), update(data), release(data_lock)
- ngx.log(ngx.WARN, "SFive(log): won't add data from " .. ngx.var.remote_addr ..
- " to (" .. content .. ", " .. format .. ", " .. quality .. "): not implemented yet!")
-
- -- local json = '{'
- -- json = json .. '"time": "' .. string.gsub(ngx.utctime(), " ", "T", 1) .. 'Z",'
- -- 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 .. '"status": ' .. status .. ','
- -- json = json .. '"bytes_sent": ' .. ngx.var.bytes_sent
- -- json = json .. '}'
-
+ local status = ngx.var.status
+ if status == '200' or status == '206' then
+
+ -- TODO: acquire(data_lock), update(data), release(data_lock)
+ ngx.log(ngx.ERR, "SFive(log): won't add data from " .. ngx.var.remote_addr ..
+ " to (" .. content .. ", " .. format .. ", " .. quality .. "): not implemented yet!")
+ -- local json = '{'
+ -- json = json .. '"time": "' .. string.gsub(ngx.utctime(), " ", "T", 1) .. 'Z",'
+ -- 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 .. '"status": ' .. status .. ','
+ -- json = json .. '"bytes_sent": ' .. ngx.var.bytes_sent
+ -- json = json .. '}'
+ end
end
-function _SFIVE.connect()
+local connect = function()
ngx.log(ngx.INFO, "SFive(connect): trying to connect to '" .. config.sockpath .."'")
local sock = ngx.socket.udp()
@@ -99,7 +101,7 @@ function _SFIVE.connect()
return sock
end
-function _SFIVE.send_data(sock, starttime)
+local send_data = function(sock, starttime)
-- logs = sfive_data:get_keys()
-- for i, k in ipairs(logs) do
@@ -118,7 +120,7 @@ function _SFIVE.send_data(sock, starttime)
return sock:send(json)
end
-function _SFIVE.send_init(sock)
+local send_init = function(sock)
local json = '{'
json = json .. '"version": 1,'
json = json .. '"hostname": "' .. config.hostname .. '"'
@@ -126,13 +128,13 @@ function _SFIVE.send_init(sock)
return sock:send(json)
end
-function _SFIVE.task()
- local sock, err = _SFIVE.connect(config.sockpath)
+local task = function()
+ local sock, err = connect(config.sockpath)
if not sock then
ngx.log(ngx.ERR, "SFive(task): connect(): " .. err)
return
else
- local ok, err = _SFIVE.send_init(sock)
+ local ok, err = send_init(sock)
if not ok then
ngx.log(ngx.ERR, "SFive(task): sending init failed: " .. err)
sock:close()
@@ -147,7 +149,7 @@ function _SFIVE.task()
ngx.sleep(config.duration)
-- TODO: acquire(data_lock), send(data), flush(data), release(data_lock)
- local ok, err = _SFIVE.send_data(sock, starttime)
+ local ok, err = send_data(sock, starttime)
if not ok then
ngx.log(ngx.ERR, "SFive(task): sending data failed: " .. err)
sock:close()
@@ -156,13 +158,14 @@ function _SFIVE.task()
end
end
-function _SFIVE.launcher(premature)
- local task = ngx.thread.spawn(_SFIVE.task)
+local launcher
+launcher = function(premature)
+ local task = ngx.thread.spawn(task)
ngx.thread.wait(task)
if premature then
return
end
- local ok, err = ngx.timer.at(2, _SFIVE.launcher)
+ local ok, err = ngx.timer.at(2, launcher)
if not ok then
ngx.log(ngx.ERR, "SFive(launcher): failed to reenqueue myself: ", err)
inst.flags:delete("running")
@@ -170,7 +173,7 @@ function _SFIVE.launcher(premature)
end
end
-function _SFIVE.init()
+local init = function()
local ok, err = sfive:add("running", true)
if not ok then
if err ~= "exists" then
@@ -182,7 +185,7 @@ function _SFIVE.init()
sfive_data:flush_all()
sfive_data:flush_expired()
- ok, err = ngx.timer.at(0, _SFIVE.launcher)
+ ok, err = ngx.timer.at(0, launcher)
if not ok then
ngx.log(ngx.ERR, "SFive(init): failed to enqueue sfive launcher: ", err)
return
@@ -195,7 +198,7 @@ function _SFIVE.init_worker(hostname, duration, sockpath)
config.hostname = hostname
config.duration = duration
config.sockpath = sockpath
- _SFIVE.init()
+ init()
ngx.log(ngx.INFO, "SFive(init): worker initialized successfully!")
end