added path cbuf to request.lua (required heka dev)
This commit is contained in:
Родитель
742a602c19
Коммит
ae4673d5eb
|
@ -1,33 +1,65 @@
|
||||||
data = circular_buffer.new(1440, 5, 60)
|
statusCodes = circular_buffer.new(1440, 5, 60)
|
||||||
local OK = data:set_header(1, "200", "count")
|
local OK = statusCodes:set_header(1, "200", "count")
|
||||||
local REDIRECT = data:set_header(2, "300", "count")
|
local REDIRECT = statusCodes:set_header(2, "300", "count")
|
||||||
local BADREQUEST = data:set_header(3, "400", "count")
|
local BADREQUEST = statusCodes:set_header(3, "400", "count")
|
||||||
local SERVERERR = data:set_header(4, "500", "count")
|
local SERVERERR = statusCodes:set_header(4, "500", "count")
|
||||||
local TOTAL = data:set_header(5, "TOTAL", "count")
|
local TOTAL = statusCodes:set_header(5, "TOTAL", "count")
|
||||||
|
|
||||||
|
local REQUESTS = 1
|
||||||
|
local TIME = 2
|
||||||
|
|
||||||
|
local paths = {}
|
||||||
|
|
||||||
function process_message()
|
function process_message()
|
||||||
local ts = read_message("Timestamp")
|
local ts = read_message("Timestamp")
|
||||||
local statusCode = read_message("Fields[statusCode]")
|
local statusCode = read_message("Fields[statusCode]")
|
||||||
|
local path = read_message("Fields[path]")
|
||||||
|
local responseTime = read_message("Fields[responseTime]")
|
||||||
|
local processPath = true
|
||||||
if statusCode == nil then return 0 end
|
if statusCode == nil then return 0 end
|
||||||
|
|
||||||
data:add(ts, TOTAL, 1)
|
-- status codes
|
||||||
|
statusCodes:add(ts, TOTAL, 1)
|
||||||
|
|
||||||
if statusCode < 200 then
|
if statusCode < 200 then
|
||||||
return 0
|
return 0
|
||||||
elseif statusCode < 300 then
|
elseif statusCode <= 299 then
|
||||||
data:add(ts, OK, 1)
|
statusCodes:add(ts, OK, 1)
|
||||||
elseif statusCode < 400 then
|
elseif statusCode <= 399 then
|
||||||
data:add(ts, REDIRECT, 1)
|
processPath = false
|
||||||
elseif statusCode < 500 then
|
statusCodes:add(ts, REDIRECT, 1)
|
||||||
data:add(ts, BADREQUEST, 1)
|
elseif statusCode <= 499 then
|
||||||
elseif statusCode < 600 then
|
processPath = false
|
||||||
data:add(ts, SERVERERR, 1)
|
statusCodes:add(ts, BADREQUEST, 1)
|
||||||
|
elseif statusCode <= 599 then
|
||||||
|
statusCodes:add(ts, SERVERERR, 1)
|
||||||
|
else
|
||||||
|
processPath = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if processPath == false then return 0 end
|
||||||
|
|
||||||
|
-- response time
|
||||||
|
local buf = paths[path]
|
||||||
|
if buf == nil then
|
||||||
|
buf = circular_buffer.new(1440, 2, 60)
|
||||||
|
buf:set_header(1, "requests", "count")
|
||||||
|
buf:set_header(2, "time", "ms", "max")
|
||||||
|
paths[path] = buf
|
||||||
|
end
|
||||||
|
|
||||||
|
buf:add(ts, REQUESTS, 1)
|
||||||
|
buf:set(ts, TIME, math.max(buf:get(ts, TIME), responseTime))
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function timer_event(ns)
|
function timer_event(ns)
|
||||||
output(data)
|
output(statusCodes)
|
||||||
inject_message("cbuf", "HTTP status codes")
|
inject_message("cbuf", "HTTP status codes")
|
||||||
|
|
||||||
|
for path, buf in pairs(paths) do
|
||||||
|
output(buf)
|
||||||
|
inject_message("cbuf", string.format("%s requests", path))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,6 @@ module.exports = {
|
||||||
timestamp: new Date(event.timestamp),
|
timestamp: new Date(event.timestamp),
|
||||||
severity: 6,
|
severity: 6,
|
||||||
fields: {
|
fields: {
|
||||||
method: event.method,
|
|
||||||
statusCode: event.statusCode,
|
statusCode: event.statusCode,
|
||||||
path: event.path,
|
path: event.path,
|
||||||
responseTime: event.responseTime
|
responseTime: event.responseTime
|
||||||
|
|
Загрузка…
Ссылка в новой задаче