.. code-block:: lua
+ local ffi = require('ffi')
modules.load('stats')
-- log statistics every second
local stat_id = event.recurrent(1 * second, function(evid)
- log(table_print(stats.list()))
+ log_info(ffi.C.LOG_GRP_STATISTICS, table_print(stats.list()))
end)
-- stop printing statistics after first minute
.. code-block:: lua
+ local ffi = require('ffi')
modules.load('stats')
-- make a closure, encapsulating counter
local total_increment = now['answer.total'] - previous['answer.total']
local slow_increment = now['answer.slow'] - previous['answer.slow']
if slow_increment / total_increment > 0.05 then
- log('WARNING! More than 5 %% of queries was slow!')
+ log_warn(ffi.C.LOG_GRP_STATISTICS, 'WARNING! More than 5 %% of queries was slow!')
end
previous = now -- store current value in closure
end
-- Get request method and deal with it properly
local m = h:get(':method')
local path = h:get(':path')
- log('[service] method %s path %s', m, path)
+ log('method %s path %s', m, path)
-- Return table, response code will be '200 OK'
if m == 'GET' then
return {key = path, value = value}